@plasmicapp/loader-react 1.0.36 → 1.0.37

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.
@@ -3,6 +3,8 @@ export { PlasmicCanvasContext, PlasmicCanvasHost, repeatedElement } from '@plasm
3
3
  import { getBundleSubset, Registry, PlasmicModulesFetcher } from '@plasmicapp/loader-core';
4
4
  import React__default, { useState, useCallback, useEffect, useRef, useMemo, createElement, memo, useContext, createContext } from 'react';
5
5
  import ReactDOM from 'react-dom';
6
+ import * as jsxDevRuntime from 'react/jsx-dev-runtime';
7
+ import * as jsxRuntime from 'react/jsx-runtime';
6
8
  import pascalcase from 'pascalcase';
7
9
  import ReactDOMServer from 'react-dom/server';
8
10
 
@@ -189,16 +191,29 @@ function mergeBundles(target, from) {
189
191
  });
190
192
  }
191
193
 
192
- var existingModules = new Set(target.modules.map(function (m) {
193
- return m.fileName;
194
- }));
195
- var newModules = from.modules.filter(function (m) {
196
- return !existingModules.has(m.fileName);
197
- });
194
+ var existingModules = {
195
+ browser: new Set(target.modules.browser.map(function (m) {
196
+ return m.fileName;
197
+ })),
198
+ server: new Set(target.modules.server.map(function (m) {
199
+ return m.fileName;
200
+ }))
201
+ };
202
+ var newModules = {
203
+ browser: from.modules.browser.filter(function (m) {
204
+ return !existingModules.browser.has(m.fileName);
205
+ }),
206
+ server: from.modules.server.filter(function (m) {
207
+ return !existingModules.server.has(m.fileName);
208
+ })
209
+ };
198
210
 
