@asteby/metacore-runtime-react 52.1.0 → 53.0.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/addon-loader.d.ts +22 -1
  3. package/dist/addon-loader.d.ts.map +1 -1
  4. package/dist/addon-loader.js +23 -5
  5. package/dist/addon-page-host.d.ts +80 -0
  6. package/dist/addon-page-host.d.ts.map +1 -0
  7. package/dist/addon-page-host.js +216 -0
  8. package/dist/addon-page-loader.d.ts +40 -0
  9. package/dist/addon-page-loader.d.ts.map +1 -0
  10. package/dist/addon-page-loader.js +87 -0
  11. package/dist/dynamic-view.d.ts +20 -1
  12. package/dist/dynamic-view.d.ts.map +1 -1
  13. package/dist/dynamic-view.js +26 -3
  14. package/dist/federated-error-boundary.d.ts +46 -0
  15. package/dist/federated-error-boundary.d.ts.map +1 -0
  16. package/dist/federated-error-boundary.js +55 -0
  17. package/dist/host-api.d.ts +22 -0
  18. package/dist/host-api.d.ts.map +1 -0
  19. package/dist/host-api.js +113 -0
  20. package/dist/index.d.ts +6 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +8 -1
  23. package/dist/testing.d.ts +42 -0
  24. package/dist/testing.d.ts.map +1 -0
  25. package/dist/testing.js +53 -0
  26. package/dist/types.d.ts +13 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/views/calendar-view.d.ts +23 -0
  29. package/dist/views/calendar-view.d.ts.map +1 -0
  30. package/dist/views/calendar-view.js +138 -0
  31. package/dist/views/chart-view.d.ts +14 -0
  32. package/dist/views/chart-view.d.ts.map +1 -0
  33. package/dist/views/chart-view.js +77 -0
  34. package/dist/views/data-source.d.ts +30 -0
  35. package/dist/views/data-source.d.ts.map +1 -0
  36. package/dist/views/data-source.js +103 -0
  37. package/dist/views/index.d.ts +4 -0
  38. package/dist/views/index.d.ts.map +1 -0
  39. package/dist/views/index.js +2 -0
  40. package/dist/views/map-view.d.ts +39 -0
  41. package/dist/views/map-view.d.ts.map +1 -0
  42. package/dist/views/map-view.js +143 -0
  43. package/dist/views/panels.d.ts +13 -0
  44. package/dist/views/panels.d.ts.map +1 -0
  45. package/dist/views/panels.js +119 -0
  46. package/dist/views/registry.d.ts +46 -0
  47. package/dist/views/registry.d.ts.map +1 -0
  48. package/dist/views/registry.js +139 -0
  49. package/dist/views/skeleton.d.ts +5 -0
  50. package/dist/views/skeleton.d.ts.map +1 -0
  51. package/dist/views/skeleton.js +6 -0
  52. package/dist/views/split-view.d.ts +6 -0
  53. package/dist/views/split-view.d.ts.map +1 -0
  54. package/dist/views/split-view.js +52 -0
  55. package/dist/views/timeline-view.d.ts +25 -0
  56. package/dist/views/timeline-view.d.ts.map +1 -0
  57. package/dist/views/timeline-view.js +130 -0
  58. package/dist/views/types.d.ts +87 -0
  59. package/dist/views/types.d.ts.map +1 -0
  60. package/dist/views/types.js +1 -0
  61. package/package.json +16 -4
  62. package/src/__tests__/addon-page-host.test.tsx +122 -0
  63. package/src/__tests__/addon-page-loader.test.tsx +201 -0
  64. package/src/__tests__/declarative-views.test.tsx +351 -0
  65. package/src/__tests__/host-api.test.ts +87 -0
  66. package/src/__tests__/index-static-graph.test.ts +18 -0
  67. package/src/addon-loader.tsx +51 -8
  68. package/src/addon-page-host.tsx +319 -0
  69. package/src/addon-page-loader.tsx +203 -0
  70. package/src/dynamic-view.tsx +61 -3
  71. package/src/federated-error-boundary.tsx +121 -0
  72. package/src/host-api.ts +143 -0
  73. package/src/index.ts +38 -0
  74. package/src/testing.tsx +108 -0
  75. package/src/types.ts +13 -0
  76. package/src/views/calendar-view.tsx +234 -0
  77. package/src/views/chart-view.tsx +122 -0
  78. package/src/views/data-source.ts +127 -0
  79. package/src/views/index.ts +37 -0
  80. package/src/views/map-view.tsx +217 -0
  81. package/src/views/panels.tsx +177 -0
  82. package/src/views/registry.tsx +202 -0
  83. package/src/views/skeleton.tsx +13 -0
  84. package/src/views/split-view.tsx +115 -0
  85. package/src/views/timeline-view.tsx +229 -0
  86. package/src/views/types.ts +105 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @asteby/metacore-runtime-react
2
2
 
3
+ ## 53.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - df0c760: Páginas federadas y vistas declarativas.
8
+
9
+ - `AddonPageLoader` monta una entrada de `frontend.pages[]`: baja su `expose` por Module Federation, verifica `frontend.integrity` (SRI) antes de importar, aplica un timeout (10 s) y aísla la página en un contenedor con `contain: layout paint`. `AddonLoader` gana `integrity` y `onRenderError`, y envuelve sus `children` en `FederatedErrorBoundary`. `loadFederatedModule` queda exportado para hosts.
10
+ - Hooks para el remote, servidos por `<AddonPageHost>`: `useHostContext`, `useHostApi`, `useAddonNavigate` (relativo a la base, sin `window.location`), `useAddonLocation`, `useAddonSearchParams`, `useBreadcrumbs` y `usePageChrome` (título, acciones del header y modo foco). El host lee el chrome con `createPageChromeStore`/`usePageChromeState`.
11
+ - `createHostApi(client)`: el `HostApi` que el host entrega al remote. Devuelve solo cuerpos y errores `HostApiError` sin `config` ni cabeceras: el token nunca llega al remote.
12
+ - `FederatedErrorBoundary`: error contenido con "Reintentar", `onError` para incidentes y `resetKeys`.
13
+ - Vistas declarativas por tipo, cada una en su chunk perezoso: `DeclarativeView` (chart con los widgets del tablero, timeline, calendar, split con `DynamicTable` + paneles, y map como contrato + lista accesible hasta que un paquete de mapas registre el renderer real) y `DetailPanels` (map, timeline por relación o capacidad, chart, relation, stats; `custom` lo registra el host). Registro: `registerViewRenderer`, `registerPanelRenderer`, `preloadViewRenderer`. `DynamicView` enruta a ellas cuando la metadata trae el bloque `view` (`resolveViewKind`); sin él sigue la tabla. `TableMetadata` gana `view` y `detail`.
14
+ - Subpaths nuevos: `./testing` (`renderWithHost`, `createMockHostApi`) y `./views/map` (helpers puros del contrato de mapas para `@asteby/metacore-maps`). El test de grafo estático exige que ningún renderer ni el helper de pruebas entren al índice.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [df0c760]
19
+ - @asteby/metacore-sdk@3.15.0
20
+
3
21
  ## 52.1.0
4
22
 
5
23
  ### Minor Changes
@@ -1,4 +1,5 @@
1
1
  import type { AddonAPI, AddonLayout, Registry } from '@asteby/metacore-sdk';
2
+ import { type FederatedErrorInfo } from './federated-error-boundary';
2
3
  export interface AddonLoaderProps {
3
4
  /** Unique key of the addon — maps to the federation container name. */
4
5
  scope: string;
@@ -42,7 +43,27 @@ export interface AddonLoaderProps {
42
43
  * — the loader sets the context value via {@link useDeclareAddonLayout}.
43
44
  */
44
45
  layout?: AddonLayout;
46
+ /**
47
+ * SRI of `remoteEntry.js` (`manifest.frontend.integrity`). When set, the
48
+ * entry is verified before the MF runtime imports it and a mismatch fails
49
+ * the load permanently (no retry). Unset = previous behaviour.
50
+ */
51
+ integrity?: string;
52
+ /**
53
+ * Render errors thrown by `children` (the addon's UI mounted under this
54
+ * fiber) are contained by a {@link FederatedErrorBoundary}; this reports
55
+ * them (ops: reportFrontendIncident).
56
+ */
57
+ onRenderError?: (error: Error, info: FederatedErrorInfo) => void;
45
58
  children?: React.ReactNode;
46
59
  }
47
- export declare function AddonLoader({ scope, url, module, api, hostRegistry, addonKey, unbindKey, fallback, onReady, onError, layout, children, }: AddonLoaderProps): import("react").JSX.Element | null;
60
+ /**
61
+ * Load one exposed module of a federated remote through the MF runtime:
62
+ * verifies `integrity` (SRI) first, (re)registers the remote when its URL
63
+ * changed, then `loadRemote("<scope>/<expose>")`. Transient failures (host
64
+ * boot race, gateway blips) are retried; an integrity mismatch is not.
65
+ * Shared by {@link AddonLoader} (`./register`) and `AddonPageLoader` (pages).
66
+ */
67
+ export declare function loadFederatedModule<T = unknown>(scope: string, url: string, module: string, integrity?: string): Promise<T | null>;
68
+ export declare function AddonLoader({ scope, url, module, api, hostRegistry, addonKey, unbindKey, fallback, onReady, onError, layout, integrity, onRenderError, children, }: AddonLoaderProps): import("react").JSX.Element | null;
48
69
  //# sourceMappingURL=addon-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAc3E,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,GAAG,EAAE,QAAQ,CAAA;IACb;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAC9B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B;AA4ED,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,GAAG,EACH,MAAqB,EACrB,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,QAAe,EACf,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,GACX,EAAE,gBAAgB,sCAmElB"}
1
+ {"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA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Ae,EACf,OAAO,EACP,OAAO,EACP,MAAM,EACN,SAAS,EACT,aAAa,EACb,QAAQ,GACX,EAAE,gBAAgB,sCA6ElB"}
@@ -19,7 +19,9 @@ function getMfRuntime() {
19
19
  });
20
20
  return mfRuntime;
21
21
  }
22
+ import { ensureRemoteIntegrity, RemoteIntegrityError } from '@asteby/metacore-sdk';
22
23
  import { useDeclareAddonLayout } from './addon-layout-context';
