@gears-frontx/react 0.2.0-alpha.2 → 0.2.0-alpha.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/index.cjs CHANGED
@@ -62,7 +62,6 @@ __export(src_exports, {
62
62
  LAYOUT_SLICE_NAME: () => import_framework5.LAYOUT_SLICE_NAME,
63
63
  Language: () => import_framework6.Language,
64
64
  LanguageDisplayMode: () => import_framework6.LanguageDisplayMode,
65
- LayoutDomain: () => import_framework5.LayoutDomain,
66
65
  MOCK_PLUGIN: () => import_framework5.MOCK_PLUGIN,
67
66
  MfeBridgeFactory: () => import_framework14.MfeBridgeFactory,
68
67
  MfeContext: () => MfeContext,
@@ -71,18 +70,15 @@ __export(src_exports, {
71
70
  MfeProvider: () => MfeProvider,
72
71
  MfeRegistry: () => import_framework14.MfeRegistry,
73
72
  MfeRegistryFactory: () => import_framework14.MfeRegistryFactory,
74
- MockEventSource: () => import_framework5.MockEventSource,
75
73
  MockEvents: () => import_framework5.MockEvents,
76
74
  MountStrategy: () => import_framework14.MountStrategy,
77
75
  OptionalMountStrategy: () => import_framework14.OptionalMountStrategy,
78
76
  ParentMfeBridge: () => import_framework14.ParentMfeBridge,
79
77
  RestEndpointProtocol: () => import_framework5.RestEndpointProtocol,
80
- RestMockPlugin: () => import_framework5.RestMockPlugin,
81
78
  RestPlugin: () => import_framework5.RestPlugin,
82
79
  RestPluginWithConfig: () => import_framework5.RestPluginWithConfig,
83
80
  RestProtocol: () => import_framework5.RestProtocol,
84
81
  SUPPORTED_LANGUAGES: () => import_framework5.SUPPORTED_LANGUAGES,
85
- SseMockPlugin: () => import_framework5.SseMockPlugin,
86
82
  SsePlugin: () => import_framework5.SsePlugin,
87
83
  SsePluginWithConfig: () => import_framework5.SsePluginWithConfig,
88
84
  SseProtocol: () => import_framework5.SseProtocol,
@@ -103,14 +99,13 @@ __export(src_exports, {
103
99
  createFrontX: () => import_framework5.createFrontX,
104
100
  createFrontXApp: () => import_framework5.createFrontXApp,
105
101
  createI18nRegistry: () => import_framework5.createI18nRegistry,
106
- createShadowRoot: () => import_framework17.createShadowRoot,
102
+ createShadowRoot: () => import_framework16.createShadowRoot,
107
103
  createSlice: () => import_framework5.createSlice,
108
104
  createStore: () => import_framework5.createStore,
109
105
  createThemeRegistry: () => import_framework5.createThemeRegistry,
110
106
  effects: () => import_framework5.effects,
111
107
  eventBus: () => eventBus2,
112
- extensionScreenSchema: () => import_framework16.extensionScreenSchema,
113
- extractGtsPackage: () => import_framework17.extractGtsPackage,
108
+ extractGtsPackage: () => import_framework16.extractGtsPackage,
114
109
  footerActions: () => import_framework5.footerActions,
115
110
  footerSlice: () => import_framework5.footerSlice,
116
111
  frontxApiTransport: () => import_framework5.frontxApiTransport,
@@ -125,13 +120,12 @@ __export(src_exports, {
125
120
  i18nRegistry: () => import_framework5.i18nRegistry,
126
121
  initMockEffects: () => import_framework5.initMockEffects,
127
122
  initTenantEffects: () => import_framework5.initTenantEffects,
128
- injectCssVariables: () => import_framework17.injectCssVariables,
123
+ injectCssVariables: () => import_framework16.injectCssVariables,
129
124
  invalidateQueryCacheForApp: () => invalidateQueryCacheForApp,
130
125
  isMockPlugin: () => import_framework5.isMockPlugin,
131
126
  isRestShortCircuit: () => import_framework5.isRestShortCircuit,
132
127
  isShortCircuit: () => import_framework5.isShortCircuit,
133
128
  isSseShortCircuit: () => import_framework5.isSseShortCircuit,
134
- languageSchema: () => import_framework16.languageSchema,
135
129
  layout: () => import_framework5.layout,
136
130
  layoutDomainReducers: () => import_framework5.layoutDomainReducers,
137
131
  layoutReducer: () => import_framework5.layoutReducer,
@@ -189,7 +183,6 @@ __export(src_exports, {
189
183
  tenantActions: () => import_framework5.tenantActions,
190
184
  tenantReducer: () => import_framework5.tenantReducer,
191
185
  tenantSlice: () => import_framework5.tenantSlice,
192
- themeSchema: () => import_framework16.themeSchema,
193
186
  themes: () => import_framework5.themes,
194
187
  toggleMenu: () => import_framework5.toggleMenu,
195
188
  toggleMockMode: () => import_framework5.toggleMockMode,
@@ -1282,6 +1275,9 @@ function useRegisteredPackages() {
1282
1275
  // src/mfe/ThemeAwareReactLifecycle.tsx
1283
1276
  var import_client = require("react-dom/client");
1284
1277
  var import_jsx_runtime4 = require("react/jsx-runtime");
1278
+ var ADOPTED_HOST_STYLE_ATTR = "data-frontx-adopted-host-style";
1279
+ var BASE_RESETS_STYLE_ID = "__frontx-base-resets__";
1280
+ var SHELL_OWNED_SHADOW_STYLE_IDS = ["__frontx-shadow-isolation__", "__frontx-css-variables__"];
1285
1281
  function resolveProviderMountOptions(app, bridge, mountContext) {
1286
1282
  const extensionId = mountContext?.extensionId;
1287
1283
  const domainId = mountContext?.domainId;
@@ -1336,27 +1332,108 @@ var ThemeAwareReactLifecycle = class {
1336
1332
  /**
1337
1333
  * Copy all inline <style> and <link rel="stylesheet"> from the host document
1338
1334
  * into the shadow root so that Tailwind and component styles apply inside the MFE.
1335
+ *
1336
+ * The clones are inserted ahead of everything already in the shadow root, never
1337
+ * appended, because adopted host styles are context rather than authority: where
1338
+ * they and the MFE's own CSS declare the same property at equal specificity, the
1339
+ * MFE has to win. Appending inverted that. `MfeHandlerMF` injects the MFE's
1340
+ * compiled stylesheet into the shadow root before it calls mount, so an appended
1341
+ * clone of the shell's Tailwind preflight - whose
1342
+ * `button, [type='button'], [type='reset'], [type='submit']` rule sets
1343
+ * `background-color: transparent` at specificity (0,1,0) - tied with
1344
+ * `@gears-frontx/ui-kit`'s single-class button rule and won on document order,
1345
+ * leaving every kit Button transparent until it was hovered.
1346
+ *
1347
+ * Inserting at the front rather than pushing MFE styles to the back is what makes
1348
+ * the invariant hold for stylesheets that appear after mount too - a lazily
1349
+ * imported component's CSS module, or whatever initializeStyles() adds - since
1350
+ * those land behind the adopted block by construction.
1351
+ *
1352
+ * A cascade layer around the adopted CSS was the alternative and is rejected:
1353
+ * layered rules lose to unlayered ones at *any* specificity, so a host utility
1354
+ * class would stop overriding an MFE element selector. Document order keeps
1355
+ * specificity in charge and only settles the ties.
1356
+ *
1357
+ * The block replaces its predecessor instead of stacking on it, the same
1358
+ * upsert shape `injectStylesheet` and `injectCssVariables` use in
1359
+ * `@gears-frontx/mfes`' shadow utilities, widened from one id-keyed node to a
1360
+ * marked block. Replacement is required rather than tidy: `createShadowRoot`
1361
+ * hands back an existing `element.shadowRoot` instead of attaching a new one,
1362
+ * so remounting the same container runs this method again on a shadow root
1363
+ * that already holds a full adopted block, and appending would grow it once
1364
+ * per mount with no bound. It does not save re-resolving the cloned `<link>`s -
1365
+ * every mount clones them afresh and the browser resolves each clone; what
1366
+ * replacement buys is that the count stays at one block instead of one per
1367
+ * mount.
1368
+ *
1369
+ * The block is rebuilt from the host head rather than left in place, because
1370
+ * the head is not fixed: a lazily imported chunk adds stylesheets to it after
1371
+ * the first mount, and the second mount has to pick those up.
1372
+ *
1373
+ * The fresh block goes in before the previous one comes out. Removing first
1374
+ * leaves the shadow root with no host CSS at all, and everything between that
1375
+ * removal and the insertion is synchronous work in this same task - so the gap
1376
+ * never reaches a paint, but any code that reads computed styles from the tree
1377
+ * in between sees an unstyled one. Inserting first costs one moment with two
1378
+ * blocks present, which changes nothing: the old block is a clone of the same
1379
+ * host head and loses every tie to the new one on document order anyway.
1339
1380
  */
1340
1381
  adoptHostStylesIntoShadowRoot(shadowRoot) {
1341
- const styleElements = document.head.querySelectorAll("style");
1342
- styleElements.forEach((el) => {
1343
- const clone = document.createElement("style");
1344
- clone.textContent = el.textContent ?? "";
1345
- shadowRoot.appendChild(clone);
1346
- });
1347
- const linkElements = document.head.querySelectorAll('link[rel="stylesheet"]');
1348
- linkElements.forEach((el) => {
1349
- const clone = el.cloneNode(true);
1350
- shadowRoot.appendChild(clone);
1382
+ const supersededStyles = Array.from(shadowRoot.querySelectorAll(`[${ADOPTED_HOST_STYLE_ATTR}]`));
1383
+ const adoptedStyles = document.createDocumentFragment();
1384
+ const hostStyleNodes = document.head.querySelectorAll('style, link[rel="stylesheet"]');
1385
+ hostStyleNodes.forEach((el) => {
1386
+ if (el instanceof HTMLStyleElement) {
1387
+ const clone = document.createElement("style");
1388
+ clone.textContent = el.textContent ?? "";
1389
+ clone.setAttribute(ADOPTED_HOST_STYLE_ATTR, "");
1390
+ adoptedStyles.appendChild(clone);
1391
+ return;
1392
+ }
1393
+ const linkClone = el.cloneNode(true);
1394
+ linkClone.setAttribute(ADOPTED_HOST_STYLE_ATTR, "");
1395
+ adoptedStyles.appendChild(linkClone);
1351
1396
  });
1397
+ shadowRoot.insertBefore(adoptedStyles, shadowRoot.firstChild);
1398
+ supersededStyles.forEach((el) => el.remove());
1352
1399
  }
1353
1400
  /**
1354
1401
  * Box-model resets and :host defaults needed inside every shadow root.
1355
1402
  * These aren't part of Tailwind's compiled output but are required for
1356
1403
  * consistent rendering across browsers.
1404
+ *
1405
+ * Reuses the node a previous mount left behind, exactly as `injectStylesheet`
1406
+ * does in `@gears-frontx/mfes`' shadow utilities: a remount runs against a
1407
+ * shadow root that `createShadowRoot` handed back intact, and appending a
1408
+ * second copy would add one node per mount forever.
1409
+ *
1410
+ * Reuse alone is not enough, which is why the node is also positioned on every
1411
+ * mount rather than left where the previous one sat. These resets are context
1412
+ * like the adopted block is - `border-color: currentColor` on `*` is a 0-0-0
1413
+ * declaration that beats an MFE preflight's own 0-0-0 reset purely on document
1414
+ * order - so they have to stay ahead of the MFE's CSS, and where they land is
1415
+ * not stable on its own. `MfeHandlerMF.wrapLifecycleWithStylesheets` removes the
1416
+ * MFE's stylesheet on unmount and appends a fresh one before the next mount, so
1417
+ * a node merely left in place ends up ahead of that stylesheet on a remount and
1418
+ * behind it on the first mount: two different cascades for one component.
1419
+ * Anchoring it to the end of the shell-owned head gives every mount the same
1420
+ * order - adopted block, isolation, resets, MFE - which is also the order the
1421
+ * adoption method's invariant is written against.
1422
+ *
1423
+ * With no shell-owned node to anchor to, the resets go to the front. That is the
1424
+ * plain-`Element` container: no adopted block, no isolation style, and the MFE
1425
+ * stylesheet already appended by the handler, so the front is again the only
1426
+ * position that leaves the MFE winning ties.
1427
+ *
1428
+ * Looked up by attribute-selector form rather than `getElementById`, which
1429
+ * `ShadowRoot` has but `Element` does not, and this hook takes either.
1357
1430
  */
1358
1431
  injectBaseResets(container) {
1359
- const style = document.createElement("style");
1432
+ const existing = container.querySelector(
1433
+ `style[id="${BASE_RESETS_STYLE_ID}"]`
1434
+ );
1435
+ const style = existing ?? document.createElement("style");
1436
+ style.id = BASE_RESETS_STYLE_ID;
1360
1437
  style.textContent = `
1361
1438
  *, *::before, *::after {
1362
1439
  box-sizing: border-box;
@@ -1374,7 +1451,17 @@ var ThemeAwareReactLifecycle = class {
1374
1451
  background-color: hsl(var(--background));
1375
1452
  }
1376
1453
  `;
1377
- container.appendChild(style);
1454
+ const shellOwnedHead = container.querySelectorAll(
1455
+ [
1456
+ `[${ADOPTED_HOST_STYLE_ATTR}]`,
1457
+ ...SHELL_OWNED_SHADOW_STYLE_IDS.map((id) => `[id="${id}"]`)
1458
+ ].join(", ")
1459
+ );
1460
+ const lastShellOwnedNode = shellOwnedHead[shellOwnedHead.length - 1];
1461
+ container.insertBefore(
1462
+ style,
1463
+ lastShellOwnedNode ? lastShellOwnedNode.nextSibling : container.firstChild
1464
+ );
1378
1465
  }
1379
1466
  /**
1380
1467
  * Hook for subclasses to inject additional CSS not covered by the adopted host
@@ -1446,8 +1533,7 @@ var import_framework14 = require("@gears-frontx/framework");
1446
1533
  var import_framework15 = require("@gears-frontx/framework");
1447
1534
  var import_framework16 = require("@gears-frontx/framework");
1448
1535
  var import_framework17 = require("@gears-frontx/framework");
1449
- var import_framework18 = require("@gears-frontx/framework");
1450
- var eventBus2 = import_framework18.eventBus;
1536
+ var eventBus2 = import_framework17.eventBus;
1451
1537
  // Annotate the CommonJS export names for ESM import in node:
1452
1538
  0 && (module.exports = {
1453
1539
  ACCOUNTS_DOMAIN,
@@ -1482,7 +1568,6 @@ var eventBus2 = import_framework18.eventBus;
1482
1568
  LAYOUT_SLICE_NAME,
1483
1569
  Language,
1484
1570
  LanguageDisplayMode,
1485
- LayoutDomain,
1486
1571
  MOCK_PLUGIN,
1487
1572
  MfeBridgeFactory,
1488
1573
  MfeContext,
@@ -1491,18 +1576,15 @@ var eventBus2 = import_framework18.eventBus;
1491
1576
  MfeProvider,
1492
1577
  MfeRegistry,
1493
1578
  MfeRegistryFactory,
1494
- MockEventSource,
1495
1579
  MockEvents,
1496
1580
  MountStrategy,
1497
1581
  OptionalMountStrategy,
1498
1582
  ParentMfeBridge,
1499
1583
  RestEndpointProtocol,
1500
- RestMockPlugin,
1501
1584
  RestPlugin,
1502
1585
  RestPluginWithConfig,
1503
1586
  RestProtocol,
1504
1587
  SUPPORTED_LANGUAGES,
1505
- SseMockPlugin,
1506
1588
  SsePlugin,
1507
1589
  SsePluginWithConfig,
1508
1590
  SseProtocol,
@@ -1529,7 +1611,6 @@ var eventBus2 = import_framework18.eventBus;
1529
1611
  createThemeRegistry,
1530
1612
  effects,
1531
1613
  eventBus,
1532
- extensionScreenSchema,
1533
1614
  extractGtsPackage,
1534
1615
  footerActions,
1535
1616
  footerSlice,
@@ -1551,7 +1632,6 @@ var eventBus2 = import_framework18.eventBus;
1551
1632
  isRestShortCircuit,
1552
1633
  isShortCircuit,
1553
1634
  isSseShortCircuit,
1554
- languageSchema,
1555
1635
  layout,
1556
1636
  layoutDomainReducers,
1557
1637
  layoutReducer,
@@ -1609,7 +1689,6 @@ var eventBus2 = import_framework18.eventBus;
1609
1689
  tenantActions,
1610
1690
  tenantReducer,
1611
1691
  tenantSlice,
1612
- themeSchema,
1613
1692
  themes,
1614
1693
  toggleMenu,
1615
1694
  toggleMockMode,