@plasmicapp/loader-react 1.0.344 → 1.0.346

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.js CHANGED
@@ -269,17 +269,9 @@ function MaybeWrap(props) {
269
269
  function uniq(elements) {
270
270
  return Array.from(new Set(elements));
271
271
  }
272
- function uniqBy(elements, iterator) {
273
- const vis = /* @__PURE__ */ new Set();
274
- const filtered = [];
275
- for (const elt of elements) {
276
- const key = iterator(elt);
277
- if (!vis.has(key)) {
278
- vis.add(key);
279
- filtered.push(elt);
280
- }
281
- }
282
- return filtered;
272
+ function intersect(a, b) {
273
+ const setB = new Set(b);
274
+ return a.filter((elt) => setB.has(elt));
283
275
  }
284
276
 
285
277
  // src/variation.ts
@@ -622,14 +614,7 @@ function prepComponentData(bundle, compMetas, opts) {
622
614
  };
623
615
  }
624
616
  function mergeBundles(target, from) {
625
- var _a;
626
- const existingCompIds = new Set(target.components.map((c) => c.id));
627
- const newCompMetas = from.components.filter(
628
- (m) => !existingCompIds.has(m.id)
629
- );
630
- if (newCompMetas.length > 0) {
631
- target = __spreadProps(__spreadValues({}, target), { components: [...target.components, ...newCompMetas] });
632
- }
617
+ var _a, _b, _c, _d, _e;
633
618
  const existingProjects = new Set(target.projects.map((p) => p.id));
634
619
  const newProjects = from.projects.filter((p) => !existingProjects.has(p.id));
635
620
  if (newProjects.length > 0) {
@@ -637,6 +622,35 @@ function mergeBundles(target, from) {
637
622
  projects: [...target.projects, ...newProjects]
638
623
  });
639
624
  }
625
+ const existingCompIds = new Set(target.components.map((c) => c.id));
626
+ function shouldIncludeComponentInBundle(c) {
627
+ if (existingCompIds.has(c.id)) {
628
+ return false;
629
+ }
630
+ if (!existingProjects.has(c.projectId)) {
631
+ return true;
632
+ }
633
+ if (!target.filteredIds[c.projectId]) {
634
+ return true;
635
+ }
636
+ return target.filteredIds[c.projectId].includes(c.id);
637
+ }
638
+ const newCompMetas = from.components.filter(
639
+ (m) => shouldIncludeComponentInBundle(m)
640
+ );
641
+ if (newCompMetas.length > 0) {
642
+ target = __spreadProps(__spreadValues({}, target), { components: [...target.components, ...newCompMetas] });
643
+ Object.entries(from.filteredIds).forEach(([projectId, ids]) => {
644
+ if (!target.filteredIds[projectId]) {
645
+ target.filteredIds[projectId] = [...ids];
646
+ } else {
647
+ target.filteredIds[projectId] = intersect(
648
+ target.filteredIds[projectId],
649
+ ids
650
+ );
651
+ }
652
+ });
653
+ }
640
654
  const existingModules = {
641
655
  browser: new Set(target.modules.browser.map((m) => m.fileName)),
642
656
  server: new Set(target.modules.server.map((m) => m.fileName))
@@ -667,12 +681,18 @@ function mergeBundles(target, from) {
667
681
  });
668
682
  }
669
683
  const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
670
- const newSplits = (_a = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a : [];
684
+ const newSplits = (_a = from.activeSplits.filter(
685
+ // Don't include splits belonging to projects already present
686
+ // in the target bundle
687
+ (s) => !existingSplitIds.has(s.id) && !existingProjects.has(s.projectId)
688
+ )) != null ? _a : [];
671
689
  if (newSplits.length > 0) {
672
690
  target = __spreadProps(__spreadValues({}, target), {
673
691
  activeSplits: [...target.activeSplits, ...newSplits]
674
692
  });
675
693
  }
694
+ target.bundleKey = (_c = (_b = target.bundleKey) != null ? _b : from.bundleKey) != null ? _c : null;
695
+ target.deferChunksByDefault = (_e = (_d = target.deferChunksByDefault) != null ? _d : from.deferChunksByDefault) != null ? _e : false;
676
696
  return target;
677
697
  }
678
698
  var convertBundlesToComponentRenderData = (bundles, compMetas) => {
@@ -788,7 +808,8 @@ var BaseInternalPlasmicComponentLoader = class {
788
808
  projects: [],
789
809
  activeSplits: [],
790
810
  bundleKey: null,
791
- deferChunksByDefault: false
811
+ deferChunksByDefault: false,
812
+ filteredIds: {}
792
813
  };
793
814
  this.opts = args.opts;
794
815
  this.fetcher = args.fetcher;
@@ -899,7 +920,7 @@ var BaseInternalPlasmicComponentLoader = class {
899
920
  });
900
921
  }
901
922
  mergeBundle(newBundle) {
902
- var _a, _b, _c, _d, _e;
923
+ var _a, _b;
903
924
  newBundle.bundleKey = (_a = newBundle.bundleKey) != null ? _a : null;
904
925
  if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
905
926
  console.warn(
@@ -909,39 +930,8 @@ ${newBundle.bundleKey}
909
930
  ${this.bundle.bundleKey}`
910
931
  );
911
932
  }
912
- const bundles = [this.bundle, newBundle];
913
- this.bundle = {
914
- activeSplits: uniqBy(
915
- bundles.flatMap((bundle) => bundle.activeSplits),
916
- (split) => split.id
917
- ),
918
- components: uniqBy(
919
- bundles.flatMap((bundle) => bundle.components),
920
- (c) => c.id
921
- ),
922
- globalGroups: uniqBy(
923
- bundles.flatMap((bundle) => bundle.globalGroups),
924
- (g) => g.id
925
- ),
926
- modules: {
927
- browser: uniqBy(
928
- bundles.flatMap((bundle) => bundle.modules.browser),
929
- (m) => m.fileName
930
- ),
931
- server: uniqBy(
932
- bundles.flatMap((bundle) => bundle.modules.server),
933
- (m) => m.fileName
934
- )
935
- },
936
- projects: uniqBy(
937
- bundles.flatMap((bundle) => bundle.projects),
938
- (p) => p.id
939
- ),
940
- // Avoid `undefined` as it cannot be serialized as JSON
941
- bundleKey: (_c = (_b = newBundle.bundleKey) != null ? _b : this.bundle.bundleKey) != null ? _c : null,
942
- deferChunksByDefault: (_d = newBundle.deferChunksByDefault) != null ? _d : false
943
- };
944
- (_e = this.onBundleMerged) == null ? void 0 : _e.call(this);
933
+ this.bundle = mergeBundles(newBundle, this.bundle);
934
+ (_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
945
935
  }
946
936
  getBundle() {
947
937
  return this.bundle;
@@ -957,7 +947,8 @@ ${this.bundle.bundleKey}`
957
947
  projects: [],
958
948
  activeSplits: [],
959
949
  bundleKey: null,
960
- deferChunksByDefault: false
950
+ deferChunksByDefault: false,
951
+ filteredIds: {}
961
952
  };
962
953
  this.registry.clear();
963
954
  }