@bluealba/pae-ui-react-core 4.7.0 → 4.8.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.
@@ -0,0 +1,12 @@
1
+ import { FC, ReactNode } from 'react';
2
+
3
+ export interface PortalContainerProviderProps {
4
+ container: HTMLElement | null;
5
+ children: ReactNode;
6
+ }
7
+ export declare const PortalContainerProvider: FC<PortalContainerProviderProps>;
8
+ /**
9
+ * Returns the portal container to use, or undefined to let Radix default to
10
+ * document.body.
11
+ */
12
+ export declare const usePortalContainer: () => HTMLElement | undefined;
@@ -1,4 +1,4 @@
1
1
  export declare const useTheme: () => {
2
- theme: "light" | "dark";
2
+ theme: "dark" | "light";
3
3
  setTheme: (value: "light" | "dark") => void;
4
4
  };
@@ -8,3 +8,5 @@ export { default as ThemeToggle } from './ThemeToggle/ThemeToggle';
8
8
  export { useTheme } from './ThemeToggle/useTheme';
9
9
  export { default as FragmentSlot } from './FragmentSlot';
10
10
  export type { FragmentSlotProps } from './FragmentSlot';
11
+ export { PortalContainerProvider, usePortalContainer } from './PortalContainerContext';
12
+ export type { PortalContainerProviderProps } from './PortalContainerContext';
@@ -4,7 +4,45 @@ import { RootComponentProps } from '../MicrofrontendProps';
4
4
 
5
5
  export interface MicroFrontendOptions<T extends RootComponentProps> extends SingleSpaReactOpts<T> {
6
6
  rootComponent: FC<T>;
7
+ /**
8
+ * Mount this module inside its own shadow root (attached to a dedicated child
9
+ * of the host element the platform resolves from ui.mountAtSelector, so the
10
+ * shared host stays usable by other modules mounted there later).
11
+ *
12
+ * Why: global CSS from OTHER modules mounted at the same time (a framework
13
+ * reset, unlayered utilities, ...) cannot reach this module's DOM, and this
14
+ * module's own DOM cannot be affected by it. This is the only isolation
15
+ * that works for SIMULTANEOUSLY mounted modules (e.g. fragments side by side).
16
+ *
17
+ * What module authors must know:
18
+ * - Design tokens (CSS custom properties) inherit into the shadow root —
19
+ * they keep working.
20
+ * - Selectors like `:root`, `html` or `body` do NOT match inside a shadow
21
+ * root; use `:host` instead.
22
+ * - CSS built with the SDK (`pae-ui-sdk`) is automatically encapsulated. The
23
+ * module's `<style data-pae-module>` nodes are kept out of the light-DOM
24
+ * `document.head` and live inside the shadow root, including lazy chunks and
25
+ * HMR updates. No extra setup needed for webpack-imported stylesheets.
26
+ * - If you inject styles by other means (e.g. dynamic `<style>` creation,
27
+ * third-party runtime CSS-in-JS), access the shadow root via:
28
+ * `usePortalContainer()?.getRootNode() as ShadowRoot | undefined`
29
+ * - Platform core components (Dialog, Tooltip) portal into the shadow root
30
+ * automatically when the module author passes the container from
31
+ * `usePortalContainer()` to the `container` prop of their portal component.
32
+ * Third-party overlay libraries default to document.body: pass them the
33
+ * container from `usePortalContainer()` to keep them inside the shadow root.
34
+ */
35
+ shadowDom?: boolean;
7
36
  }
37
+ /**
38
+ * Marker set on a shadow module's exported `mount` so other core code can detect,
39
+ * after a bare `System.import` (e.g. reading a module's `menu`/`icon` without
40
+ * mounting it), that the module is shadow-isolated and its styles must be evacuated
41
+ * from `document.head`. See {@link hasShadowDomMarker} and useApplicationJSModule.
42
+ */
43
+ export declare const SHADOW_DOM_MARKER = "__paeShadowDom";
44
+ /** True if `mount` is a shadow module's lifecycle (carries {@link SHADOW_DOM_MARKER}). */
45
+ export declare const hasShadowDomMarker: (mount: unknown) => boolean;
8
46
  /**
9
47
  * Main function to create a PAE micro-frontend module.
10
48
  * Internally we use single-spa so currently our API is pretty similar.
@@ -12,6 +50,10 @@ export interface MicroFrontendOptions<T extends RootComponentProps> extends Sing
12
50
  *
13
51
  * All PAE micro-frontends are wrapped in PAE components that provides react context later used
14
52
  * by the provided hooks.
53
+ *
54
+ * When `shadowDom: true` is passed the module is mounted inside its own open shadow
55
+ * root (see {@link withShadowDom}), isolating it from global CSS in the light DOM and
56
+ * keeping its own CSS out of `document.head`.
15
57
  */
16
- declare const initializeMicroFrontend: <T extends RootComponentProps>({ rootComponent, ...opts }: MicroFrontendOptions<T>) => ReactAppOrParcel<T>;
58
+ declare const initializeMicroFrontend: <T extends RootComponentProps>({ rootComponent, shadowDom, ...opts }: MicroFrontendOptions<T>) => ReactAppOrParcel<T>;
17
59
  export default initializeMicroFrontend;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Per-module style routing registry, shared process-wide via `window`.
3
+ *
4
+ * The CSS of an isolated (`shadowDom`) micro-frontend must never leak into the
5
+ * light-DOM `document.head`. style-loader injects `<style data-pae-module=name>`
6
+ * nodes into the head at bundle-load (e.g. when the shell imports a module just to
7
+ * read its `menu`/`icon`, long before — or without ever — mounting it). This
8
+ * registry holds, per module, a DETACHED holder element that owns those nodes
9
+ * while the module is not mounted (a detached node is not rendered, so its CSS does
10
+ * not apply ⇒ no leak), plus the current `target` where new nodes should go.
11
+ *
12
+ * `initializeMicroFrontend` flips `target` across the lifecycle (holder ⇄ shadow
13
+ * root) and `useApplicationJSModule` evacuates a shadow module's head styles into
14
+ * the holder right after importing it for its exports.
15
+ */
16
+ export interface StyleEntry {
17
+ /** The module name (equals the `data-pae-module` attribute of its style nodes). */
18
+ name: string;
19
+ /** Where newly injected `<style data-pae-module=name>` nodes should be placed now. */
20
+ target: Node;
21
+ /** Detached `<div>` that owns the module's style nodes while it is not mounted. */
22
+ holder: HTMLElement;
23
+ mode: 'detached' | 'shadow';
24
+ }
25
+ /** Get or lazily create the registry entry (with a detached holder) for a module. */
26
+ export declare const getStyleEntry: (moduleName: string) => StyleEntry;
27
+ /**
28
+ * Move every `<style|link data-pae-module=name>` node currently under `from` into
29
+ * `to`. Used to evacuate a module's styles out of `document.head` (into its holder
30
+ * or shadow root) and back into the holder on unmount.
31
+ */
32
+ export declare const moveModuleStyles: (from: ParentNode, to: Node, name: string) => void;
33
+ /**
34
+ * Evacuate a shadow module's styles out of the light-DOM `document.head` into its
35
+ * detached holder, and route future styles there too — unless the module is
36
+ * currently mounted (its target is the live shadow root). Returns the entry.
37
+ */
38
+ export declare const evacuateToHolder: (moduleName: string) => StyleEntry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluealba/pae-ui-react-core",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",