199
- if (newModules.length > 0) {
211
+ if (newModules.browser.length > 0 || newModules.server.length > 0) {
200
212
  target = _extends({}, target, {
201
- modules: [].concat(target.modules, newModules)
213
+ modules: {
214
+ browser: [].concat(target.modules.browser, newModules.browser),
215
+ server: [].concat(target.modules.server, newModules.server)
216
+ }
202
217
  });
203
218
  }
204
219
 
@@ -1149,7 +1164,8 @@ var ComponentLookup = /*#__PURE__*/function () {
1149
1164
  };
1150
1165
 
1151
1166
  _proto.getCss = function getCss() {
1152
- return this.bundle.modules.filter(function (mod) {
1167
+ // We can probably always get the modules from the browser build
1168
+ return this.bundle.modules.browser.filter(function (mod) {
1153
1169
  return mod.type === 'asset' && mod.fileName.endsWith('css');
1154
1170
  });
1155
1171
  };
@@ -1303,7 +1319,9 @@ function initPlasmicLoader(opts) {
1303
1319
  var internal = new InternalPlasmicComponentLoader(opts);
1304
1320
  internal.registerModules({
1305
1321
  react: React__default,
1306
- 'react-dom': ReactDOM
1322
+ 'react-dom': ReactDOM,
1323
+ 'react/jsx-runtime': jsxRuntime,
1324
+ 'react/jsx-dev-runtime': jsxDevRuntime
1307
1325
  });
1308
1326
  return new PlasmicComponentLoader(internal);
1309
1327
  }
@@ -1314,13 +1332,16 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1314
1332
  this.roots = [];
1315
1333
  this.globalVariants = [];
1316
1334
  this.bundle = {
1317
- modules: [],
1335
+ modules: {
1336
+ browser: [],
1337
+ server: []
1338
+ },
1318
1339
  components: [],
1319
1340
  globalGroups: [],
1320
1341
  external: [],
1321
1342
  projects: []
1322
1343
  };
1323
- this.registry = new Registry();
1344
+ this.registry = Registry.getInstance();
1324
1345
  this.fetcher = new PlasmicModulesFetcher(opts);
1325
1346
  }
1326
1347
 
@@ -1335,14 +1356,20 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1335
1356
  };
1336
1357
 
1337
1358
  _proto.registerModules = function registerModules(modules) {
1338
- if (!this.registry.isEmpty()) {
1339
- console.warn('Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over.');
1340
- this.registry.clear();
1341
- }
1359
+ var _this = this;
1360
+
1361
+ if (Object.keys(modules).some(function (name) {
1362
+ return _this.registry.getRegisteredModule(name) !== modules[name];
1363
+ })) {
1364
+ if (!this.registry.isEmpty()) {
1365
+ console.warn('Calling PlasmicComponentLoader.registerModules() after Plasmic component has rendered; starting over.');
1366
+ this.registry.clear();
1367
+ }
1342
1368
 
1343
- for (var _i = 0, _Object$keys = Object.keys(modules); _i < _Object$keys.length; _i++) {
1344
- var key = _Object$keys[_i];
1345
- this.registry.register(key, modules[key]);
1369
+ for (var _i = 0, _Object$keys = Object.keys(modules); _i < _Object$keys.length; _i++) {
1370
+ var key = _Object$keys[_i];
1371
+ this.registry.register(key, modules[key]);
1372
+ }
1346
1373
  }
1347
1374
  };
1348
1375
 
@@ -1389,7 +1416,10 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1389
1416
 
1390
1417
  _proto.clearCache = function clearCache() {
1391
1418
  this.bundle = {
1392
- modules: [],
1419
+ modules: {
1420
+ browser: [],
1421
+ server: []
1422
+ },
1393
1423
  components: [],
1394
1424
  globalGroups: [],
1395
1425
  external: [],
@@ -1408,13 +1438,13 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1408
1438
 
1409
1439
  _proto.maybeFetchComponentData = /*#__PURE__*/function () {
1410
1440
  var _maybeFetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1411
- var _this = this;
1441
+ var _this2 = this;
1412
1442
 
1413
1443
  var _len2,
1414
1444
  specs,
1415
1445
  _key2,
1416
1446
  returnWithSpecsToFetch,
1417
- _this$maybeGetCompMet2,
1447
+ _this$maybeGetCompMet,
1418
1448
  existingMetas,
1419
1449
  missingSpecs,
1420
1450
  _args2 = arguments;
@@ -1429,19 +1459,19 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1429
1459
 
1430
1460
  returnWithSpecsToFetch = /*#__PURE__*/function () {
1431
1461
  var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(specsToFetch) {
1432
- var _this$maybeGetCompMet, existingMetas2, missingSpecs2;
1462
+ var _this2$maybeGetCompMe, existingMetas2, missingSpecs2;
1433
1463
 
1434
1464
  return runtime_1.wrap(function _callee$(_context) {
1435
1465
  while (1) {
1436
1466
  switch (_context.prev = _context.next) {
1437
1467
  case 0:
1438
1468
  _context.next = 2;
1439
- return _this.fetchMissingData({
1469
+ return _this2.fetchMissingData({
1440
1470
  missingSpecs: specsToFetch
1441
1471
  });
1442
1472
 
1443
1473
  case 2:
1444
- _this$maybeGetCompMet = _this.maybeGetCompMetas.apply(_this, specs), existingMetas2 = _this$maybeGetCompMet.found, missingSpecs2 = _this$maybeGetCompMet.missing;
1474
+ _this2$maybeGetCompMe = _this2.maybeGetCompMetas.apply(_this2, specs), existingMetas2 = _this2$maybeGetCompMe.found, missingSpecs2 = _this2$maybeGetCompMe.missing;
1445
1475
 
1446
1476
  if (!(missingSpecs2.length > 0)) {
1447
1477
  _context.next = 5;
@@ -1451,7 +1481,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1451
1481
  return _context.abrupt("return", null);
1452
1482
 
1453
1483
  case 5:
1454
- return _context.abrupt("return", prepComponentData.apply(void 0, [_this.bundle].concat(existingMetas2)));
1484
+ return _context.abrupt("return", prepComponentData.apply(void 0, [_this2.bundle].concat(existingMetas2)));
1455
1485
 
1456
1486
  case 6:
1457
1487
  case "end":
@@ -1479,7 +1509,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1479
1509
 
1480
1510
  case 6:
1481
1511
  // Else we only fetch actually missing specs
1482
- _this$maybeGetCompMet2 = this.maybeGetCompMetas.apply(this, specs), existingMetas = _this$maybeGetCompMet2.found, missingSpecs = _this$maybeGetCompMet2.missing;
1512
+ _this$maybeGetCompMet = this.maybeGetCompMetas.apply(this, specs), existingMetas = _this$maybeGetCompMet.found, missingSpecs = _this$maybeGetCompMet.missing;
1483
1513
 
1484
1514
  if (!(missingSpecs.length === 0)) {
1485
1515
  _context2.next = 9;
@@ -1513,7 +1543,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1513
1543
  _proto.fetchComponentData = /*#__PURE__*/function () {
1514
1544
  var _fetchComponentData = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1515
1545
  var data,
1516
- _this$maybeGetCompMet3,
1546
+ _this$maybeGetCompMet2,
1517
1547
  missingSpecs,
1518
1548
  _args3 = arguments;
1519
1549
 
@@ -1532,7 +1562,7 @@ var InternalPlasmicComponentLoader = /*#__PURE__*/function () {
1532
1562
  break;
1533
1563
  }
1534
1564
 
1535
- _this$maybeGetCompMet3 = this.maybeGetCompMetas.apply(this, _args3), missingSpecs = _this$maybeGetCompMet3.missing;
1565
+ _this$maybeGetCompMet2 = this.maybeGetCompMetas.apply(this, _args3), missingSpecs = _this$maybeGetCompMet2.missing;
1536
1566
  throw new Error("Unable to find components " + missingSpecs.map(getLookupSpecName).join(', '));
1537
1567
 
1538
1568
  case 6: