@plasmicapp/loader-react 1.0.205 → 1.0.207

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.
Files changed (38) hide show
  1. package/dist/index-react-server.d.ts +5 -0
  2. package/dist/index-shared.d.ts +6 -0
  3. package/dist/index.d.ts +5 -4
  4. package/dist/loader-react-server.d.ts +72 -0
  5. package/dist/loader-react.cjs.development.js +484 -426
  6. package/dist/loader-react.cjs.development.js.map +1 -1
  7. package/dist/loader-react.cjs.production.min.js +1 -1
  8. package/dist/loader-react.cjs.production.min.js.map +1 -1
  9. package/dist/loader-react.esm.js +484 -426
  10. package/dist/loader-react.esm.js.map +1 -1
  11. package/dist/loader.d.ts +9 -52
  12. package/dist/utils.d.ts +1 -0
  13. package/dist-react-server/PlasmicComponent.d.ts +19 -0
  14. package/dist-react-server/PlasmicRootProvider.d.ts +92 -0
  15. package/dist-react-server/bundles.d.ts +7 -0
  16. package/dist-react-server/component-lookup.d.ts +21 -0
  17. package/dist-react-server/global-variants.d.ts +13 -0
  18. package/dist-react-server/index-react-server.d.ts +5 -0
  19. package/dist-react-server/index-shared.d.ts +6 -0
  20. package/dist-react-server/index.d.ts +12 -0
  21. package/dist-react-server/index.js +8 -0
  22. package/dist-react-server/loader-react-server.d.ts +72 -0
  23. package/dist-react-server/loader-react.cjs.development.js +1315 -0
  24. package/dist-react-server/loader-react.cjs.development.js.map +1 -0
  25. package/dist-react-server/loader-react.cjs.production.min.js +2 -0
  26. package/dist-react-server/loader-react.cjs.production.min.js.map +1 -0
  27. package/dist-react-server/loader-react.esm.js +1306 -0
  28. package/dist-react-server/loader-react.esm.js.map +1 -0
  29. package/dist-react-server/loader.d.ts +168 -0
  30. package/dist-react-server/prepass.d.ts +43 -0
  31. package/dist-react-server/render.d.ts +27 -0
  32. package/dist-react-server/usePlasmicComponent.d.ts +15 -0
  33. package/dist-react-server/utils.d.ts +30 -0
  34. package/dist-react-server/variation.d.ts +9 -0
  35. package/index.d.ts +1 -0
  36. package/package.json +46 -9
  37. package/react-server-conditional.d.ts +4 -0
  38. package/react-server.d.ts +1 -0
@@ -1,12 +1,12 @@
1
+ 'use client';import * as PlasmicDataSourcesContext from '@plasmicapp/data-sources-context';
1
2
  import * as PlasmicHost from '@plasmicapp/host';
2
3
  import { PageParamsProvider, registerComponent, registerGlobalContext, registerTrait } from '@plasmicapp/host';
3
4
  export { DataCtxReader, DataProvider, PageParamsProvider, PlasmicCanvasContext, PlasmicCanvasHost, repeatedElement, useDataEnv, usePlasmicCanvasContext, useSelector, useSelectors } from '@plasmicapp/host';
5
+ import { getBundleSubset, Registry, PlasmicTracker, PlasmicModulesFetcher } from '@plasmicapp/loader-core';
6
+ import { getExternalIds, getActiveVariation } from '@plasmicapp/loader-splits';
4
7
  import * as PlasmicQuery from '@plasmicapp/query';
5
8
  import { PlasmicQueryDataProvider, PlasmicPrepassContext } from '@plasmicapp/query';
6
9
  export { usePlasmicQueryData } from '@plasmicapp/query';
7
- import { getBundleSubset, Registry, PlasmicModulesFetcher, PlasmicTracker } from '@plasmicapp/loader-core';
8
- import * as PlasmicDataSourcesContext from '@plasmicapp/data-sources-context';
9
- import { getExternalIds, getActiveVariation } from '@plasmicapp/loader-splits';
10
10
  import React__default, { useState, useCallback, useEffect, useRef, useMemo, createElement, memo, useContext, createContext } from 'react';
11
11
  import ReactDOM from 'react-dom';
12
12
  import * as jsxDevRuntime from 'react/jsx-dev-runtime';
@@ -116,158 +116,6 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
116
116
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
117
117
  }
118
118
 
