@plasmicapp/loader-react 1.0.340 → 1.0.342
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.d.ts +242 -70
- package/dist/index.esm.js +265 -268
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +259 -263
- package/dist/index.js.map +4 -4
- package/dist/react-server.d.ts +377 -32
- package/dist/react-server.esm.js +1035 -28
- package/dist/react-server.esm.js.map +4 -4
- package/dist/react-server.js +1030 -27
- package/dist/react-server.js.map +4 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -92,12 +92,12 @@ __export(src_exports, {
|
|
|
92
92
|
PlasmicComponentLoader: () => PlasmicComponentLoader,
|
|
93
93
|
PlasmicRootProvider: () => PlasmicRootProvider,
|
|
94
94
|
convertBundlesToComponentRenderData: () => convertBundlesToComponentRenderData,
|
|
95
|
-
extractPlasmicQueryData: () =>
|
|
95
|
+
extractPlasmicQueryData: () => extractPlasmicQueryData,
|
|
96
96
|
extractPlasmicQueryDataFromElement: () => extractPlasmicQueryDataFromElement,
|
|
97
97
|
hydrateFromElement: () => hydrateFromElement,
|
|
98
98
|
initPlasmicLoader: () => initPlasmicLoader,
|
|
99
99
|
matchesPagePath: () => matchesPagePath,
|
|
100
|
-
plasmicPrepass: () =>
|
|
100
|
+
plasmicPrepass: () => plasmicPrepass,
|
|
101
101
|
renderToElement: () => renderToElement,
|
|
102
102
|
renderToString: () => renderToString,
|
|
103
103
|
repeatedElement: () => import_host3.repeatedElement,
|
|
@@ -110,19 +110,22 @@ __export(src_exports, {
|
|
|
110
110
|
});
|
|
111
111
|
module.exports = __toCommonJS(src_exports);
|
|
112
112
|
|
|
113
|
-
// src/loader.ts
|
|
113
|
+
// src/loader-client.ts
|
|
114
114
|
var PlasmicDataSourcesContext = __toESM(require("@plasmicapp/data-sources-context"));
|
|
115
115
|
var PlasmicHost = __toESM(require("@plasmicapp/host"));
|
|
116
116
|
var import_host2 = require("@plasmicapp/host");
|
|
117
|
-
var
|
|
118
|
-
var import_loader_fetcher = require("@plasmicapp/loader-fetcher");
|
|
119
|
-
var import_loader_splits = require("@plasmicapp/loader-splits");
|
|
117
|
+
var import_loader_core3 = require("@plasmicapp/loader-core");
|
|
120
118
|
var PlasmicQuery = __toESM(require("@plasmicapp/query"));
|
|
121
119
|
var import_react = __toESM(require("react"));
|
|
122
120
|
var import_react_dom = __toESM(require("react-dom"));
|
|
123
121
|
var jsxDevRuntime = __toESM(require("react/jsx-dev-runtime"));
|
|
124
122
|
var jsxRuntime = __toESM(require("react/jsx-runtime"));
|
|
125
123
|
|
|
124
|
+
// src/PlasmicRootProvider.tsx
|
|
125
|
+
var import_host = require("@plasmicapp/host");
|
|
126
|
+
var import_query = require("@plasmicapp/query");
|
|
127
|
+
var React2 = __toESM(require("react"));
|
|
128
|
+
|
|
126
129
|
// src/utils.tsx
|
|
127
130
|
var import_pascalcase = __toESM(require("pascalcase"));
|
|
128
131
|
var React = __toESM(require("react"));
|
|
@@ -267,80 +270,6 @@ function uniq(elements) {
|
|
|
267
270
|
return Array.from(new Set(elements));
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
// src/component-lookup.ts
|
|
271
|
-
function getFirstCompMeta(metas, lookup) {
|
|
272
|
-
const filtered = getCompMetas(metas, lookup);
|
|
273
|
-
return filtered.length === 0 ? void 0 : filtered[0];
|
|
274
|
-
}
|
|
275
|
-
var ComponentLookup = class {
|
|
276
|
-
constructor(bundle, registry) {
|
|
277
|
-
this.bundle = bundle;
|
|
278
|
-
this.registry = registry;
|
|
279
|
-
}
|
|
280
|
-
getComponentMeta(spec) {
|
|
281
|
-
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
282
|
-
return compMeta;
|
|
283
|
-
}
|
|
284
|
-
getComponent(spec, opts = {}) {
|
|
285
|
-
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
286
|
-
if (!compMeta) {
|
|
287
|
-
throw new Error(`Component not found: ${spec}`);
|
|
288
|
-
}
|
|
289
|
-
const moduleName = compMeta.entry;
|
|
290
|
-
if (!this.registry.hasModule(moduleName, opts)) {
|
|
291
|
-
throw new Error(`Component not yet fetched: ${compMeta.name}`);
|
|
292
|
-
}
|
|
293
|
-
const entry = this.registry.load(moduleName, {
|
|
294
|
-
forceOriginal: opts.forceOriginal
|
|
295
|
-
});
|
|
296
|
-
return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
297
|
-
}
|
|
298
|
-
hasComponent(spec) {
|
|
299
|
-
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
300
|
-
if (compMeta) {
|
|
301
|
-
return this.registry.hasModule(compMeta.entry);
|
|
302
|
-
}
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
getGlobalContexts() {
|
|
306
|
-
const customGlobalMetas = this.bundle.globalGroups.filter(
|
|
307
|
-
(m) => m.type === "global-user-defined"
|
|
308
|
-
);
|
|
309
|
-
return customGlobalMetas.map((meta) => ({
|
|
310
|
-
meta,
|
|
311
|
-
context: this.registry.load(meta.contextFile).default
|
|
312
|
-
}));
|
|
313
|
-
}
|
|
314
|
-
getGlobalContextsProvider(spec) {
|
|
315
|
-
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
316
|
-
const projectMeta = compMeta ? this.bundle.projects.find((x) => x.id === compMeta.projectId) : void 0;
|
|
317
|
-
if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
|
|
318
|
-
return void 0;
|
|
319
|
-
}
|
|
320
|
-
const entry = this.registry.load(
|
|
321
|
-
projectMeta.globalContextsProviderFileName
|
|
322
|
-
);
|
|
323
|
-
return typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
324
|
-
}
|
|
325
|
-
getRootProvider() {
|
|
326
|
-
const entry = this.registry.load("root-provider.js");
|
|
327
|
-
return entry.default;
|
|
328
|
-
}
|
|
329
|
-
getCss() {
|
|
330
|
-
return this.bundle.modules.browser.filter(
|
|
331
|
-
(mod) => mod.type === "asset" && mod.fileName.endsWith("css")
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
getRemoteFonts() {
|
|
335
|
-
return this.bundle.projects.flatMap((p) => p.remoteFonts);
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
// src/PlasmicRootProvider.tsx
|
|
340
|
-
var import_host = require("@plasmicapp/host");
|
|
341
|
-
var import_query = require("@plasmicapp/query");
|
|
342
|
-
var React2 = __toESM(require("react"));
|
|
343
|
-
|
|
344
273
|
// src/variation.ts
|
|
345
274
|
function getPlasmicCookieValues() {
|
|
346
275
|
return Object.fromEntries(
|
|
@@ -583,6 +512,11 @@ function createUseGlobalVariant(name, projectId) {
|
|
|
583
512
|
};
|
|
584
513
|
}
|
|
585
514
|
|
|
515
|
+
// src/loader-shared.ts
|
|
516
|
+
var import_loader_core2 = require("@plasmicapp/loader-core");
|
|
517
|
+
var import_loader_fetcher = require("@plasmicapp/loader-fetcher");
|
|
518
|
+
var import_loader_splits = require("@plasmicapp/loader-splits");
|
|
519
|
+
|
|
586
520
|
// src/bundles.ts
|
|
587
521
|
var import_loader_core = require("@plasmicapp/loader-core");
|
|
588
522
|
function getUsedComps(allComponents, entryCompIds) {
|
|
@@ -719,9 +653,101 @@ var convertBundlesToComponentRenderData = (bundles, compMetas) => {
|
|
|
719
653
|
return prepComponentData(mergedBundles, compMetas);
|
|
720
654
|
};
|
|
721
655
|
|
|
722
|
-
// src/
|
|
723
|
-
|
|
656
|
+
// src/component-lookup.ts
|
|
657
|
+
function getFirstCompMeta(metas, lookup) {
|
|
658
|
+
const filtered = getCompMetas(metas, lookup);
|
|
659
|
+
return filtered.length === 0 ? void 0 : filtered[0];
|
|
660
|
+
}
|
|
661
|
+
var ComponentLookup = class {
|
|
662
|
+
constructor(bundle, registry) {
|
|
663
|
+
this.bundle = bundle;
|
|
664
|
+
this.registry = registry;
|
|
665
|
+
}
|
|
666
|
+
getComponentMeta(spec) {
|
|
667
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
668
|
+
return compMeta;
|
|
669
|
+
}
|
|
670
|
+
getComponent(spec, opts = {}) {
|
|
671
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
672
|
+
if (!compMeta) {
|
|
673
|
+
throw new Error(`Component not found: ${spec}`);
|
|
674
|
+
}
|
|
675
|
+
const moduleName = compMeta.entry;
|
|
676
|
+
if (!this.registry.hasModule(moduleName, opts)) {
|
|
677
|
+
throw new Error(`Component not yet fetched: ${compMeta.name}`);
|
|
678
|
+
}
|
|
679
|
+
const entry = this.registry.load(moduleName, {
|
|
680
|
+
forceOriginal: opts.forceOriginal
|
|
681
|
+
});
|
|
682
|
+
return !opts.forceOriginal && typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
683
|
+
}
|
|
684
|
+
hasComponent(spec) {
|
|
685
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
686
|
+
if (compMeta) {
|
|
687
|
+
return this.registry.hasModule(compMeta.entry);
|
|
688
|
+
}
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
getGlobalContexts() {
|
|
692
|
+
const customGlobalMetas = this.bundle.globalGroups.filter(
|
|
693
|
+
(m) => m.type === "global-user-defined"
|
|
694
|
+
);
|
|
695
|
+
return customGlobalMetas.map((meta) => ({
|
|
696
|
+
meta,
|
|
697
|
+
context: this.registry.load(meta.contextFile).default
|
|
698
|
+
}));
|
|
699
|
+
}
|
|
700
|
+
getGlobalContextsProvider(spec) {
|
|
701
|
+
const compMeta = getFirstCompMeta(this.bundle.components, spec);
|
|
702
|
+
const projectMeta = compMeta ? this.bundle.projects.find((x) => x.id === compMeta.projectId) : void 0;
|
|
703
|
+
if (!projectMeta || !projectMeta.globalContextsProviderFileName || !this.registry.hasModule(projectMeta.globalContextsProviderFileName)) {
|
|
704
|
+
return void 0;
|
|
705
|
+
}
|
|
706
|
+
const entry = this.registry.load(
|
|
707
|
+
projectMeta.globalContextsProviderFileName
|
|
708
|
+
);
|
|
709
|
+
return typeof (entry == null ? void 0 : entry.getPlasmicComponent) === "function" ? entry.getPlasmicComponent() : entry.default;
|
|
710
|
+
}
|
|
711
|
+
getRootProvider() {
|
|
712
|
+
const entry = this.registry.load("root-provider.js");
|
|
713
|
+
return entry.default;
|
|
714
|
+
}
|
|
715
|
+
getCss() {
|
|
716
|
+
return this.bundle.modules.browser.filter(
|
|
717
|
+
(mod) => mod.type === "asset" && mod.fileName.endsWith("css")
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
getRemoteFonts() {
|
|
721
|
+
return this.bundle.projects.flatMap((p) => p.remoteFonts);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// src/loader-shared.ts
|
|
726
|
+
var SUBSTITUTED_COMPONENTS = {};
|
|
727
|
+
var REGISTERED_CODE_COMPONENT_HELPERS = {};
|
|
728
|
+
var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
|
|
729
|
+
var REGISTERED_CUSTOM_FUNCTIONS = {};
|
|
730
|
+
function customFunctionImportAlias(meta) {
|
|
731
|
+
const customFunctionPrefix = `__fn_`;
|
|
732
|
+
return meta.namespace ? `${customFunctionPrefix}${meta.namespace}__${meta.name}` : `${customFunctionPrefix}${meta.name}`;
|
|
733
|
+
}
|
|
734
|
+
function parseFetchComponentDataArgs(...args) {
|
|
735
|
+
let specs;
|
|
736
|
+
let opts;
|
|
737
|
+
if (Array.isArray(args[0])) {
|
|
738
|
+
specs = args[0];
|
|
739
|
+
opts = args[1];
|
|
740
|
+
} else {
|
|
741
|
+
specs = args;
|
|
742
|
+
opts = void 0;
|
|
743
|
+
}
|
|
744
|
+
return { specs, opts };
|
|
745
|
+
}
|
|
746
|
+
var BaseInternalPlasmicComponentLoader = class {
|
|
724
747
|
constructor(args) {
|
|
748
|
+
this.registry = new import_loader_core2.Registry();
|
|
749
|
+
this.globalVariants = [];
|
|
750
|
+
this.subs = [];
|
|
725
751
|
this.bundle = {
|
|
726
752
|
modules: {
|
|
727
753
|
browser: [],
|
|
@@ -740,6 +766,7 @@ var ReactServerPlasmicComponentLoader = class {
|
|
|
740
766
|
this.tracker = args.tracker;
|
|
741
767
|
this.onBundleMerged = args.onBundleMerged;
|
|
742
768
|
this.onBundleFetched = args.onBundleFetched;
|
|
769
|
+
this.registerModules(args.builtinModules);
|
|
743
770
|
}
|
|
744
771
|
maybeGetCompMetas(...specs) {
|
|
745
772
|
const found = /* @__PURE__ */ new Set();
|
|
@@ -865,83 +892,7 @@ var ReactServerPlasmicComponentLoader = class {
|
|
|
865
892
|
bundleKey: null,
|
|
866
893
|
deferChunksByDefault: false
|
|
867
894
|
};
|
|
868
|
-
|
|
869
|
-
};
|
|
870
|
-
function parseFetchComponentDataArgs(...args) {
|
|
871
|
-
let specs;
|
|
872
|
-
let opts;
|
|
873
|
-
if (Array.isArray(args[0])) {
|
|
874
|
-
specs = args[0];
|
|
875
|
-
opts = args[1];
|
|
876
|
-
} else {
|
|
877
|
-
specs = args;
|
|
878
|
-
opts = void 0;
|
|
879
|
-
}
|
|
880
|
-
return { specs, opts };
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// src/loader.ts
|
|
884
|
-
var SUBSTITUTED_COMPONENTS = {};
|
|
885
|
-
var REGISTERED_CODE_COMPONENT_HELPERS = {};
|
|
886
|
-
var SUBSTITUTED_GLOBAL_VARIANT_HOOKS = {};
|
|
887
|
-
var REGISTERED_CUSTOM_FUNCTIONS = {};
|
|
888
|
-
function customFunctionImportAlias(meta) {
|
|
889
|
-
const customFunctionPrefix = `__fn_`;
|
|
890
|
-
return meta.namespace ? `${customFunctionPrefix}${meta.namespace}__${meta.name}` : `${customFunctionPrefix}${meta.name}`;
|
|
891
|
-
}
|
|
892
|
-
var InternalPlasmicComponentLoader = class {
|
|
893
|
-
constructor(opts) {
|
|
894
|
-
this.opts = opts;
|
|
895
|
-
this.registry = new import_loader_core2.Registry();
|
|
896
|
-
this.subs = [];
|
|
897
|
-
this.roots = [];
|
|
898
|
-
this.globalVariants = [];
|
|
899
|
-
this.tracker = new import_loader_core2.PlasmicTracker({
|
|
900
|
-
projectIds: opts.projects.map((p) => p.id),
|
|
901
|
-
platform: opts.platform,
|
|
902
|
-
preview: opts.preview,
|
|
903
|
-
nativeFetch: opts.nativeFetch
|
|
904
|
-
});
|
|
905
|
-
this.reactServerLoader = new ReactServerPlasmicComponentLoader({
|
|
906
|
-
opts,
|
|
907
|
-
fetcher: new import_loader_core2.PlasmicModulesFetcher(opts),
|
|
908
|
-
tracker: this.tracker,
|
|
909
|
-
onBundleMerged: () => {
|
|
910
|
-
this.refreshRegistry();
|
|
911
|
-
},
|
|
912
|
-
onBundleFetched: () => {
|
|
913
|
-
this.roots.forEach((watcher) => {
|
|
914
|
-
var _a;
|
|
915
|
-
return (_a = watcher.onDataFetched) == null ? void 0 : _a.call(watcher);
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
});
|
|
919
|
-
this.registerModules({
|
|
920
|
-
react: import_react.default,
|
|
921
|
-
"react-dom": import_react_dom.default,
|
|
922
|
-
"react/jsx-runtime": jsxRuntime,
|
|
923
|
-
"react/jsx-dev-runtime": jsxDevRuntime,
|
|
924
|
-
// Also inject @plasmicapp/query and @plasmicapp/host to use the
|
|
925
|
-
// same contexts here and in loader-downloaded code.
|
|
926
|
-
"@plasmicapp/query": PlasmicQuery,
|
|
927
|
-
"@plasmicapp/data-sources-context": PlasmicDataSourcesContext,
|
|
928
|
-
"@plasmicapp/host": PlasmicHost,
|
|
929
|
-
"@plasmicapp/loader-runtime-registry": {
|
|
930
|
-
components: SUBSTITUTED_COMPONENTS,
|
|
931
|
-
globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
|
|
932
|
-
codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS,
|
|
933
|
-
functions: REGISTERED_CUSTOM_FUNCTIONS
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
getBundle() {
|
|
938
|
-
return this.reactServerLoader.getBundle();
|
|
939
|
-
}
|
|
940
|
-
setGlobalVariants(globalVariants) {
|
|
941
|
-
this.globalVariants = globalVariants;
|
|
942
|
-
}
|
|
943
|
-
getGlobalVariants() {
|
|
944
|
-
return this.globalVariants;
|
|
895
|
+
this.registry.clear();
|
|
945
896
|
}
|
|
946
897
|
registerModules(modules) {
|
|
947
898
|
if (Object.keys(modules).some(
|
|
@@ -962,112 +913,56 @@ var InternalPlasmicComponentLoader = class {
|
|
|
962
913
|
this.internalSubstituteComponent(component, name, void 0);
|
|
963
914
|
}
|
|
964
915
|
internalSubstituteComponent(component, name, codeComponentHelpers) {
|
|
965
|
-
if (!this.
|
|
916
|
+
if (!this.isRegistryEmpty()) {
|
|
966
917
|
console.warn(
|
|
967
918
|
"Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over."
|
|
968
919
|
);
|
|
969
|
-
this.
|
|
920
|
+
this.clearRegistry();
|
|
970
921
|
}
|
|
971
922
|
this.subs.push({ lookup: name, component, codeComponentHelpers });
|
|
972
923
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
);
|
|
985
|
-
const helpers = { states: stateHelpers };
|
|
986
|
-
this.internalSubstituteComponent(
|
|
987
|
-
component,
|
|
988
|
-
{ name: meta.name, isCode: true },
|
|
989
|
-
Object.keys(stateHelpers).length > 0 ? helpers : void 0
|
|
990
|
-
);
|
|
991
|
-
(0, import_host2.registerComponent)(component, __spreadValues(__spreadProps(__spreadValues({}, meta), {
|
|
992
|
-
// Import path is not used as we will use component substitution
|
|
993
|
-
importPath: (_b = meta.importPath) != null ? _b : ""
|
|
994
|
-
}), Object.keys(stateHelpers).length > 0 ? {
|
|
995
|
-
componentHelpers: {
|
|
996
|
-
helpers,
|
|
997
|
-
importPath: "",
|
|
998
|
-
importName: ""
|
|
999
|
-
}
|
|
1000
|
-
} : {}));
|
|
924
|
+
refreshRegistry() {
|
|
925
|
+
for (const sub of this.subs) {
|
|
926
|
+
const metas = getCompMetas(this.getBundle().components, sub.lookup);
|
|
927
|
+
metas.forEach((meta) => {
|
|
928
|
+
SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
|
|
929
|
+
if (sub.codeComponentHelpers) {
|
|
930
|
+
REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
this.registry.updateModules(this.getBundle());
|
|
1001
935
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
(0, import_host2.registerFunction)(fn, __spreadProps(__spreadValues({}, meta), {
|
|
1005
|
-
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
1006
|
-
}));
|
|
1007
|
-
REGISTERED_CUSTOM_FUNCTIONS[customFunctionImportAlias(meta)] = fn;
|
|
936
|
+
isRegistryEmpty() {
|
|
937
|
+
return this.registry.isEmpty();
|
|
1008
938
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
this.substituteComponent(context, { name: meta.name, isCode: true });
|
|
1012
|
-
(0, import_host2.registerGlobalContext)(context, __spreadProps(__spreadValues({}, meta), {
|
|
1013
|
-
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
1014
|
-
}));
|
|
939
|
+
clearRegistry() {
|
|
940
|
+
this.registry.clear();
|
|
1015
941
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
942
|
+
setGlobalVariants(globalVariants) {
|
|
943
|
+
this.globalVariants = globalVariants;
|
|
1018
944
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
945
|
+
getGlobalVariants() {
|
|
946
|
+
return this.globalVariants;
|
|
1021
947
|
}
|
|
1022
948
|
registerPrefetchedBundle(bundle) {
|
|
1023
949
|
if (!isBrowser) {
|
|
1024
950
|
const cachedBundle = (0, import_loader_fetcher.internal_getCachedBundleInNodeServer)(this.opts);
|
|
1025
951
|
if (cachedBundle) {
|
|
1026
|
-
this.
|
|
952
|
+
this.mergeBundle(cachedBundle);
|
|
1027
953
|
}
|
|
1028
954
|
}
|
|
1029
|
-
this.
|
|
1030
|
-
}
|
|
1031
|
-
subscribePlasmicRoot(watcher) {
|
|
1032
|
-
this.roots.push(watcher);
|
|
1033
|
-
}
|
|
1034
|
-
unsubscribePlasmicRoot(watcher) {
|
|
1035
|
-
const index = this.roots.indexOf(watcher);
|
|
1036
|
-
if (index >= 0) {
|
|
1037
|
-
this.roots.splice(index, 1);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
clearCache() {
|
|
1041
|
-
this.reactServerLoader.clearCache();
|
|
1042
|
-
this.registry.clear();
|
|
955
|
+
this.mergeBundle(bundle);
|
|
1043
956
|
}
|
|
1044
957
|
getLookup() {
|
|
1045
958
|
return new ComponentLookup(this.getBundle(), this.registry);
|
|
1046
959
|
}
|
|
1047
|
-
maybeFetchComponentData(...args) {
|
|
1048
|
-
return this.reactServerLoader.maybeFetchComponentData(...args);
|
|
1049
|
-
}
|
|
1050
|
-
fetchComponentData(...args) {
|
|
1051
|
-
return this.reactServerLoader.fetchComponentData(...args);
|
|
1052
|
-
}
|
|
1053
|
-
fetchPages(opts) {
|
|
1054
|
-
return this.reactServerLoader.fetchPages(opts);
|
|
1055
|
-
}
|
|
1056
|
-
fetchComponents() {
|
|
1057
|
-
return this.reactServerLoader.fetchComponents();
|
|
1058
|
-
}
|
|
1059
|
-
getActiveSplits() {
|
|
1060
|
-
return this.reactServerLoader.getActiveSplits();
|
|
1061
|
-
}
|
|
1062
|
-
getChunksUrl(bundle, modules) {
|
|
1063
|
-
return this.reactServerLoader.getChunksUrl(bundle, modules);
|
|
1064
|
-
}
|
|
1065
960
|
trackConversion(value = 0) {
|
|
1066
961
|
this.tracker.trackConversion(value);
|
|
1067
962
|
}
|
|
1068
963
|
getActiveVariation(opts) {
|
|
1069
964
|
return __async(this, null, function* () {
|
|
1070
|
-
yield this.
|
|
965
|
+
yield this.fetchComponents();
|
|
1071
966
|
return (0, import_loader_splits.getActiveVariation)(__spreadProps(__spreadValues({}, opts), {
|
|
1072
967
|
splits: this.getBundle().activeSplits
|
|
1073
968
|
}));
|
|
@@ -1090,23 +985,6 @@ var InternalPlasmicComponentLoader = class {
|
|
|
1090
985
|
trackRender(opts) {
|
|
1091
986
|
this.tracker.trackRender(opts);
|
|
1092
987
|
}
|
|
1093
|
-
refreshRegistry() {
|
|
1094
|
-
for (const sub of this.subs) {
|
|
1095
|
-
const metas = getCompMetas(this.getBundle().components, sub.lookup);
|
|
1096
|
-
metas.forEach((meta) => {
|
|
1097
|
-
SUBSTITUTED_COMPONENTS[meta.id] = sub.component;
|
|
1098
|
-
if (sub.codeComponentHelpers) {
|
|
1099
|
-
REGISTERED_CODE_COMPONENT_HELPERS[meta.id] = sub.codeComponentHelpers;
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
for (const globalGroup of this.getBundle().globalGroups) {
|
|
1104
|
-
if (globalGroup.type !== "global-screen") {
|
|
1105
|
-
SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = createUseGlobalVariant(globalGroup.name, globalGroup.projectId);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
this.registry.updateModules(this.getBundle());
|
|
1109
|
-
}
|
|
1110
988
|
};
|
|
1111
989
|
var PlasmicComponentLoader = class {
|
|
1112
990
|
constructor(internal) {
|
|
@@ -1226,9 +1104,118 @@ var PlasmicComponentLoader = class {
|
|
|
1226
1104
|
}
|
|
1227
1105
|
};
|
|
1228
1106
|
|
|
1107
|
+
// src/loader-client.ts
|
|
1108
|
+
var InternalPlasmicComponentLoader = class extends BaseInternalPlasmicComponentLoader {
|
|
1109
|
+
constructor(opts) {
|
|
1110
|
+
const tracker = new import_loader_core3.PlasmicTracker({
|
|
1111
|
+
projectIds: opts.projects.map((p) => p.id),
|
|
1112
|
+
platform: opts.platform,
|
|
1113
|
+
preview: opts.preview,
|
|
1114
|
+
nativeFetch: opts.nativeFetch
|
|
1115
|
+
});
|
|
1116
|
+
super({
|
|
1117
|
+
opts,
|
|
1118
|
+
tracker,
|
|
1119
|
+
fetcher: new import_loader_core3.PlasmicModulesFetcher(opts),
|
|
1120
|
+
onBundleMerged: () => {
|
|
1121
|
+
this.refreshRegistry();
|
|
1122
|
+
},
|
|
1123
|
+
onBundleFetched: () => {
|
|
1124
|
+
this.roots.forEach((watcher) => {
|
|
1125
|
+
var _a;
|
|
1126
|
+
return (_a = watcher.onDataFetched) == null ? void 0 : _a.call(watcher);
|
|
1127
|
+
});
|
|
1128
|
+
},
|
|
1129
|
+
builtinModules: {
|
|
1130
|
+
react: import_react.default,
|
|
1131
|
+
"react-dom": import_react_dom.default,
|
|
1132
|
+
"react/jsx-runtime": jsxRuntime,
|
|
1133
|
+
"react/jsx-dev-runtime": jsxDevRuntime,
|
|
1134
|
+
// Also inject @plasmicapp/query and @plasmicapp/host to use the
|
|
1135
|
+
// same contexts here and in loader-downloaded code.
|
|
1136
|
+
"@plasmicapp/query": PlasmicQuery,
|
|
1137
|
+
"@plasmicapp/data-sources-context": PlasmicDataSourcesContext,
|
|
1138
|
+
"@plasmicapp/host": PlasmicHost,
|
|
1139
|
+
"@plasmicapp/loader-runtime-registry": {
|
|
1140
|
+
components: SUBSTITUTED_COMPONENTS,
|
|
1141
|
+
globalVariantHooks: SUBSTITUTED_GLOBAL_VARIANT_HOOKS,
|
|
1142
|
+
codeComponentHelpers: REGISTERED_CODE_COMPONENT_HELPERS,
|
|
1143
|
+
functions: REGISTERED_CUSTOM_FUNCTIONS
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
this.roots = [];
|
|
1148
|
+
}
|
|
1149
|
+
registerComponent(component, meta) {
|
|
1150
|
+
var _a, _b;
|
|
1151
|
+
const stateHelpers = Object.fromEntries(
|
|
1152
|
+
Object.entries((_a = meta.states) != null ? _a : {}).filter(
|
|
1153
|
+
([_, stateSpec]) => Object.keys(stateSpec).some((key) => import_host2.stateHelpersKeys.includes(key))
|
|
1154
|
+
).map(([stateName, stateSpec]) => [
|
|
1155
|
+
stateName,
|
|
1156
|
+
Object.fromEntries(
|
|
1157
|
+
import_host2.stateHelpersKeys.filter((key) => key in stateSpec).map((key) => [key, stateSpec[key]])
|
|
1158
|
+
)
|
|
1159
|
+
])
|
|
1160
|
+
);
|
|
1161
|
+
const helpers = { states: stateHelpers };
|
|
1162
|
+
this.internalSubstituteComponent(
|
|
1163
|
+
component,
|
|
1164
|
+
{ name: meta.name, isCode: true },
|
|
1165
|
+
Object.keys(stateHelpers).length > 0 ? helpers : void 0
|
|
1166
|
+
);
|
|
1167
|
+
(0, import_host2.registerComponent)(component, __spreadValues(__spreadProps(__spreadValues({}, meta), {
|
|
1168
|
+
// Import path is not used as we will use component substitution
|
|
1169
|
+
importPath: (_b = meta.importPath) != null ? _b : ""
|
|
1170
|
+
}), Object.keys(stateHelpers).length > 0 ? {
|
|
1171
|
+
componentHelpers: {
|
|
1172
|
+
helpers,
|
|
1173
|
+
importPath: "",
|
|
1174
|
+
importName: ""
|
|
1175
|
+
}
|
|
1176
|
+
} : {}));
|
|
1177
|
+
}
|
|
1178
|
+
registerFunction(fn, meta) {
|
|
1179
|
+
var _a;
|
|
1180
|
+
(0, import_host2.registerFunction)(fn, __spreadProps(__spreadValues({}, meta), {
|
|
1181
|
+
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
1182
|
+
}));
|
|
1183
|
+
REGISTERED_CUSTOM_FUNCTIONS[customFunctionImportAlias(meta)] = fn;
|
|
1184
|
+
}
|
|
1185
|
+
registerGlobalContext(context, meta) {
|
|
1186
|
+
var _a;
|
|
1187
|
+
this.substituteComponent(context, { name: meta.name, isCode: true });
|
|
1188
|
+
(0, import_host2.registerGlobalContext)(context, __spreadProps(__spreadValues({}, meta), {
|
|
1189
|
+
importPath: (_a = meta.importPath) != null ? _a : ""
|
|
1190
|
+
}));
|
|
1191
|
+
}
|
|
1192
|
+
registerTrait(trait, meta) {
|
|
1193
|
+
(0, import_host2.registerTrait)(trait, meta);
|
|
1194
|
+
}
|
|
1195
|
+
registerToken(token) {
|
|
1196
|
+
(0, import_host2.registerToken)(token);
|
|
1197
|
+
}
|
|
1198
|
+
subscribePlasmicRoot(watcher) {
|
|
1199
|
+
this.roots.push(watcher);
|
|
1200
|
+
}
|
|
1201
|
+
unsubscribePlasmicRoot(watcher) {
|
|
1202
|
+
const index = this.roots.indexOf(watcher);
|
|
1203
|
+
if (index >= 0) {
|
|
1204
|
+
this.roots.splice(index, 1);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
refreshRegistry() {
|
|
1208
|
+
for (const globalGroup of this.getBundle().globalGroups) {
|
|
1209
|
+
if (globalGroup.type !== "global-screen") {
|
|
1210
|
+
SUBSTITUTED_GLOBAL_VARIANT_HOOKS[globalGroup.id] = createUseGlobalVariant(globalGroup.name, globalGroup.projectId);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
super.refreshRegistry();
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1229
1217
|
// src/index.ts
|
|
1230
1218
|
var import_host3 = require("@plasmicapp/host");
|
|
1231
|
-
var import_prepass2 = require("@plasmicapp/prepass");
|
|
1232
1219
|
var import_query2 = require("@plasmicapp/query");
|
|
1233
1220
|
|
|
1234
1221
|
// src/PlasmicComponent.tsx
|
|
@@ -1316,7 +1303,7 @@ function PlasmicComponent(props) {
|
|
|
1316
1303
|
if (!Component) {
|
|
1317
1304
|
return null;
|
|
1318
1305
|
}
|
|
1319
|
-
let
|
|
1306
|
+
let elt = /* @__PURE__ */ React5.createElement(Component, __spreadValues({}, componentProps));
|
|
1320
1307
|
if (isRootLoader) {
|
|
1321
1308
|
const lookup = loader.getLookup();
|
|
1322
1309
|
const ReactWebRootProvider = lookup.getRootProvider();
|
|
@@ -1324,7 +1311,7 @@ function PlasmicComponent(props) {
|
|
|
1324
1311
|
name: component,
|
|
1325
1312
|
projectId
|
|
1326
1313
|
});
|
|
1327
|
-
|
|
1314
|
+
elt = /* @__PURE__ */ React5.createElement(
|
|
1328
1315
|
ReactWebRootProvider,
|
|
1329
1316
|
__spreadProps(__spreadValues({}, rest), {
|
|
1330
1317
|
userAuthToken,
|
|
@@ -1341,11 +1328,11 @@ function PlasmicComponent(props) {
|
|
|
1341
1328
|
cond: !!GlobalContextsProvider,
|
|
1342
1329
|
wrapper: (children) => /* @__PURE__ */ React5.createElement(GlobalContextsProvider, __spreadValues({}, globalContextsProps), children)
|
|
1343
1330
|
},
|
|
1344
|
-
/* @__PURE__ */ React5.createElement(PlasmicComponentContext.Provider, { value: true },
|
|
1331
|
+
/* @__PURE__ */ React5.createElement(PlasmicComponentContext.Provider, { value: true }, elt)
|
|
1345
1332
|
)
|
|
1346
1333
|
);
|
|
1347
1334
|
}
|
|
1348
|
-
return
|
|
1335
|
+
return elt;
|
|
1349
1336
|
}, [
|
|
1350
1337
|
Component,
|
|
1351
1338
|
componentProps,
|
|
@@ -1362,11 +1349,20 @@ function PlasmicComponent(props) {
|
|
|
1362
1349
|
return element;
|
|
1363
1350
|
}
|
|
1364
1351
|
|
|
1352
|
+
// src/prepass-client.ts
|
|
1353
|
+
var import_prepass = require("@plasmicapp/prepass");
|
|
1354
|
+
function extractPlasmicQueryData(element) {
|
|
1355
|
+
return (0, import_prepass.extractPlasmicQueryData)(element);
|
|
1356
|
+
}
|
|
1357
|
+
function plasmicPrepass(element) {
|
|
1358
|
+
return (0, import_prepass.plasmicPrepass)(element);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1365
1361
|
// src/render.tsx
|
|
1362
|
+
var import_prepass2 = require("@plasmicapp/prepass");
|
|
1366
1363
|
var import_react2 = __toESM(require("react"));
|
|
1367
1364
|
var import_react_dom2 = __toESM(require("react-dom"));
|
|
1368
1365
|
var import_server = require("react-dom/server");
|
|
1369
|
-
var import_prepass = require("@plasmicapp/prepass");
|
|
1370
1366
|
function renderToElement(_0, _1, _2) {
|
|
1371
1367
|
return __async(this, arguments, function* (loader, target, lookup, opts = {}) {
|
|
1372
1368
|
return new Promise((resolve) => {
|
|
@@ -1382,7 +1378,7 @@ function renderToString(loader, lookup, opts = {}) {
|
|
|
1382
1378
|
function extractPlasmicQueryDataFromElement(_0, _1) {
|
|
1383
1379
|
return __async(this, arguments, function* (loader, lookup, opts = {}) {
|
|
1384
1380
|
const element = makeElement(loader, lookup, opts);
|
|
1385
|
-
return (0,
|
|
1381
|
+
return (0, import_prepass2.extractPlasmicQueryData)(element);
|
|
1386
1382
|
});
|
|
1387
1383
|
}
|
|
1388
1384
|
function hydrateFromElement(_0, _1, _2) {
|