vitral 0.8.0 → 0.9.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.
@@ -41,10 +41,21 @@ function reactRemote(Component) {
41
41
  const start = (el, props, ctx, hydrate) => {
42
42
  const tree = (p) => /* @__PURE__ */ jsx(RemoteTree, { Component, props: p, ctx });
43
43
  const options = { onUncaughtError: (e) => ctx.reportError(e) };
44
+ const scope = ctx.portalContainer === document.body && el.closest("[data-vitral-scope]")?.getAttribute("data-vitral-scope");
45
+ let stop;
46
+ let gone = false;
47
+ if (scope) void import("./portals-AK5XA2M5.js").then((m) => gone || (stop = m.scopePortals(el, scope)));
44
48
  const root = hydrate ? hydrateRoot(el, tree(props), options) : createRoot(el, options);
45
49
  const render = (p) => root.render(tree(p));
46
50
  if (!hydrate) render(props);
47
- return { update: render, unmount: () => root.unmount() };
51
+ return {
52
+ update: render,
53
+ unmount: () => {
54
+ root.unmount();
55
+ gone = true;
56
+ stop?.();
57
+ }
58
+ };
48
59
  };
49
60
  return defineRemote({
50
61
  mount: (el, props, ctx) => start(el, props, ctx, false),
@@ -151,7 +151,7 @@ async function groups(list, root, entry, resolveId) {
151
151
  }
152
152
  try {
153
153
  const mod = await import(pathToFileURL(found.id.split("?")[0]).href);
154
- const extra = mod.default && typeof mod.default === "object" ? Object.keys(mod.default) : [];
154
+ const extra = mod.default && (typeof mod.default === "object" || typeof mod.default === "function") ? Object.keys(mod.default) : [];
155
155
  group.names[spec] = [.../* @__PURE__ */ new Set([...Object.keys(mod), ...extra])].filter((n) => n !== "default" && ident.test(n));
156
156
  } catch {
157
157
  }
@@ -250,9 +250,12 @@ export default {${g.keys.map((k, i) => `${JSON.stringify(k)}: m${i}`).join(", ")
250
250
  }
251
251
  return `import { deps } from ${JSON.stringify(DEPS)}
252
252
  const m = deps[${JSON.stringify(spec)}]
253
- export default m.default ?? m
254
- ` + (names.length ? `export const { ${names.join(", ")} } = m
255
- ` : "");
253
+ const d = m.default ?? m
254
+ export default d
255
+ ` + // `export { v as "delete" }`: nomes que são palavras reservadas (`axios.delete`) também saem.
256
+ names.map((n, i) => `const v${i} = ${JSON.stringify(n)} in m ? m[${JSON.stringify(n)}] : d?.[${JSON.stringify(n)}]
257
+ export { v${i} as ${JSON.stringify(n)} }
258
+ `).join("");
256
259
  }
257
260
  if (id.startsWith(DEEP)) {
258
261
  const file = id.slice(DEEP.length);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  subpaths
3
- } from "./chunk-6AFVJCQG.js";
3
+ } from "./chunk-P5JSFGPI.js";
4
4
 
5
5
  // src/next-config.ts
6
6
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
package/dist/next-host.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  Remote,
4
4
  preload
5
- } from "./chunk-4IWZIFAL.js";
5
+ } from "./chunk-JKNTXBZH.js";
6
6
  import "./chunk-B2MPYF4M.js";
7
7
  import "./chunk-ZJ4IM2PZ.js";
8
8
  import "./chunk-NTXMEZIZ.js";
@@ -34,8 +34,7 @@ function setup() {
34
34
  }
35
35
  function interceptNavigation() {
36
36
  const nav = globalThis.navigation;
37
- if (!nav) return () => {
38
- };
37
+ if (!nav) return interceptClicks();
39
38
  let last;
40
39
  const done = () => last = void 0;
41
40
  const on = (e) => {
@@ -55,6 +54,20 @@ function interceptNavigation() {
55
54
  Router.events.off("routeChangeComplete", done);
56
55
  };
57
56
  }
57
+ function interceptClicks() {
58
+ const on = (e) => {
59
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
60
+ const a = e.target?.closest?.("a[href]");
61
+ if (!a || a.target && a.target !== "_self" || a.hasAttribute("download")) return;
62
+ const url = new URL(a.href, location.href);
63
+ if (url.origin !== location.origin || !remoteFor(url.pathname)) return;
64
+ if (url.pathname === location.pathname && url.search === location.search && url.hash) return;
65
+ e.preventDefault();
66
+ void Router.push(url.pathname + url.search + url.hash);
67
+ };
68
+ document.addEventListener("click", on);
69
+ return () => document.removeEventListener("click", on);
70
+ }
58
71
  function VitralNext() {
59
72
  setup();
60
73
  useEffect(() => {
@@ -0,0 +1,22 @@
1
+ // src/core/portals.ts
2
+ function scopePortals(root, scope) {
3
+ const owner = (node) => {
4
+ const key = Object.keys(node).find((k) => k.startsWith("__reactFiber$"));
5
+ for (let f = key && node[key]; f; f = f.return) {
6
+ const s = f.stateNode;
7
+ if (s && s !== node && s.nodeType === 1 && root.contains(s)) return true;
8
+ if (f.tag === 3) return s?.containerInfo === root;
9
+ }
10
+ return false;
11
+ };
12
+ const mark = (n) => {
13
+ if (n instanceof Element && !n.hasAttribute("data-vitral-scope") && owner(n)) n.setAttribute("data-vitral-scope", scope);
14
+ };
15
+ const watch = new MutationObserver((list) => list.forEach((r) => r.addedNodes.forEach(mark)));
16
+ watch.observe(document.body, { childList: true });
17
+ document.body.childNodes.forEach(mark);
18
+ return () => watch.disconnect();
19
+ }
20
+ export {
21
+ scopePortals
22
+ };
package/dist/react.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  usePortalContainer,
9
9
  useShared,
10
10
  useVitral
11
- } from "./chunk-4IWZIFAL.js";
11
+ } from "./chunk-JKNTXBZH.js";
12
12
  import "./chunk-B2MPYF4M.js";
13
13
  import "./chunk-ZJ4IM2PZ.js";
14
14
  import "./chunk-NTXMEZIZ.js";
package/dist/vite.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  dedupeHooks,
4
4
  dedupeIds,
5
5
  groups
6
- } from "./chunk-6AFVJCQG.js";
6
+ } from "./chunk-P5JSFGPI.js";
7
7
  import {
8
8
  extractProps,
9
9
  typesFile
package/dist/vue.d.ts CHANGED
@@ -127,8 +127,8 @@ declare const VitralRemote: vue.DefineComponent<vue.ExtractPropTypes<{
127
127
  onError?: ((...args: any[]) => any) | undefined;
128
128
  onReady?: ((...args: any[]) => any) | undefined;
129
129
  }>, {
130
- name: string;
131
130
  isolate: Isolation;
131
+ name: string;
132
132
  priority: RequestPriority;
133
133
  loading: Loading;
134
134
  src: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitral",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Micro-frontends de qualquer framework numa página só, sem configuração de build no host. React, Next, Vue, Nuxt, Angular, Svelte, Solid, Preact, Lit e JS puro.",
5
5
  "keywords": [
6
6
  "micro-frontend",
@@ -266,7 +266,8 @@
266
266
  "./expose-*",
267
267
  "./capture-*",
268
268
  "./channel-*",
269
- "./hydrate-*"
269
+ "./hydrate-*",
270
+ "./portals-*"
270
271
  ],
271
272
  "limit": "4.83 kB"
272
273
  },
@@ -285,7 +286,8 @@
285
286
  "./expose-*",
286
287
  "./capture-*",
287
288
  "./channel-*",
288
- "./hydrate-*"
289
+ "./hydrate-*",
290
+ "./portals-*"
289
291
  ],
290
292
  "limit": "5.78 kB"
291
293
  },
@@ -327,7 +329,8 @@
327
329
  "./expose-*",
328
330
  "./capture-*",
329
331
  "./channel-*",
330
- "./hydrate-*"
332
+ "./hydrate-*",
333
+ "./portals-*"
331
334
  ],
332
335
  "limit": "5.53 kB"
333
336
  },
@@ -346,7 +349,8 @@
346
349
  "./expose-*",
347
350
  "./capture-*",
348
351
  "./channel-*",
349
- "./hydrate-*"
352
+ "./hydrate-*",
353
+ "./portals-*"
350
354
  ],
351
355
  "limit": "5.76 kB"
352
356
  },
@@ -392,9 +396,10 @@
392
396
  "./expose-*",
393
397
  "./capture-*",
394
398
  "./channel-*",
395
- "./hydrate-*"
399
+ "./hydrate-*",
400
+ "./portals-*"
396
401
  ],
397
- "limit": "6.27 kB"
402
+ "limit": "6.33 kB"
398
403
  },
399
404
  {
400
405
  "name": "vue",
@@ -412,7 +417,8 @@
412
417
  "./expose-*",
413
418
  "./capture-*",
414
419
  "./channel-*",
415
- "./hydrate-*"
420
+ "./hydrate-*",
421
+ "./portals-*"
416
422
  ],
417
423
  "limit": "6.12 kB"
418
424
  },
@@ -431,7 +437,8 @@
431
437
  "./expose-*",
432
438
  "./capture-*",
433
439
  "./channel-*",
434
- "./hydrate-*"
440
+ "./hydrate-*",
441
+ "./portals-*"
435
442
  ],
436
443
  "limit": "6.49 kB"
437
444
  },
@@ -456,7 +463,8 @@
456
463
  "./expose-*",
457
464
  "./capture-*",
458
465
  "./channel-*",
459
- "./hydrate-*"
466
+ "./hydrate-*",
467
+ "./portals-*"
460
468
  ]
461
469
  },
462
470
  {
@@ -469,7 +477,8 @@
469
477
  "./stale-*",
470
478
  "./channel-*",
471
479
  "./reframe-*",
472
- "./hydrate-*"
480
+ "./hydrate-*",
481
+ "./portals-*"
473
482
  ]
474
483
  },
475
484
  {
@@ -511,7 +520,8 @@
511
520
  "./stale-*",
512
521
  "./channel-*",
513
522
  "./reframe-*",
514
- "./hydrate-*"
523
+ "./hydrate-*",
524
+ "./portals-*"
515
525
  ]
516
526
  },
517
527
  {