119
- function getUsedComps(allComponents, entryCompIds) {
120
- var q = [].concat(entryCompIds);
121
- var seenIds = new Set(entryCompIds);
122
- var componentMetaById = new Map(allComponents.map(function (meta) {
123
- return [meta.id, meta];
124
- }));
125
- var usedComps = [];
126
- while (q.length > 0) {
127
- var _q$splice = q.splice(0, 1),
128
- id = _q$splice[0];
129
- var meta = componentMetaById.get(id);
130
- if (!meta) {
131
- continue;
132
- }
133
- usedComps.push(meta);
134
- meta.usedComponents.forEach(function (usedCompId) {
135
- if (!seenIds.has(usedCompId)) {
136
- seenIds.add(usedCompId);
137
- q.push(usedCompId);
138
- }
139
- });
140
- }
141
- return usedComps;
142
- }
143
- function prepComponentData(bundle, compMetas, opts) {
144
- if (compMetas.length === 0) {
145
- return {
146
- entryCompMetas: bundle.components,
147
- bundle: bundle,
148
- remoteFontUrls: []
149
- };
150
- }
151
- var usedComps = getUsedComps(bundle.components, compMetas.map(function (compMeta) {
152
- return compMeta.id;
153
- }));
154
- var compPaths = usedComps.map(function (compMeta) {
155
- return compMeta.entry;
156
- });
157
- var subBundle = getBundleSubset(bundle, ['entrypoint.css'].concat(compPaths, ['root-provider.js'], bundle.projects.map(function (x) {
158
- return x.globalContextsProviderFileName;
159
- }).filter(function (x) {
160
- return !!x;
161
- }), bundle.components.filter(function (c) {
162
- return c.isGlobalContextProvider;
163
- }).map(function (c) {
164
- return c.entry;
165
- }), bundle.globalGroups.map(function (g) {
166
- return g.contextFile;
167
- })), opts);
168
- var remoteFontUrls = [];
169
- subBundle.projects.forEach(function (p) {
170
- return remoteFontUrls.push.apply(remoteFontUrls, p.remoteFonts.map(function (f) {
171
- return f.url;
172
- }));
173
- });
174
- return {
175
- entryCompMetas: compMetas,
176
- bundle: subBundle,
177
- remoteFontUrls: remoteFontUrls
178
- };
179
- }
180
- function mergeBundles(target, from) {
181
- var _from$activeSplits$fi;
182
- var existingCompIds = new Set(target.components.map(function (c) {
183
- return c.id;
184
- }));
185
- var newCompMetas = from.components.filter(function (m) {
186
- return !existingCompIds.has(m.id);
187
- });
188
- if (newCompMetas.length > 0) {
189
- target = _extends({}, target, {
190
- components: [].concat(target.components, newCompMetas)
191
- });
192
- }
193
- var existingProjects = new Set(target.projects.map(function (p) {
194
- return p.id;
195
- }));
196
- var newProjects = from.projects.filter(function (p) {
197
- return !existingProjects.has(p.id);
198
- });
199
- if (newProjects.length > 0) {
200
- target = _extends({}, target, {
201
- projects: [].concat(target.projects, newProjects)
202
- });
203
- }
204
- var existingModules = {
205
- browser: new Set(target.modules.browser.map(function (m) {
206
- return m.fileName;
207
- })),
208
- server: new Set(target.modules.server.map(function (m) {
209
- return m.fileName;
210
- }))
211
- };
212
- var newModules = {
213
- browser: from.modules.browser.filter(function (m) {
214
- return !existingModules.browser.has(m.fileName);
215
- }),
216
- server: from.modules.server.filter(function (m) {
217
- return !existingModules.server.has(m.fileName);
218
- })
219
- };
220
- if (newModules.browser.length > 0 || newModules.server.length > 0) {
221
- target = _extends({}, target, {
222
- modules: {
223
- browser: [].concat(target.modules.browser, newModules.browser),
224
- server: [].concat(target.modules.server, newModules.server)
225
- }
226
- });
227
- }
228
- var existingGlobalIds = new Set(target.globalGroups.map(function (g) {
229
- return g.id;
230
- }));
231
- var newGlobals = from.globalGroups.filter(function (g) {
232
- return !existingGlobalIds.has(g.id);
233
- });
234
- if (newGlobals.length > 0) {
235
- target = _extends({}, target, {
236
- globalGroups: [].concat(target.globalGroups, newGlobals)
237
- });
238
- }
239
- var existingExternals = new Set(target.external);
240
- var newExternals = target.external.filter(function (x) {
241
- return !existingExternals.has(x);
242
- });
243
- if (newExternals.length > 0) {
244
- target = _extends({}, target, {
245
- external: [].concat(target.external, newExternals)
246
- });
247
- }
248
- var existingSplitIds = new Set(target.activeSplits.map(function (s) {
249
- return s.id;
250
- }));
251
- var newSplits = (_from$activeSplits$fi = from.activeSplits.filter(function (s) {
252
- return !existingSplitIds.has(s.id);
253
- })) != null ? _from$activeSplits$fi : [];
254
- if (newSplits.length > 0) {
255
- target = _extends({}, target, {
256
- activeSplits: [].concat(target.activeSplits, newSplits)
257
- });
258
- }
259
- return target;
260
- }
261
- var convertBundlesToComponentRenderData = function convertBundlesToComponentRenderData(bundles, compMetas) {
262
- if (bundles.length === 0) {
263
- return null;
264
- }
265
- var mergedBundles = bundles.reduce(function (prev, cur) {
266
- return mergeBundles(prev, cur);
267
- });
268
- return prepComponentData(mergedBundles, compMetas);
269
- };
270
-
271
119
  function createCommonjsModule(fn, module) {
272
120
  return module = { exports: {} }, fn(module, module.exports), module.exports;
273
121
  }
@@ -926,6 +774,7 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
926
774
  }
927
775
  });
928
776
 
777
+ var isBrowser = typeof window !== 'undefined';
929
778
  function useForceUpdate() {
930
779
  var _React$useState = useState(0),
931
780
  setTick = _React$useState[1];
@@ -1409,125 +1258,161 @@ function createUseGlobalVariant(name, projectId) {
1409
1258
  };
1410
1259
  }
1411
1260
 