24
+ import { FederatedErrorBoundary } from './federated-error-boundary';
23
25
  import { composeDisposables, disposableFromRegisterResult, markRemoteRegistered, purgeAddonFrontendCache, resolvePluginExports, runDispose, shouldReregisterRemote, } from './addon-fiber';
24
26
  // Derive the `loadRemote` id from the scope + exposed module name. MF resolves
25
27
  // `"<remoteName>/<expose>"` — e.g. `metacore_tickets/register` for the
@@ -43,6 +45,8 @@ function isRuntimeNotReady(e) {
43
45
  }
44
46
  /** Transient network / gateway failures while the host API is restarting. */
45
47
  function isTransientRemoteLoadError(e) {
48
+ if (e instanceof RemoteIntegrityError)
49
+ return false;
46
50
  if (isRuntimeNotReady(e))
47
51
  return true;
48
52
  const msg = e instanceof Error ? e.message : String(e);
@@ -66,7 +70,16 @@ async function withRemoteLoadRetry(op) {
66
70
  }
67
71
  }
68
72
  }
69
- async function loadAddon(scope, url, module) {
73
+ /**
74
+ * Load one exposed module of a federated remote through the MF runtime:
75
+ * verifies `integrity` (SRI) first, (re)registers the remote when its URL
76
+ * changed, then `loadRemote("<scope>/<expose>")`. Transient failures (host
77
+ * boot race, gateway blips) are retried; an integrity mismatch is not.
78
+ * Shared by {@link AddonLoader} (`./register`) and `AddonPageLoader` (pages).
79
+ */
80
+ export async function loadFederatedModule(scope, url, module, integrity) {
81
+ if (integrity)
82
+ await withRemoteLoadRetry(() => ensureRemoteIntegrity(url, integrity));
70
83
  // Re-register whenever the `?v=` URL changes so a fiber swap actually
71
84
  // fetches the new remoteEntry. `force: true` wipes that remote's module
72
85
  // cache — without it, loadRemote would keep serving the previous bundle.
@@ -76,7 +89,10 @@ async function loadAddon(scope, url, module) {
76
89
  }
77
90
  return withRemoteLoadRetry(() => getMfRuntime().then((mf) => mf.loadRemote(remoteId(scope, module))));
78
91
  }
79
- export function AddonLoader({ scope, url, module = './register', api, hostRegistry, addonKey, unbindKey, fallback = null, onReady, onError, layout, children, }) {
92
+ async function loadAddon(scope, url, module, integrity) {
93
+ return loadFederatedModule(scope, url, module, integrity);
94
+ }
95
+ export function AddonLoader({ scope, url, module = './register', api, hostRegistry, addonKey, unbindKey, fallback = null, onReady, onError, layout, integrity, onRenderError, children, }) {
80
96
  const [status, setStatus] = useState('loading');
81
97
  const [error, setError] = useState(null);
82
98
  const disposeRef = useRef(undefined);
@@ -94,7 +110,7 @@ export function AddonLoader({ scope, url, module = './register', api, hostRegist
94
110
  setStatus('loading');
95
111
  if (key)
96
112
  await purgeAddonFrontendCache(key);
97
- const mod = await loadAddon(scope, url, module);
113
+ const mod = await loadAddon(scope, url, module, integrity);
98
114
  if (cancelled)
99
115
  return;
100
116
  const plugin = resolvePluginExports(mod);
@@ -130,7 +146,7 @@ export function AddonLoader({ scope, url, module = './register', api, hostRegist
130
146
  // api identity is expected to be stable per addon; including it would
131
147
  // re-register on every parent render. Fiber identity is (scope, url, module).
132
148
  // eslint-disable-next-line react-hooks/exhaustive-deps
133
- }, [scope, url, module, addonKey, unbindKey, hostRegistry]);
149
+ }, [scope, url, module, addonKey, unbindKey, hostRegistry, integrity]);
134
150
  if (status === 'loading')
135
151
  return _jsx(_Fragment, { children: fallback });
136
152
  if (status === 'error') {
@@ -142,5 +158,7 @@ export function AddonLoader({ scope, url, module = './register', api, hostRegist
142
158
  return null;
143
159
  return _jsxs("div", { className: "text-sm text-red-500", children: ["Addon load error: ", error?.message] });
144
160
  }
145
- return _jsx(_Fragment, { children: children });
161
+ if (children === undefined || children === null)
162
+ return null;
163
+ return (_jsx(FederatedErrorBoundary, { addonKey: addonKey || api.manifest?.key || scope, expose: module, onError: onRenderError, resetKeys: [url], children: children }));
146
164
  }
@@ -0,0 +1,80 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { AddonHostContext, Breadcrumb, HostApi, PageChrome } from '@asteby/metacore-sdk';
3
+ export interface PageChromeState extends PageChrome {
4
+ breadcrumbs: Breadcrumb[];
5
+ }
6
+ export interface PageChromeStore {
7
+ get(): PageChromeState;
8
+ subscribe(listener: () => void): () => void;
9
+ /** Merge a partial update (page side). */
10
+ set(patch: Partial<PageChromeState>): void;
11
+ /** Back to empty (page unmounted). */
12
+ reset(): void;
13
+ }
14
+ export declare function createPageChromeStore(initial?: Partial<PageChromeState>): PageChromeStore;
15
+ /** Host side: subscribe the header to what the page declared. */
16
+ export declare function usePageChromeState(store: PageChromeStore): PageChromeState;
17
+ export interface AddonNavigateOptions {
18
+ replace?: boolean;
19
+ }
20
+ /** Location of the host router, as plain strings (router-agnostic). */
21
+ export interface AddonPageLocation {
22
+ pathname: string;
23
+ search: string;
24
+ }
25
+ export interface AddonPageHostValue {
26
+ host: AddonHostContext;
27
+ api: HostApi;
28
+ basePath: string;
29
+ location: AddonPageLocation;
30
+ navigate: (to: string, opts?: AddonNavigateOptions) => void;
31
+ chrome?: PageChromeStore;
32
+ }
33
+ export interface AddonPageHostProps extends Omit<AddonPageHostValue, 'basePath'> {
34
+ basePath: string;
35
+ children: ReactNode;
36
+ }
37
+ export declare function AddonPageHost({ host, api, basePath, location, navigate, chrome, children, }: AddonPageHostProps): import("react").JSX.Element;
38
+ /** True when rendered inside a host page (lets shared components degrade). */
39
+ export declare function useIsInAddonPage(): boolean;
40
+ /** Org, user, branch, locale, installed addons and realtime of the host. */
41
+ export declare function useHostContext(): AddonHostContext;
42
+ /** Authenticated API client provided by the host (never exposes the token). */
43
+ export declare function useHostApi(): HostApi;
44
+ /**
45
+ * Resolve `to` inside the page. Plain paths are base-relative:
46
+ * `"shipments/42"` and `"/shipments/42"` both land on `<base>/shipments/42`.
47
+ * `"./x"` and `"../x"` resolve against the current sub-path (like URLs), and
48
+ * `".."` never climbs above the base. `""` / `"?q=1"` keep the current path.
49
+ * A `?query` / `#hash` is kept.
50
+ */
51
+ export declare function resolveAddonPath(basePath: string, currentSubpath: string, to: string): string;
52
+ /** Path below the page base (`"shipments/42"`), from the host location. */
53
+ export declare function addonSubpath(basePath: string, pathname: string): string;
54
+ /**
55
+ * Navigate inside the page. The host router does the work (no
56
+ * `window.location`), so history, guards and the shell stay intact.
57
+ * `navigate(-1)` goes back.
58
+ */
59
+ export declare function useAddonNavigate(): (to: string | number, opts?: AddonNavigateOptions) => void;
60
+ /** Location relative to the page: `{ path: "shipments/42", search: "?x=1" }`. */
61
+ export declare function useAddonLocation(): {
62
+ path: string;
63
+ search: string;
64
+ };
65
+ /** Search params of the page URL, with a setter that goes through the host router. */
66
+ export declare function useAddonSearchParams(): [
67
+ URLSearchParams,
68
+ (next: URLSearchParams | Record<string, string>, opts?: AddonNavigateOptions) => void
69
+ ];
70
+ /**
71
+ * Declare the page's breadcrumbs (shown by the host header before the page
72
+ * title). Cleared on unmount. No-op on hosts without a chrome store.
73
+ */
74
+ export declare function useBreadcrumbs(crumbs: Breadcrumb[]): void;
75
+ /**
76
+ * Declare title, subtitle, header actions and focus mode. Values update on
77
+ * every render that changes them; everything is cleared on unmount.
78
+ */
79
+ export declare function usePageChrome(chrome: PageChrome): void;
80
+ //# sourceMappingURL=addon-page-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon-page-host.d.ts","sourceRoot":"","sources":["../src/addon-page-host.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAQH,KAAK,SAAS,EACjB,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EACR,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,UAAU,EACb,MAAM,sBAAsB,CAAA;AAO7B,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,WAAW,EAAE,UAAU,EAAE,CAAA;CAC5B;AAED,MAAM,WAAW,eAAe;IAC5B,GAAG,IAAI,eAAe,CAAA;IACtB,SAAS,CAAC,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A+E;AAC/E,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAOD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAsB7F;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMvE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,oBAAoB,KAAK,IAAI,CAa7F;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAMnE;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,IAAI;IACpC,eAAe;IACf,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,oBAAoB,KAAK,IAAI;CACxF,CAcA;AAMD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAgBzD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAuBtD"}
@@ -0,0 +1,216 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // AddonPageHost — what the host mounts around a federated page (embedded or
3
+ // full screen) so the remote can use host services without importing host
4
+ // code and without ever touching credentials.
5
+ //
6
+ // Host side (ops FederatedPageHost, starter-core):
7
+ //
8
+ // const chrome = useMemo(createPageChromeStore, [])
9
+ // <AddonPageHost
10
+ // host={hostContext} // org, user, branch, locale…
11
+ // api={hostApi} // createHostApi(axios)
12
+ // basePath="/a/shipping/control-tower"
13
+ // location={{ pathname, search }} // from the host router
14
+ // navigate={(to, o) => router.navigate({ to, replace: o?.replace })}
15
+ // chrome={chrome} // header reads it
16
+ // >
17
+ // <Page … />
18
+ // </AddonPageHost>
19
+ //
20
+ // // header: const { title, actions, focus, breadcrumbs } = usePageChromeState(chrome)
21
+ //
22
+ // Remote side (inside the page):
23
+ //
24
+ // const api = useHostApi()
25
+ // const { org, user, locale } = useHostContext()
26
+ // const navigate = useAddonNavigate() // relative to basePath
27
+ // const [params, setParams] = useAddonSearchParams()
28
+ // useBreadcrumbs([{ title: t('shipping.nav.group'), url: '/m/Shipment' }])
29
+ // usePageChrome({ title: t('shipping.pages.control_tower'), focus: true })
30
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore, } from 'react';
31
+ const EMPTY_CHROME = Object.freeze({ breadcrumbs: [] });
32
+ export function createPageChromeStore(initial) {
33
+ let state = { ...EMPTY_CHROME, ...initial };
34
+ const listeners = new Set();
35
+ const emit = () => listeners.forEach((l) => l());
36
+ return {
37
+ get: () => state,
38
+ subscribe(listener) {
39
+ listeners.add(listener);
40
+ return () => listeners.delete(listener);
41
+ },
42
+ set(patch) {
43
+ state = { ...state, ...patch };
44
+ emit();
45
+ },
46
+ reset() {
47
+ state = { ...EMPTY_CHROME, ...initial };
48
+ emit();
49
+ },
50
+ };
51
+ }
52
+ /** Host side: subscribe the header to what the page declared. */
53
+ export function usePageChromeState(store) {
54
+ return useSyncExternalStore(store.subscribe, store.get, store.get);
55
+ }
56
+ const AddonPageHostContext = createContext(null);
57
+ export function AddonPageHost({ host, api, basePath, location, navigate, chrome, children, }) {
58
+ const base = normalizeBase(basePath);
59
+ const value = useMemo(() => ({ host, api, basePath: base, location, navigate, chrome }), [host, api, base, location, navigate, chrome]);
60
+ // The chrome belongs to the page: clear it when the page goes away so the
61
+ // next screen does not inherit a stale title or header buttons.
62
+ useEffect(() => () => chrome?.reset(), [chrome]);
63
+ return _jsx(AddonPageHostContext.Provider, { value: value, children: children });
64
+ }
65
+ function usePageHost(hook) {
66
+ const ctx = useContext(AddonPageHostContext);
67
+ if (!ctx) {
68
+ throw new Error(`${hook}() must run inside <AddonPageHost>. Hosts mount it around every federated page; ` +
69
+ 'in tests use renderWithHost() from @asteby/metacore-runtime-react/testing.');
70
+ }
71
+ return ctx;
72
+ }
73
+ /** True when rendered inside a host page (lets shared components degrade). */
74
+ export function useIsInAddonPage() {
75
+ return useContext(AddonPageHostContext) !== null;
76
+ }
77
+ // ---------------------------------------------------------------------------
78
+ // Remote-facing hooks
79
+ // ---------------------------------------------------------------------------
80
+ /** Org, user, branch, locale, installed addons and realtime of the host. */
81
+ export function useHostContext() {
82
+ return usePageHost('useHostContext').host;
83
+ }
84
+ /** Authenticated API client provided by the host (never exposes the token). */
85
+ export function useHostApi() {
86
+ return usePageHost('useHostApi').api;
87
+ }
88
+ function normalizeBase(base) {
89
+ const b = `/${base.replace(/^\/+|\/+$/g, '')}`;
90
+ return b === '/' ? '' : b;
91
+ }
92
+ /**
93
+ * Resolve `to` inside the page. Plain paths are base-relative:
94
+ * `"shipments/42"` and `"/shipments/42"` both land on `<base>/shipments/42`.
95
+ * `"./x"` and `"../x"` resolve against the current sub-path (like URLs), and
96
+ * `".."` never climbs above the base. `""` / `"?q=1"` keep the current path.
97
+ * A `?query` / `#hash` is kept.
98
+ */
99
+ export function resolveAddonPath(basePath, currentSubpath, to) {
100
+ const base = normalizeBase(basePath);
101
+ const m = /^([^?#]*)(.*)$/.exec(to);
102
+ const pathPart = m ? m[1] : to;
103
+ const suffix = m ? m[2] : '';
104
+ const current = currentSubpath.split('/').filter(Boolean);
105
+ let segs;
106
+ if (pathPart === '') {
107
+ segs = current;
108
+ }
109
+ else if (pathPart.startsWith('./') || pathPart.startsWith('../') || pathPart === '.' || pathPart === '..') {
110
+ // Relative to the current "directory" (drop the last segment, like URLs).
111
+ segs = current.slice(0, -1);
112
+ }
113
+ else {
114
+ segs = [];
115
+ }
116
+ for (const seg of pathPart.split('/')) {
117
+ if (!seg || seg === '.')
118
+ continue;
119
+ if (seg === '..')
120
+ segs.pop();
121
+ else
122
+ segs.push(seg);
123
+ }
124
+ const rest = segs.join('/');
125
+ return `${base}${rest ? `/${rest}` : ''}${suffix}` || '/';
126
+ }
127
+ /** Path below the page base (`"shipments/42"`), from the host location. */
128
+ export function addonSubpath(basePath, pathname) {
129
+ const base = normalizeBase(basePath);
130
+ if (base && (pathname === base || pathname.startsWith(`${base}/`))) {
131
+ return pathname.slice(base.length).replace(/^\/+/, '');
132
+ }
133
+ return '';
134
+ }
135
+ /**
136
+ * Navigate inside the page. The host router does the work (no
137
+ * `window.location`), so history, guards and the shell stay intact.
138
+ * `navigate(-1)` goes back.
139
+ */
140
+ export function useAddonNavigate() {
141
+ const { basePath, location, navigate } = usePageHost('useAddonNavigate');
142
+ const sub = addonSubpath(basePath, location.pathname);
143
+ return useCallback((to, opts) => {
144
+ if (typeof to === 'number') {
145
+ if (typeof window !== 'undefined')
146
+ window.history.go(to);
147
+ return;
148
+ }
149
+ navigate(resolveAddonPath(basePath, sub, to), opts);
150
+ }, [basePath, sub, navigate]);
151
+ }
152
+ /** Location relative to the page: `{ path: "shipments/42", search: "?x=1" }`. */
153
+ export function useAddonLocation() {
154
+ const { basePath, location } = usePageHost('useAddonLocation');
155
+ return useMemo(() => ({ path: addonSubpath(basePath, location.pathname), search: location.search }), [basePath, location.pathname, location.search]);
156
+ }
157
+ /** Search params of the page URL, with a setter that goes through the host router. */
158
+ export function useAddonSearchParams() {
159
+ const { basePath, location, navigate } = usePageHost('useAddonSearchParams');
160
+ const params = useMemo(() => new URLSearchParams(location.search), [location.search]);
161
+ const set = useCallback((next, opts) => {
162
+ const qs = (next instanceof URLSearchParams ? next : new URLSearchParams(next)).toString();
163
+ const sub = addonSubpath(basePath, location.pathname);
164
+ navigate(`${normalizeBase(basePath)}${sub ? `/${sub}` : ''}${qs ? `?${qs}` : ''}`, {
165
+ replace: opts?.replace ?? true,
166
+ });
167
+ }, [basePath, location.pathname, navigate]);
168
+ return [params, set];
169
+ }
170
+ function sameCrumbs(a, b) {
171
+ return a.length === b.length && a.every((c, i) => c.title === b[i].title && c.url === b[i].url);
172
+ }
173
+ /**
174
+ * Declare the page's breadcrumbs (shown by the host header before the page
175
+ * title). Cleared on unmount. No-op on hosts without a chrome store.
176
+ */
177
+ export function useBreadcrumbs(crumbs) {
178
+ const { chrome } = usePageHost('useBreadcrumbs');
179
+ const last = useRef(null);
180
+ useEffect(() => {
181
+ if (!chrome)
182
+ return;
183
+ if (last.current && sameCrumbs(last.current, crumbs))
184
+ return;
185
+ last.current = crumbs;
186
+ chrome.set({ breadcrumbs: crumbs });
187
+ });
188
+ useEffect(() => () => {
189
+ last.current = null;
190
+ chrome?.set({ breadcrumbs: [] });
191
+ }, [chrome]);
192
+ }
193
+ /**
194
+ * Declare title, subtitle, header actions and focus mode. Values update on
195
+ * every render that changes them; everything is cleared on unmount.
196
+ */
197
+ export function usePageChrome(chrome) {
198
+ const { chrome: store } = usePageHost('usePageChrome');
199
+ const { title, subtitle, actions, focus } = chrome;
200
+ // Action handlers are usually inline closures: keep the latest in a ref so
201
+ // the store only changes when what the header SHOWS changes.
202
+ const handlers = useRef(new Map());
203
+ handlers.current = new Map((actions ?? []).map((a) => [a.key, a.onSelect]));
204
+ const actionsSig = JSON.stringify((actions ?? []).map(({ onSelect: _onSelect, ...rest }) => rest));
205
+ useEffect(() => {
206
+ if (!store)
207
+ return;
208
+ const stable = (actions ?? []).map((a) => ({
209
+ ...a,
210
+ onSelect: () => handlers.current.get(a.key)?.(),
211
+ }));
212
+ store.set({ title, subtitle, actions: stable, focus });
213
+ // eslint-disable-next-line react-hooks/exhaustive-deps
214
+ }, [store, title, subtitle, actionsSig, focus]);
215
+ useEffect(() => () => store?.set({ title: undefined, subtitle: undefined, actions: undefined, focus: undefined }), [store]);
216
+ }
@@ -0,0 +1,40 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type AddonHostContext, type FrontendPage, type HostApi } from '@asteby/metacore-sdk';
3
+ import { type AddonPageHostProps, type PageChromeStore } from './addon-page-host';
4
+ import { type FederatedErrorBoundaryProps, type FederatedErrorInfo } from './federated-error-boundary';
5
+ export interface AddonPageLoaderProps {
6
+ /** Federation container name (`metacore_shipping`). */
7
+ scope: string;
8
+ /** remoteEntry.js URL (may carry the `?v=` cache-bust). */
9
+ url: string;
10
+ /** `manifest.frontend.integrity`. */
11
+ integrity?: string;
12
+ /** Addon key (incidents, data attributes). */
13
+ addonKey: string;
14
+ /** The manifest page being mounted. */
15
+ page: FrontendPage;
16
+ /** Absolute mount path (`pageMountPath(addonKey, page, frontend.layout)`). */
17
+ basePath: string;
18
+ host: AddonHostContext;
19
+ api: HostApi;
20
+ location: AddonPageHostProps['location'];
21
+ navigate: AddonPageHostProps['navigate'];
22
+ chrome?: PageChromeStore;
23
+ /** Extra route params the host router extracted. */
24
+ params?: Record<string, string>;
25
+ /** Shown while the remote downloads (default: page skeleton). */
26
+ fallback?: ReactNode;
27
+ /** Abort the load after this many ms (default 10 000; 0 disables). */
28
+ timeoutMs?: number;
29
+ /** Load failure or render crash, for telemetry (reportFrontendIncident). */
30
+ onError?: (error: Error, info: FederatedErrorInfo & {
31
+ phase: 'load' | 'render';
32
+ }) => void;
33
+ /** Override the error UI (load and render). */
34
+ errorFallback?: FederatedErrorBoundaryProps['fallback'];
35
+ errorStrings?: FederatedErrorBoundaryProps['strings'];
36
+ }
37
+ /** Page-sized skeleton: header line + content block, fixed heights (no layout shift). */
38
+ export declare function AddonPageSkeleton(): import("react").JSX.Element;
39
+ export declare function AddonPageLoader({ scope, url, integrity, addonKey, page, basePath, host, api, location, navigate, chrome, params, fallback, timeoutMs, onError, errorFallback, errorStrings, }: AddonPageLoaderProps): import("react").JSX.Element;
40
+ //# sourceMappingURL=addon-page-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon-page-loader.d.ts","sourceRoot":"","sources":["../src/addon-page-loader.tsx"],"names":[],"mappings":"AAcA,OAAO,EAA2C,KAAK,SAAS,EAAE,MAAM,OAAO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S,CAAC,CAAA;CACxD;AAOD,yFAAyF;AACzF,wBAAgB,iBAAiB,gCAOhC;AAmBD,wBAAgB,eAAe,CAAC,EAC5B,KAAK,EACL,GAAG,EACH,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAkB,EAClB,OAAO,EACP,aAAa,EACb,YAAY,GACf,EAAE,oBAAoB,+BAqFtB"}
@@ -0,0 +1,87 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // AddonPageLoader — mounts one `frontend.pages[]` entry of a federated remote.
3
+ //
4
+ // The host has already decided WHERE (embedded `/a/…` or full screen
5
+ // `/addons/…`) and WHETHER (permission) from the manifest; this component
6
+ // downloads the page's expose, verifies the remote entry (SRI), and renders
7
+ // the page inside:
8
+ // FederatedErrorBoundary → a crashing page never takes the shell down
9
+ // AddonPageHost → useHostApi / useHostContext / useAddonNavigate…
10
+ // a sized container → `contain: layout paint` + `isolation: isolate`
11
+ // so the page cannot paint over the host chrome
12
+ //
13
+ // Load failures (network, 404 expose, integrity) are not render errors: they
14
+ // show `errorFallback` (default: the boundary's card) with a retry that
15
+ // re-runs the load. `timeoutMs` turns a hung remote into that same error.
16
+ import { useEffect, useState } from 'react';
17
+ import { resolvePageModule, } from '@asteby/metacore-sdk';
18
+ import { loadFederatedModule } from './addon-loader';
19
+ import { AddonPageHost, addonSubpath } from './addon-page-host';
20
+ import { FederatedErrorBoundary, } from './federated-error-boundary';
21
+ /** Page-sized skeleton: header line + content block, fixed heights (no layout shift). */
22
+ export function AddonPageSkeleton() {
23
+ return (_jsxs("div", { "aria-busy": "true", "data-testid": "addon-page-skeleton", className: "flex flex-col gap-4 p-4", children: [_jsx("div", { className: "h-7 w-56 animate-pulse rounded-md bg-muted" }), _jsx("div", { className: "h-[60vh] w-full animate-pulse rounded-lg bg-muted/70" })] }));
24
+ }
25
+ function withTimeout(p, ms, what) {
26
+ if (!ms)
27
+ return p;
28
+ return new Promise((resolve, reject) => {
29
+ const t = setTimeout(() => reject(new Error(`metacore: ${what} did not load within ${ms} ms`)), ms);
30
+ p.then((v) => {
31
+ clearTimeout(t);
32
+ resolve(v);
33
+ }, (e) => {
34
+ clearTimeout(t);
35
+ reject(e);
36
+ });
37
+ });
38
+ }
39
+ export function AddonPageLoader({ scope, url, integrity, addonKey, page, basePath, host, api, location, navigate, chrome, params, fallback, timeoutMs = 10_000, onError, errorFallback, errorStrings, }) {
40
+ const [state, setState] = useState({ status: 'loading' });
41
+ const [attempt, setAttempt] = useState(0);
42
+ useEffect(() => {
43
+ let cancelled = false;
44
+ setState({ status: 'loading' });
45
+ withTimeout(loadFederatedModule(scope, url, page.expose, integrity), timeoutMs, `page "${page.expose}" of ${addonKey}`)
46
+ .then((mod) => {
47
+ if (cancelled)
48
+ return;
49
+ setState({ status: 'ready', Page: resolvePageModule(mod, page.expose) });
50
+ })
51
+ .catch((e) => {
52
+ if (cancelled)
53
+ return;
54
+ const error = e instanceof Error ? e : new Error(String(e));
55
+ setState({ status: 'error', error });
56
+ onError?.(error, { addonKey, expose: page.expose, phase: 'load' });
57
+ });
58
+ return () => {
59
+ cancelled = true;
60
+ };
61
+ // onError identity is not part of the fiber identity.
62
+ // eslint-disable-next-line react-hooks/exhaustive-deps
63
+ }, [scope, url, page.expose, integrity, addonKey, timeoutMs, attempt]);
64
+ const retry = () => {
65
+ setState({ status: 'loading' });
66
+ setAttempt((n) => n + 1);
67
+ };
68
+ const subpath = addonSubpath(basePath, location.pathname);
69
+ let body;
70
+ if (state.status === 'loading') {
71
+ body = fallback ?? _jsx(AddonPageSkeleton, {});
72
+ }
73
+ else if (state.status === 'error') {
74
+ // Reuse the boundary's UI for load failures so both look the same.
75
+ body = (_jsx(FederatedErrorBoundary, { addonKey: addonKey, expose: page.expose, fallback: errorFallback, strings: errorStrings, onReset: retry, children: _jsx(ThrowError, { error: state.error }) }));
76
+ }
77
+ else {
78
+ const { Page } = state;
79
+ body = (_jsx(FederatedErrorBoundary, { addonKey: addonKey, expose: page.expose, resetKeys: [url, page.expose], fallback: errorFallback, strings: errorStrings, onError: (error, info) => onError?.(error, { ...info, phase: 'render' }), children: _jsx(Page, { host: host, basePath: basePath, params: { ...params, '*': subpath }, page: page }) }));
80
+ }
81
+ return (_jsx("div", { "data-addon-page": `${addonKey}:${page.key}`, className: "relative min-h-0 w-full", style: { contain: 'layout paint', isolation: 'isolate' }, children: _jsx(AddonPageHost, { host: host, api: api, basePath: basePath, location: location, navigate: navigate, chrome: chrome, children: body }) }));
82
+ }
83
+ // Throws the load error during render so the boundary paints it; the
84
+ // boundary's retry (onReset) re-runs the load, not only the render.
85
+ function ThrowError({ error }) {
86
+ throw error;
87
+ }
@@ -1,10 +1,20 @@
1
1
  import { type DynamicTableProps } from './dynamic-table';
2
2
  import { type DynamicKanbanProps } from './dynamic-kanban';
3
+ import type { TableMetadata } from './types';
4
+ import type { ViewDataSource } from './views/types';
3
5
  /**
4
6
  * Pure routing decision: which renderer a `view_type` maps onto. Exported so a
5
7
  * host that resolves metadata itself can branch without mounting this wrapper.
6
8
  */
7
9
  export declare function resolveViewRenderer(viewType: string | undefined): 'kanban' | 'table';
10
+ /**
11
+ * Full routing decision including the declarative views: `'declarative'`
12
+ * when the type is map/timeline/calendar/chart/split AND the metadata carries
13
+ * its `view` block; otherwise the same table/kanban rule as
14
+ * {@link resolveViewRenderer} (a host that does not serve `view` keeps the
15
+ * table, exactly like before).
16
+ */
17
+ export declare function resolveViewKind(viewType: string | undefined, meta: Pick<TableMetadata, 'view'> | null | undefined): 'declarative' | 'kanban' | 'table';
8
18
  /**
9
19
  * Reads the `view` selector out of a URL search string (`?view=kanban`, a bare
10
20
  * `view=kanban`, or a full href). Returns `undefined` when absent. The query is
@@ -37,6 +47,15 @@ export interface DynamicViewProps extends DynamicTableProps {
37
47
  * kanban-only extras (e.g. `onCardClick`, `pageSize`).
38
48
  */
39
49
  kanbanProps?: Partial<Omit<DynamicKanbanProps, 'model' | 'endpoint'>>;
50
+ /**
51
+ * Data source for declarative views (map/timeline/calendar/chart/split).
52
+ * Default: {@link createApiViewDataSource} over the injected ApiClient.
53
+ */
54
+ viewDataSource?: ViewDataSource;
55
+ /** Open a record from a declarative view (host detail route or drawer). */
56
+ onOpenRecord?: (row: Record<string, unknown>) => void;
57
+ /** BCP-47 locale for declarative views. */
58
+ locale?: string;
40
59
  }
41
- export declare function DynamicView({ view, kanbanProps, ...tableProps }: DynamicViewProps): import("react").JSX.Element | null;
60
+ export declare function DynamicView({ view, kanbanProps, viewDataSource, onOpenRecord, locale, ...tableProps }: DynamicViewProps): import("react").JSX.Element | null;
42
61
  //# sourceMappingURL=dynamic-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-view.d.ts","sourceRoot":"","sources":["../src/dynamic-view.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGzE;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC7B,QAAQ,GAAG,OAAO,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMtE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,gBAAgB,EAAE,MAAM,GAAG,SAAS,GACrC,MAAM,GAAG,SAAS,CAEpB;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACvD;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO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