1412
- var isBrowser = typeof window !== 'undefined';
1413
- function initPlasmicLoader(opts) {
1414
- var internal = new InternalPlasmicComponentLoader(opts);
1415
- return new PlasmicComponentLoader(internal);
1416
- }
1417
- var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1418
- function InternalPlasmicComponentLoader(opts) {
1419
- this.opts = opts;
1420
- this.subs = [];
1421
- this.roots = [];
1422
- this.globalVariants = [];
1423
- this.bundle = {
1424
- modules: {
1425
- browser: [],
1426
- server: []
1427
- },
1428
- components: [],
1429
- globalGroups: [],
1430
- external: [],
1431
- projects: [],
1432
- activeSplits: []
1433
- };
1434
- this.substitutedComponents = {};
1435
- this.substitutedGlobalVariantHooks = {};
1436
- this.registry = Registry.getInstance();
1437
- this.fetcher = new PlasmicModulesFetcher(opts);
1438
- this.tracker = new PlasmicTracker({
1439
- projectIds: opts.projects.map(function (p) {
1440
- return p.id;
1441
- }),
1442
- platform: opts.platform,
1443
- preview: opts.preview
1444
- });
1445
- this.registerModules({
1446
- react: React__default,
1447
- 'react-dom': ReactDOM,
1448
- 'react/jsx-runtime': jsxRuntime,
1449
- 'react/jsx-dev-runtime': jsxDevRuntime,
1450
- // Also inject @plasmicapp/query and @plasmicapp/host to use the
1451
- // same contexts here and in loader-downloaded code.
1452
- '@plasmicapp/query': PlasmicQuery,
1453
- '@plasmicapp/data-sources-context': PlasmicDataSourcesContext,
1454
- '@plasmicapp/host': PlasmicHost,
1455
- '@plasmicapp/loader-runtime-registry': {
1456
- components: this.substitutedComponents,
1457
- globalVariantHooks: this.substitutedGlobalVariantHooks
1261
+ function getUsedComps(allComponents, entryCompIds) {
1262
+ var q = [].concat(entryCompIds);
1263
+ var seenIds = new Set(entryCompIds);
1264
+ var componentMetaById = new Map(allComponents.map(function (meta) {
1265
+ return [meta.id, meta];
1266
+ }));
1267
+ var usedComps = [];
1268
+ while (q.length > 0) {
1269
+ var _q$splice = q.splice(0, 1),
1270
+ id = _q$splice[0];
1271
+ var meta = componentMetaById.get(id);
1272
+ if (!meta) {
1273
+ continue;
1274
+ }
1275
+ usedComps.push(meta);
1276
+ meta.usedComponents.forEach(function (usedCompId) {
1277
+ if (!seenIds.has(usedCompId)) {
1278
+ seenIds.add(usedCompId);
1279
+ q.push(usedCompId);
1458
1280
  }
1459
1281
  });
1460
1282
  }
1461
- var _proto = InternalPlasmicComponentLoader.prototype;
1462
- _proto.setGlobalVariants = function setGlobalVariants(globalVariants) {
1463
- this.globalVariants = globalVariants;
1464
- };
1465
- _proto.getGlobalVariants = function getGlobalVariants() {
1466
- return this.globalVariants;
1467
- };
1468
- _proto.registerModules = function registerModules(modules) {
1469
- var _this = this;
1470
- if (Object.keys(modules).some(function (name) {
1471
- return _this.registry.getRegisteredModule(name) !== modules[name];
1472
- })) {
1473
- if (!this.registry.isEmpty()) {
1474
- console.warn('Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over.');
1475
- this.registry.clear();
1476
- }
1477
- for (var _i = 0, _Object$keys = Object.keys(modules); _i < _Object$keys.length; _i++) {
1478
- var key = _Object$keys[_i];
1479
- this.registry.register(key, modules[key]);
1480
- }
1481
- }
1482
- };
1483
- _proto.substituteComponent = function substituteComponent(component, name) {
1484
- if (!this.registry.isEmpty()) {
1485
- console.warn('Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over.');
1486
- this.registry.clear();
1487
- }
1488
- this.subs.push({
1489
- lookup: name,
1490
- component: component
1491
- });
1492
- };
1493
- _proto.registerComponent = function registerComponent$1(component, meta) {
1494
- var _meta$importPath;
1495
- this.substituteComponent(component, {
1496
- name: meta.name,
1497
- isCode: true
1498
- });
1499
- // Import path is not used as we will use component substitution
1500
- registerComponent(component, _extends({}, meta, {
1501
- importPath: (_meta$importPath = meta.importPath) != null ? _meta$importPath : ''
1283
+ return usedComps;
1284
+ }
1285
+ function prepComponentData(bundle, compMetas, opts) {
1286
+ if (compMetas.length === 0) {
1287
+ return {
1288
+ entryCompMetas: bundle.components,
1289
+ bundle: bundle,
1290
+ remoteFontUrls: []
1291
+ };
1292
+ }
1293
+ var usedComps = getUsedComps(bundle.components, compMetas.map(function (compMeta) {
1294
+ return compMeta.id;
1295
+ }));
1296
+ var compPaths = usedComps.map(function (compMeta) {
1297
+ return compMeta.entry;
1298
+ });
1299
+ var subBundle = getBundleSubset(bundle, ['entrypoint.css'].concat(compPaths, ['root-provider.js'], bundle.projects.map(function (x) {
1300
+ return x.globalContextsProviderFileName;
1301
+ }).filter(function (x) {
1302
+ return !!x;
1303
+ }), bundle.components.filter(function (c) {
1304
+ return c.isGlobalContextProvider;
1305
+ }).map(function (c) {
1306
+ return c.entry;
1307
+ }), bundle.globalGroups.map(function (g) {
1308
+ return g.contextFile;
1309
+ })), opts);
1310
+ var remoteFontUrls = [];
1311
+ subBundle.projects.forEach(function (p) {
1312
+ return remoteFontUrls.push.apply(remoteFontUrls, p.remoteFonts.map(function (f) {
1313
+ return f.url;
1502
1314
  }));
1315
+ });
1316
+ return {
1317
+ entryCompMetas: compMetas,
1318
+ bundle: subBundle,
1319
+ remoteFontUrls: remoteFontUrls
1503
1320
  };
1504
- _proto.registerGlobalContext = function registerGlobalContext$1(context, meta) {
1505
- var _meta$importPath2;
1506
- this.substituteComponent(context, {
1507
- name: meta.name,
1508
- isCode: true
1321
+ }
1322
+ function mergeBundles(target, from) {
1323
+ var _from$activeSplits$fi;
1324
+ var existingCompIds = new Set(target.components.map(function (c) {
1325
+ return c.id;
1326
+ }));
1327
+ var newCompMetas = from.components.filter(function (m) {
1328
+ return !existingCompIds.has(m.id);
1329
+ });
1330
+ if (newCompMetas.length > 0) {
1331
+ target = _extends({}, target, {
1332
+ components: [].concat(target.components, newCompMetas)
1509
1333
  });
1510
- // Import path is not used as we will use component substitution
1511
- registerGlobalContext(context, _extends({}, meta, {
1512
- importPath: (_meta$importPath2 = meta.importPath) != null ? _meta$importPath2 : ''
1513
- }));
1514
- };
1515
- _proto.registerTrait = function registerTrait$1(trait, meta) {
1516
- registerTrait(trait, meta);
1517
- };
1518
- _proto.registerPrefetchedBundle = function registerPrefetchedBundle(bundle) {
1519
- this.mergeBundle(bundle);
1520
- };
1521
- _proto.subscribePlasmicRoot = function subscribePlasmicRoot(watcher) {
1522
- this.roots.push(watcher);
1334
+ }
1335
+ var existingProjects = new Set(target.projects.map(function (p) {
1336
+ return p.id;
1337
+ }));
1338
+ var newProjects = from.projects.filter(function (p) {
1339
+ return !existingProjects.has(p.id);
1340
+ });
1341
+ if (newProjects.length > 0) {
1342
+ target = _extends({}, target, {
1343
+ projects: [].concat(target.projects, newProjects)
1344
+ });
1345
+ }
1346
+ var existingModules = {
1347
+ browser: new Set(target.modules.browser.map(function (m) {
1348
+ return m.fileName;
1349
+ })),
1350
+ server: new Set(target.modules.server.map(function (m) {
1351
+ return m.fileName;
1352
+ }))
1523
1353
  };
1524
- _proto.unsubscribePlasmicRoot = function unsubscribePlasmicRoot(watcher) {
1525
- var index = this.roots.indexOf(watcher);
1526
- if (index >= 0) {
1527
- this.roots.splice(index, 1);
1528
- }
1354
+ var newModules = {
1355
+ browser: from.modules.browser.filter(function (m) {
1356
+ return !existingModules.browser.has(m.fileName);
1357
+ }),
1358
+ server: from.modules.server.filter(function (m) {
1359
+ return !existingModules.server.has(m.fileName);
1360
+ })
1529
1361
  };
1530
- _proto.clearCache = function clearCache() {
1362
+ if (newModules.browser.length > 0 || newModules.server.length > 0) {
1363
+ target = _extends({}, target, {
1364
+ modules: {
1365
+ browser: [].concat(target.modules.browser, newModules.browser),
1366
+ server: [].concat(target.modules.server, newModules.server)
1367
+ }
1368
+ });
1369
+ }
1370
+ var existingGlobalIds = new Set(target.globalGroups.map(function (g) {
1371
+ return g.id;
1372
+ }));
1373
+ var newGlobals = from.globalGroups.filter(function (g) {
1374
+ return !existingGlobalIds.has(g.id);
1375
+ });
1376
+ if (newGlobals.length > 0) {
1377
+ target = _extends({}, target, {
1378
+ globalGroups: [].concat(target.globalGroups, newGlobals)
1379
+ });
1380
+ }
1381
+ var existingExternals = new Set(target.external);
1382
+ var newExternals = target.external.filter(function (x) {
1383
+ return !existingExternals.has(x);
1384
+ });
1385
+ if (newExternals.length > 0) {
1386
+ target = _extends({}, target, {
1387
+ external: [].concat(target.external, newExternals)
1388
+ });
1389
+ }
1390
+ var existingSplitIds = new Set(target.activeSplits.map(function (s) {
1391
+ return s.id;
1392
+ }));
1393
+ var newSplits = (_from$activeSplits$fi = from.activeSplits.filter(function (s) {
1394
+ return !existingSplitIds.has(s.id);
1395
+ })) != null ? _from$activeSplits$fi : [];
1396
+ if (newSplits.length > 0) {
1397
+ target = _extends({}, target, {
1398
+ activeSplits: [].concat(target.activeSplits, newSplits)
1399
+ });
1400
+ }
1401
+ return target;
1402
+ }
1403
+ var convertBundlesToComponentRenderData = function convertBundlesToComponentRenderData(bundles, compMetas) {
1404
+ if (bundles.length === 0) {
1405
+ return null;
1406
+ }
1407
+ var mergedBundles = bundles.reduce(function (prev, cur) {
1408
+ return mergeBundles(prev, cur);
1409
+ });
1410
+ return prepComponentData(mergedBundles, compMetas);
1411
+ };
1412
+
1413
+ /** Subset of loader functionality that works on React Server Components. */
1414
+ var ReactServerPlasmicComponentLoader = /*#__PURE__*/function () {
1415
+ function ReactServerPlasmicComponentLoader(args) {
1531
1416
  this.bundle = {
1532
1417
  modules: {
1533
1418
  browser: [],
@@ -1539,22 +1424,43 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1539
1424
  projects: [],
1540
1425
  activeSplits: []
1541
1426
  };
1542
- this.registry.clear();
1543
- };
1427
+ this.opts = args.opts;
1428
+ this.fetcher = args.fetcher;
1429
+ this.tracker = args.tracker;
1430
+ this.onBundleMerged = args.onBundleMerged;
1431
+ this.onBundleFetched = args.onBundleFetched;
1432
+ }
1433
+ var _proto = ReactServerPlasmicComponentLoader.prototype;
1544
1434
  _proto.maybeGetCompMetas = function maybeGetCompMetas() {
1435
+ var found = new Set();
1436
+ var missing = [];
1545
1437
  for (var _len = arguments.length, specs = new Array(_len), _key = 0; _key < _len; _key++) {
1546
1438
  specs[_key] = arguments[_key];
1547
1439
  }
1548
- return _maybeGetCompMetas(this.bundle.components, specs);
1440
+ for (var _i = 0, _specs = specs; _i < _specs.length; _i++) {
1441
+ var spec = _specs[_i];
1442
+ var filteredMetas = getCompMetas(this.bundle.components, spec);
1443
+ if (filteredMetas.length > 0) {
1444
+ filteredMetas.forEach(function (meta) {
1445
+ return found.add(meta);
1446
+ });
1447
+ } else {
1448
+ missing.push(spec);
1449
+ }
1450
+ }
1451
+ return {
1452
+ found: Array.from(found.keys()),
1453
+ missing: missing
1454
+ };
1549
1455
  };
1550
1456
  _proto.maybeFetchComponentData = /*#__PURE__*/function () {
1551
1457
  var _maybeFetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1552
- var _this2 = this;
1458
+ var _this = this;
1553
1459
  var _parseFetchComponentD,
1554
1460
  specs,
1555
1461
  opts,
1556
1462
  returnWithSpecsToFetch,
1557
- _this$maybeGetCompMet,
1463
+ _this$maybeGetCompMet2,
1558
1464
  existingMetas,
1559
1465
  missingSpecs,
1560
1466
  _args2 = arguments;
@@ -1565,24 +1471,24 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1565
1471
  _parseFetchComponentD = parseFetchComponentDataArgs.apply(void 0, _args2), specs = _parseFetchComponentD.specs, opts = _parseFetchComponentD.opts;
1566
1472
  returnWithSpecsToFetch = /*#__PURE__*/function () {
1567
1473
  var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(specsToFetch) {
1568
- var _this2$maybeGetCompMe, existingMetas2, missingSpecs2;
1474
+ var _this$maybeGetCompMet, existingMetas2, missingSpecs2;
1569
1475
  return runtime_1.wrap(function _callee$(_context) {
1570
1476
  while (1) {
1571
1477
  switch (_context.prev = _context.next) {
1572
1478
  case 0:
1573
1479
  _context.next = 2;
1574
- return _this2.fetchMissingData({
1480
+ return _this.fetchMissingData({
1575
1481
  missingSpecs: specsToFetch
1576
1482
  });
1577
1483
  case 2:
1578
- _this2$maybeGetCompMe = _this2.maybeGetCompMetas.apply(_this2, specs), existingMetas2 = _this2$maybeGetCompMe.found, missingSpecs2 = _this2$maybeGetCompMe.missing;
1484
+ _this$maybeGetCompMet = _this.maybeGetCompMetas.apply(_this, specs), existingMetas2 = _this$maybeGetCompMet.found, missingSpecs2 = _this$maybeGetCompMet.missing;
1579
1485
  if (!(missingSpecs2.length > 0)) {
1580
1486
  _context.next = 5;
1581
1487
  break;
1582
1488
  }
1583
1489
  return _context.abrupt("return", null);
1584
1490
  case 5:
1585
- return _context.abrupt("return", prepComponentData(_this2.bundle, existingMetas2, opts));
1491
+ return _context.abrupt("return", prepComponentData(_this.bundle, existingMetas2, opts));
1586
1492
  case 6:
1587
1493
  case "end":
1588
1494
  return _context.stop();
@@ -1604,7 +1510,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1604
1510
  return _context2.abrupt("return", _context2.sent);
1605
1511
  case 6:
1606
1512
  // Else we only fetch actually missing specs
1607
- _this$maybeGetCompMet = this.maybeGetCompMetas.apply(this, specs), existingMetas = _this$maybeGetCompMet.found, missingSpecs = _this$maybeGetCompMet.missing;
1513
+ _this$maybeGetCompMet2 = this.maybeGetCompMetas.apply(this, specs), existingMetas = _this$maybeGetCompMet2.found, missingSpecs = _this$maybeGetCompMet2.missing;
1608
1514
  if (!(missingSpecs.length === 0)) {
1609
1515
  _context2.next = 9;
1610
1516
  break;
@@ -1633,7 +1539,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1633
1539
  specs,
1634
1540
  opts,
1635
1541
  data,
1636
- _this$maybeGetCompMet2,
1542
+ _this$maybeGetCompMet3,
1637
1543
  missingSpecs,
1638
1544
  _args3 = arguments;
1639
1545
  return runtime_1.wrap(function _callee3$(_context3) {
@@ -1649,7 +1555,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1649
1555
  _context3.next = 7;
1650
1556
  break;
1651
1557
  }
1652
- _this$maybeGetCompMet2 = this.maybeGetCompMetas.apply(this, specs), missingSpecs = _this$maybeGetCompMet2.missing;
1558
+ _this$maybeGetCompMet3 = this.maybeGetCompMetas.apply(this, specs), missingSpecs = _this$maybeGetCompMet3.missing;
1653
1559
  throw new Error("Unable to find components " + missingSpecs.map(getLookupSpecName).join(', '));
1654
1560
  case 7:
1655
1561
  return _context3.abrupt("return", data);
@@ -1721,23 +1627,10 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1721
1627
  }
1722
1628
  return fetchComponents;
1723
1629
  }();
1724
- _proto.getLookup = function getLookup() {
1725
- return new ComponentLookup(this.bundle, this.registry);
1726
- };
1727
1630
  _proto.getActiveSplits = function getActiveSplits() {
1728
1631
  return this.bundle.activeSplits;
1729
1632
  };
1730
- _proto.trackConversion = function trackConversion(value) {
1731
- if (value === void 0) {
1732
- value = 0;
1733
- }
1734
- this.tracker.trackConversion(value);
1735
- }
1736
- // @ts-ignore
1737
- ;
1738
- _proto.fetchMissingData =
1739
- /*#__PURE__*/
1740
- function () {
1633
+ _proto.fetchMissingData = /*#__PURE__*/function () {
1741
1634
  var _fetchMissingData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
1742
1635
  return runtime_1.wrap(function _callee6$(_context6) {
1743
1636
  while (1) {
@@ -1772,83 +1665,285 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1772
1665
  }
1773
1666
  }
1774
1667
  };
1775
- _proto.getActiveVariation = /*#__PURE__*/function () {
1776
- var _getActiveVariation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(opts) {
1668
+ _proto.fetchAllData = /*#__PURE__*/function () {
1669
+ var _fetchAllData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
1670
+ var _this$onBundleFetched;
1671
+ var bundle;
1777
1672
  return runtime_1.wrap(function _callee7$(_context7) {
1778
1673
  while (1) {
1779
1674
  switch (_context7.prev = _context7.next) {
1780
1675
  case 0:
1781
1676
  _context7.next = 2;
1782
- return this.fetchAllData();
1677
+ return this.fetcher.fetchAllData();
1783
1678
  case 2:
1784
- return _context7.abrupt("return", getActiveVariation(_extends({}, opts, {
1785
- splits: this.bundle.activeSplits
1786
- })));
1787
- case 3:
1679
+ bundle = _context7.sent;
1680
+ this.tracker.trackFetch();
1681
+ this.mergeBundle(bundle);
1682
+ (_this$onBundleFetched = this.onBundleFetched) == null ? void 0 : _this$onBundleFetched.call(this);
1683
+ return _context7.abrupt("return", bundle);
1684
+ case 7:
1788
1685
  case "end":
1789
1686
  return _context7.stop();
1790
1687
  }
1791
1688
  }
1792
1689
  }, _callee7, this);
1793
1690
  }));
1794
- function getActiveVariation$1(_x4) {
1795
- return _getActiveVariation2.apply(this, arguments);
1691
+ function fetchAllData() {
1692
+ return _fetchAllData.apply(this, arguments);
1796
1693
  }
1797
- return getActiveVariation$1;
1694
+ return fetchAllData;
1798
1695
  }();
1799
- _proto.getTeamIds = function getTeamIds() {
1800
- return uniq(this.bundle.projects.map(function (p) {
1801
- return p.teamId ? "" + p.teamId + (p.indirect ? '@indirect' : '') : null;
1802
- }).filter(function (x) {
1803
- return !!x;
1696
+ _proto.mergeBundle = function mergeBundle(bundle) {
1697
+ var _this$onBundleMerged;
1698
+ this.bundle = mergeBundles(bundle, this.bundle);
1699
+ (_this$onBundleMerged = this.onBundleMerged) == null ? void 0 : _this$onBundleMerged.call(this);
1700
+ };
1701
+ _proto.getBundle = function getBundle() {
1702
+ return this.bundle;
1703
+ };
1704
+ _proto.clearCache = function clearCache() {
1705
+ this.bundle = {
1706
+ modules: {
1707
+ browser: [],
1708
+ server: []
1709
+ },
1710
+ components: [],
1711
+ globalGroups: [],
1712
+ external: [],
1713
+ projects: [],
1714
+ activeSplits: []
1715
+ };
1716
+ };
1717
+ return ReactServerPlasmicComponentLoader;
1718
+ }();
1719
+ function parseFetchComponentDataArgs() {
1720
+ var specs;
1721
+ var opts;
1722
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1723
+ args[_key2] = arguments[_key2];
1724
+ }
1725
+ if (Array.isArray(args[0])) {
1726
+ specs = args[0];
1727
+ opts = args[1];
1728
+ } else {
1729
+ specs = args;
1730
+ opts = undefined;
1731
+ }
1732
+ return {
1733
+ specs: specs,
1734
+ opts: opts
1735
+ };
1736
+ }
1737
+
1738
+ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1739
+ function InternalPlasmicComponentLoader(opts) {
1740
+ var _this = this;
1741
+ this.opts = opts;
1742
+ this.registry = new Registry();
1743
+ this.subs = [];
1744
+ this.roots = [];
1745
+ this.globalVariants = [];
1746
+ this.substitutedComponents = {};
1747
+ this.substitutedGlobalVariantHooks = {};
1748
+ this.tracker = new PlasmicTracker({
1749
+ projectIds: opts.projects.map(function (p) {
1750
+ return p.id;
1751
+ }),
1752
+ platform: opts.platform,
1753
+ preview: opts.preview
1754
+ });
1755
+ this.reactServerLoader = new ReactServerPlasmicComponentLoader({
1756
+ opts: opts,
1757
+ fetcher: new PlasmicModulesFetcher(opts),
1758
+ tracker: this.tracker,
1759
+ onBundleMerged: function onBundleMerged() {
1760
+ _this.refreshRegistry();
1761
+ },
1762
+ onBundleFetched: function onBundleFetched() {
1763
+ _this.roots.forEach(function (watcher) {
1764
+ return watcher.onDataFetched == null ? void 0 : watcher.onDataFetched();
1765
+ });
1766
+ }
1767
+ });
1768
+ this.registerModules({
1769
+ react: React__default,
1770
+ 'react-dom': ReactDOM,
1771
+ 'react/jsx-runtime': jsxRuntime,
1772
+ 'react/jsx-dev-runtime': jsxDevRuntime,
1773
+ // Also inject @plasmicapp/query and @plasmicapp/host to use the
1774
+ // same contexts here and in loader-downloaded code.
1775
+ '@plasmicapp/query': PlasmicQuery,
1776
+ '@plasmicapp/data-sources-context': PlasmicDataSourcesContext,
1777
+ '@plasmicapp/host': PlasmicHost,
1778
+ '@plasmicapp/loader-runtime-registry': {
1779
+ components: this.substitutedComponents,
1780
+ globalVariantHooks: this.substitutedGlobalVariantHooks
1781
+ }
1782
+ });
1783
+ }
1784
+ var _proto = InternalPlasmicComponentLoader.prototype;
1785
+ _proto.getBundle = function getBundle() {
1786
+ return this.reactServerLoader.getBundle();
1787
+ };
1788
+ _proto.setGlobalVariants = function setGlobalVariants(globalVariants) {
1789
+ this.globalVariants = globalVariants;
1790
+ };
1791
+ _proto.getGlobalVariants = function getGlobalVariants() {
1792
+ return this.globalVariants;
1793
+ };
1794
+ _proto.registerModules = function registerModules(modules) {
1795
+ var _this2 = this;
1796
+ if (Object.keys(modules).some(function (name) {
1797
+ return _this2.registry.getRegisteredModule(name) !== modules[name];
1798
+ })) {
1799
+ if (!this.registry.isEmpty()) {
1800
+ console.warn('Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over.');
1801
+ this.registry.clear();
1802
+ }
1803
+ for (var _i = 0, _Object$keys = Object.keys(modules); _i < _Object$keys.length; _i++) {
1804
+ var key = _Object$keys[_i];
1805
+ this.registry.register(key, modules[key]);
1806
+ }
1807
+ }
1808
+ };
1809
+ _proto.substituteComponent = function substituteComponent(component, name) {
1810
+ if (!this.registry.isEmpty()) {
1811
+ console.warn('Calling PlasmicComponentLoader.registerSubstitution() after Plasmic component has rendered; starting over.');
1812
+ this.registry.clear();
1813
+ }
1814
+ this.subs.push({
1815
+ lookup: name,
1816
+ component: component
1817
+ });
1818
+ };
1819
+ _proto.registerComponent = function registerComponent$1(component, meta) {
1820
+ var _meta$importPath;
1821
+ this.substituteComponent(component, {
1822
+ name: meta.name,
1823
+ isCode: true
1824
+ });
1825
+ // Import path is not used as we will use component substitution
1826
+ registerComponent(component, _extends({}, meta, {
1827
+ importPath: (_meta$importPath = meta.importPath) != null ? _meta$importPath : ''
1804
1828
  }));
1805
1829
  };
1806
- _proto.getProjectIds = function getProjectIds() {
1807
- return uniq(this.bundle.projects.map(function (p) {
1808
- return "" + p.id + (p.indirect ? '@indirect' : '');
1830
+ _proto.registerGlobalContext = function registerGlobalContext$1(context, meta) {
1831
+ var _meta$importPath2;
1832
+ this.substituteComponent(context, {
1833
+ name: meta.name,
1834
+ isCode: true
1835
+ });
1836
+ // Import path is not used as we will use component substitution
1837
+ registerGlobalContext(context, _extends({}, meta, {
1838
+ importPath: (_meta$importPath2 = meta.importPath) != null ? _meta$importPath2 : ''
1809
1839
  }));
1810
1840
  };
1811
- _proto.trackRender = function trackRender(opts) {
1812
- this.tracker.trackRender(opts);
1841
+ _proto.registerTrait = function registerTrait$1(trait, meta) {
1842
+ registerTrait(trait, meta);
1813
1843
  };
1814
- _proto.fetchAllData = /*#__PURE__*/function () {
1815
- var _fetchAllData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
1816
- var bundle;
1817
- return runtime_1.wrap(function _callee8$(_context8) {
1844
+ _proto.registerPrefetchedBundle = function registerPrefetchedBundle(bundle) {
1845
+ // For React Server Components (Next.js 13+),
1846
+ // we need to pass server modules in LoaderBundleOutput from Server Components to Client Components.
1847
+ // We don't want to pass them via normal page props because that will be serialized to the browser.
1848
+ // Instead, we pass the bundle (including the server modules) via the Node `global` variable.
1849
+ //
1850
+ // This is the code that reads the stored bundle and merges it back into the loader.
1851
+ if (!isBrowser) {
1852
+ // Check if a bundle is stored with the corresponding ID.
1853
+ if (bundle.localId !== undefined) {
1854
+ var _global$__PLASMIC_BUN;
1855
+ // If it's there, merge this bundle first.
1856
+ var storedBundle = (_global$__PLASMIC_BUN = global.__PLASMIC_BUNDLES) == null ? void 0 : _global$__PLASMIC_BUN[bundle.localId];
1857
+ if (storedBundle) {
1858
+ this.reactServerLoader.mergeBundle(storedBundle);
1859
+ }
1860
+ }
1861
+ }
1862
+ this.reactServerLoader.mergeBundle(bundle);
1863
+ };
1864
+ _proto.subscribePlasmicRoot = function subscribePlasmicRoot(watcher) {
1865
+ this.roots.push(watcher);
1866
+ };
1867
+ _proto.unsubscribePlasmicRoot = function unsubscribePlasmicRoot(watcher) {
1868
+ var index = this.roots.indexOf(watcher);
1869
+ if (index >= 0) {
1870
+ this.roots.splice(index, 1);
1871
+ }
1872
+ };
1873
+ _proto.clearCache = function clearCache() {
1874
+ this.reactServerLoader.clearCache();
1875
+ this.registry.clear();
1876
+ };
1877
+ _proto.getLookup = function getLookup() {
1878
+ return new ComponentLookup(this.getBundle(), this.registry);
1879
+ };
1880
+ _proto.maybeFetchComponentData = function maybeFetchComponentData() {
1881
+ var _this$reactServerLoad;
1882
+ return (_this$reactServerLoad = this.reactServerLoader).maybeFetchComponentData.apply(_this$reactServerLoad, arguments);
1883
+ };
1884
+ _proto.fetchComponentData = function fetchComponentData() {
1885
+ var _this$reactServerLoad2;
1886
+ return (_this$reactServerLoad2 = this.reactServerLoader).fetchComponentData.apply(_this$reactServerLoad2, arguments);
1887
+ };
1888
+ _proto.fetchPages = function fetchPages(opts) {
1889
+ return this.reactServerLoader.fetchPages(opts);
1890
+ };
1891
+ _proto.fetchComponents = function fetchComponents() {
1892
+ return this.reactServerLoader.fetchComponents();
1893
+ };
1894
+ _proto.getActiveSplits = function getActiveSplits() {
1895
+ return this.reactServerLoader.getActiveSplits();
1896
+ };
1897
+ _proto.trackConversion = function trackConversion(value) {
1898
+ if (value === void 0) {
1899
+ value = 0;
1900
+ }
1901
+ this.tracker.trackConversion(value);
1902
+ };
1903
+ _proto.getActiveVariation = /*#__PURE__*/function () {
1904
+ var _getActiveVariation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(opts) {
1905
+ return runtime_1.wrap(function _callee$(_context) {
1818
1906
  while (1) {
1819
- switch (_context8.prev = _context8.next) {
1907
+ switch (_context.prev = _context.next) {
1820
1908
  case 0:
1821
- _context8.next = 2;
1822
- return this.ensureFetcher().fetchAllData();
1909
+ _context.next = 2;
1910
+ return this.reactServerLoader.fetchComponents();
1823
1911
  case 2:
1824
- bundle = _context8.sent;
1825
- this.tracker.trackFetch();
1826
- this.mergeBundle(bundle);
1827
- this.roots.forEach(function (watcher) {
1828
- return watcher.onDataFetched == null ? void 0 : watcher.onDataFetched();
1829
- });
1830
- return _context8.abrupt("return", bundle);
1831
- case 7:
1912
+ return _context.abrupt("return", getActiveVariation(_extends({}, opts, {
1913
+ splits: this.getBundle().activeSplits
1914
+ })));
1915
+ case 3:
1832
1916
  case "end":
1833
- return _context8.stop();
1917
+ return _context.stop();
1834
1918
  }
1835
1919
  }
1836
- }, _callee8, this);
1920
+ }, _callee, this);
1837
1921
  }));
1838
- function fetchAllData() {
1839
- return _fetchAllData.apply(this, arguments);
1922
+ function getActiveVariation$1(_x) {
1923
+ return _getActiveVariation2.apply(this, arguments);
1840
1924
  }
1841
- return fetchAllData;
1925
+ return getActiveVariation$1;
1842
1926
  }();
1843
- _proto.mergeBundle = function mergeBundle(bundle) {
1844
- this.bundle = mergeBundles(bundle, this.bundle);
1845
- this.refreshRegistry();
1927
+ _proto.getTeamIds = function getTeamIds() {
1928
+ return uniq(this.getBundle().projects.map(function (p) {
1929
+ return p.teamId ? "" + p.teamId + (p.indirect ? '@indirect' : '') : null;
1930
+ }).filter(function (x) {
1931
+ return !!x;
1932
+ }));
1933
+ };
1934
+ _proto.getProjectIds = function getProjectIds() {
1935
+ return uniq(this.getBundle().projects.map(function (p) {
1936
+ return "" + p.id + (p.indirect ? '@indirect' : '');
1937
+ }));
1938
+ };
1939
+ _proto.trackRender = function trackRender(opts) {
1940
+ this.tracker.trackRender(opts);
1846
1941
  };
1847
1942
  _proto.refreshRegistry = function refreshRegistry() {
1848
1943
  var _this3 = this;
1849
1944
  var _loop = function _loop() {
1850
1945
  var sub = _step.value;
1851
- var metas = getCompMetas(_this3.bundle.components, sub.lookup);
1946
+ var metas = getCompMetas(_this3.getBundle().components, sub.lookup);
1852
1947
  metas.forEach(function (meta) {
1853
1948
  _this3.substitutedComponents[meta.id] = sub.component;
1854
1949
  });
@@ -1866,41 +1961,16 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1866
1961
  // context providers, but instead by <PlasmicRootProvider/> and by
1867
1962
  // PlasmicComponentLoader.setGlobalVariants(), we redirect these
1868
1963
  // hooks to read from them instead.
1869
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.bundle.globalGroups), _step2; !(_step2 = _iterator2()).done;) {
1964
+ for (var _iterator2 = _createForOfIteratorHelperLoose(this.getBundle().globalGroups), _step2; !(_step2 = _iterator2()).done;) {
1870
1965
  var globalGroup = _step2.value;
1871
1966
  if (globalGroup.type !== 'global-screen') {
1872
1967
  this.substitutedGlobalVariantHooks[globalGroup.id] = createUseGlobalVariant(globalGroup.name, globalGroup.projectId);
1873
1968
  }
1874
1969
  }
1875
- this.registry.updateModules(this.bundle);
1876
- };
1877
- _proto.ensureFetcher = function ensureFetcher() {
1878
- if (!this.fetcher) {
1879
- throw new Error("You must first call PlasmicComponentLoader.init()");
1880
- }
1881
- return this.fetcher;
1970
+ this.registry.updateModules(this.getBundle());
1882
1971
  };
1883
1972
  return InternalPlasmicComponentLoader;
1884
1973
  }();
1885
- function _maybeGetCompMetas(metas, specs) {
1886
- var found = new Set();
1887
- var missing = [];
1888
- for (var _iterator3 = _createForOfIteratorHelperLoose(specs), _step3; !(_step3 = _iterator3()).done;) {
1889
- var spec = _step3.value;
1890
- var filteredMetas = getCompMetas(metas, spec);
1891
- if (filteredMetas.length > 0) {
1892
- filteredMetas.forEach(function (meta) {
1893
- return found.add(meta);
1894
- });
1895
- } else {
1896
- missing.push(spec);
1897
- }
1898
- }
1899
- return {
1900
- found: Array.from(found.keys()),
1901
- missing: missing
1902
- };
1903
- }
1904
1974
  /**
1905
1975
  * Library for fetching component data, and registering
1906
1976
  * custom components.
@@ -1970,23 +2040,23 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
1970
2040
  _proto2.fetchComponentData =
1971
2041
  /*#__PURE__*/
1972
2042
  function () {
1973
- var _fetchComponentData2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
2043
+ var _fetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1974
2044
  var _this$__internal;
1975
- var _args9 = arguments;
1976
- return runtime_1.wrap(function _callee9$(_context9) {
2045
+ var _args2 = arguments;
2046
+ return runtime_1.wrap(function _callee2$(_context2) {
1977
2047
  while (1) {
1978
- switch (_context9.prev = _context9.next) {
2048
+ switch (_context2.prev = _context2.next) {
1979
2049
  case 0:
1980
- return _context9.abrupt("return", (_this$__internal = this.__internal).fetchComponentData.apply(_this$__internal, _args9));
2050
+ return _context2.abrupt("return", (_this$__internal = this.__internal).fetchComponentData.apply(_this$__internal, _args2));
1981
2051
  case 1:
1982
2052
  case "end":
1983
- return _context9.stop();
2053
+ return _context2.stop();
1984
2054
  }
1985
2055
  }
1986
- }, _callee9, this);
2056
+ }, _callee2, this);
1987
2057
  }));
1988
2058
  function fetchComponentData() {
1989
- return _fetchComponentData2.apply(this, arguments);
2059
+ return _fetchComponentData.apply(this, arguments);
1990
2060
  }
1991
2061
  return fetchComponentData;
1992
2062
  }()
@@ -1999,23 +2069,23 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
1999
2069
  _proto2.maybeFetchComponentData =
2000
2070
  /*#__PURE__*/
2001
2071
  function () {
2002
- var _maybeFetchComponentData2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10() {
2072
+ var _maybeFetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
2003
2073
  var _this$__internal2;
2004
- var _args10 = arguments;
2005
- return runtime_1.wrap(function _callee10$(_context10) {
2074
+ var _args3 = arguments;
2075
+ return runtime_1.wrap(function _callee3$(_context3) {
2006
2076
  while (1) {
2007
- switch (_context10.prev = _context10.next) {
2077
+ switch (_context3.prev = _context3.next) {
2008
2078
  case 0:
2009
- return _context10.abrupt("return", (_this$__internal2 = this.__internal).maybeFetchComponentData.apply(_this$__internal2, _args10));
2079
+ return _context3.abrupt("return", (_this$__internal2 = this.__internal).maybeFetchComponentData.apply(_this$__internal2, _args3));
2010
2080
  case 1:
2011
2081
  case "end":
2012
- return _context10.stop();
2082
+ return _context3.stop();
2013
2083
  }
2014
2084
  }
2015
- }, _callee10, this);
2085
+ }, _callee3, this);
2016
2086
  }));
2017
2087
  function maybeFetchComponentData() {
2018
- return _maybeFetchComponentData2.apply(this, arguments);
2088
+ return _maybeFetchComponentData.apply(this, arguments);
2019
2089
  }
2020
2090
  return maybeFetchComponentData;
2021
2091
  }()
@@ -2026,21 +2096,21 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
2026
2096
  _proto2.fetchPages =
2027
2097
  /*#__PURE__*/
2028
2098
  function () {
2029
- var _fetchPages2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(opts) {
2030
- return runtime_1.wrap(function _callee11$(_context11) {
2099
+ var _fetchPages = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(opts) {
2100
+ return runtime_1.wrap(function _callee4$(_context4) {
2031
2101
  while (1) {
2032
- switch (_context11.prev = _context11.next) {
2102
+ switch (_context4.prev = _context4.next) {
2033
2103
  case 0:
2034
- return _context11.abrupt("return", this.__internal.fetchPages(opts));
2104
+ return _context4.abrupt("return", this.__internal.fetchPages(opts));
2035
2105
  case 1:
2036
2106
  case "end":
2037
- return _context11.stop();
2107
+ return _context4.stop();
2038
2108
  }
2039
2109
  }
2040
- }, _callee11, this);
2110
+ }, _callee4, this);
2041
2111
  }));
2042
- function fetchPages(_x5) {
2043
- return _fetchPages2.apply(this, arguments);
2112
+ function fetchPages(_x2) {
2113
+ return _fetchPages.apply(this, arguments);
2044
2114
  }
2045
2115
  return fetchPages;
2046
2116
  }()
@@ -2051,50 +2121,50 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
2051
2121
  _proto2.fetchComponents =
2052
2122
  /*#__PURE__*/
2053
2123
  function () {
2054
- var _fetchComponents2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12() {
2055
- return runtime_1.wrap(function _callee12$(_context12) {
2124
+ var _fetchComponents = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
2125
+ return runtime_1.wrap(function _callee5$(_context5) {
2056
2126
  while (1) {
2057
- switch (_context12.prev = _context12.next) {
2127
+ switch (_context5.prev = _context5.next) {
2058
2128
  case 0:
2059
- return _context12.abrupt("return", this.__internal.fetchComponents());
2129
+ return _context5.abrupt("return", this.__internal.fetchComponents());
2060
2130
  case 1:
2061
2131
  case "end":
2062
- return _context12.stop();
2132
+ return _context5.stop();
2063
2133
  }
2064
2134
  }
2065
- }, _callee12, this);
2135
+ }, _callee5, this);
2066
2136
  }));
2067
2137
  function fetchComponents() {
2068
- return _fetchComponents2.apply(this, arguments);
2138
+ return _fetchComponents.apply(this, arguments);
2069
2139
  }
2070
2140
  return fetchComponents;
2071
2141
  }();
2072
2142
  _proto2._getActiveVariation = /*#__PURE__*/function () {
2073
- var _getActiveVariation3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(opts) {
2074
- return runtime_1.wrap(function _callee13$(_context13) {
2143
+ var _getActiveVariation3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(opts) {
2144
+ return runtime_1.wrap(function _callee6$(_context6) {
2075
2145
  while (1) {
2076
- switch (_context13.prev = _context13.next) {
2146
+ switch (_context6.prev = _context6.next) {
2077
2147
  case 0:
2078
- return _context13.abrupt("return", this.__internal.getActiveVariation(opts));
2148
+ return _context6.abrupt("return", this.__internal.getActiveVariation(opts));
2079
2149
  case 1:
2080
2150
  case "end":
2081
- return _context13.stop();
2151
+ return _context6.stop();
2082
2152
  }
2083
2153
  }
2084
- }, _callee13, this);
2154
+ }, _callee6, this);
2085
2155
  }));
2086
- function _getActiveVariation(_x6) {
2156
+ function _getActiveVariation(_x3) {
2087
2157
  return _getActiveVariation3.apply(this, arguments);
2088
2158
  }
2089
2159
  return _getActiveVariation;
2090
2160
  }();
2091
2161
  _proto2.getActiveVariation = /*#__PURE__*/function () {
2092
- var _getActiveVariation4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(opts) {
2093
- return runtime_1.wrap(function _callee14$(_context14) {
2162
+ var _getActiveVariation4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(opts) {
2163
+ return runtime_1.wrap(function _callee7$(_context7) {
2094
2164
  while (1) {
2095
- switch (_context14.prev = _context14.next) {
2165
+ switch (_context7.prev = _context7.next) {
2096
2166
  case 0:
2097
- return _context14.abrupt("return", this._getActiveVariation({
2167
+ return _context7.abrupt("return", this._getActiveVariation({
2098
2168
  traits: opts.traits,
2099
2169
  getKnownValue: function getKnownValue(key) {
2100
2170
  if (opts.known) {
@@ -2112,12 +2182,12 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
2112
2182
  }));
2113
2183
  case 1:
2114
2184
  case "end":
2115
- return _context14.stop();
2185
+ return _context7.stop();
2116
2186
  }
2117
2187
  }
2118
- }, _callee14, this);
2188
+ }, _callee7, this);
2119
2189
  }));
2120
- function getActiveVariation(_x7) {
2190
+ function getActiveVariation(_x4) {
2121
2191
  return _getActiveVariation4.apply(this, arguments);
2122
2192
  }
2123
2193
  return getActiveVariation;
@@ -2139,24 +2209,7 @@ var PlasmicComponentLoader = /*#__PURE__*/function () {
2139
2209
  };
2140
2210
  return PlasmicComponentLoader;
2141
2211
  }();
2142
- function parseFetchComponentDataArgs() {
2143
- var specs;
2144
- var opts;
2145
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2146
- args[_key2] = arguments[_key2];
2147
- }
2148
- if (Array.isArray(args[0])) {
2149
- specs = args[0];
2150
- opts = args[1];
2151
- } else {
2152
- specs = args;
2153
- opts = undefined;
2154
- }
2155
- return {
2156
- specs: specs,
2157
- opts: opts
2158
- };
2159
- }
2212
+ var global = globalThis;
2160
2213
 
2161
2214
  /**
2162
2215
  * Hook that fetches and returns a React component for rendering the argument
@@ -2567,5 +2620,10 @@ function makeElement(loader, lookup, opts) {
2567
2620
  }));
2568
2621
  }
2569
2622
 
2623
+ function initPlasmicLoader(opts) {
2624
+ var internal = new InternalPlasmicComponentLoader(opts);
2625
+ return new PlasmicComponentLoader(internal);
2626
+ }
2627
+
2570
2628
  export { InternalPlasmicComponentLoader, PlasmicComponent, PlasmicComponentLoader, PlasmicRootProvider, convertBundlesToComponentRenderData, extractPlasmicQueryData, extractPlasmicQueryDataFromElement, hydrateFromElement, initPlasmicLoader, matchesPagePath, plasmicPrepass, renderToElement, renderToString, usePlasmicComponent };
2571
2629
  //# sourceMappingURL=loader-react.esm.js.map