@plasmicpkgs/plasmic-cms 0.0.46 → 0.0.50

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.
@@ -171,44 +171,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
171
171
  return target;
172
172
  }
173
173
 
174
- function _unsupportedIterableToArray(o, minLen) {
175
- if (!o) return;
176
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
177
- var n = Object.prototype.toString.call(o).slice(8, -1);
178
- if (n === "Object" && o.constructor) n = o.constructor.name;
179
- if (n === "Map" || n === "Set") return Array.from(o);
180
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
181
- }
182
-
183
- function _arrayLikeToArray(arr, len) {
184
- if (len == null || len > arr.length) len = arr.length;
185
-
186
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
187
-
188
- return arr2;
189
- }
190
-
191
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
192
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
193
- if (it) return (it = it.call(o)).next.bind(it);
194
-
195
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
196
- if (it) o = it;
197
- var i = 0;
198
- return function () {
199
- if (i >= o.length) return {
200
- done: true
201
- };
202
- return {
203
- done: false,
204
- value: o[i++]
205
- };
206
- };
207
- }
208
-
209
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
210
- }
211
-
212
174
  function createCommonjsModule(fn, module) {
213
175
  return module = { exports: {} }, fn(module, module.exports), module.exports;
214
176
  }
@@ -1222,55 +1184,6 @@ function TablesProvider(_ref2) {
1222
1184
  data: tables
1223
1185
  }, children);
1224
1186
  }
1225
- function useQueryResults(table) {
1226
- var env = host.useDataEnv();
1227
- var tables = useTables();
1228
-
1229
- if (!env) {
1230
- return undefined;
1231
- }
1232
-
1233
- if (table) {
1234
- var _env$mkQueryContextKe;
1235
-
1236
- return {
1237
- table: table,
1238
- rows: (_env$mkQueryContextKe = env[mkQueryContextKey(table)]) != null ? _env$mkQueryContextKe : []
1239
- };
1240
- }
1241
-
1242
- if (!tables) {
1243
- return undefined;
1244
- }
1245
-
1246
- var matchingKeys = getClosestMatchingKeys(env, queryResultPrefix);
1247
-
1248
- var _loop = function _loop() {
1249
- var key = _step.value;
1250
- var inferredTable = tables.find(function (t) {
1251
- return mkQueryContextKey(t.identifier) === key;
1252
- });
1253
-
1254
- if (inferredTable) {
1255
- var _env$key;
1256
-
1257
- return {
1258
- v: {
1259
- table: inferredTable.identifier,
1260
- rows: (_env$key = env[key]) != null ? _env$key : []
1261
- }
1262
- };
1263
- }
1264
- };
1265
-
1266
- for (var _iterator = _createForOfIteratorHelperLoose(matchingKeys), _step; !(_step = _iterator()).done;) {
1267
- var _ret = _loop();
1268
-
1269
- if (typeof _ret === "object") return _ret.v;
1270
- }
1271
-
1272
- return undefined;
1273
- }
1274
1187
 
1275
1188
  function getClosestMatchingKeys(env, prefix) {
1276
1189
  return [].concat(Object.keys(env).reverse()).filter(function (k) {
@@ -1287,7 +1200,7 @@ function QueryResultProvider(_ref3) {
1287
1200
  data: rows
1288
1201
  }, children);
1289
1202
  }
1290
- function useRow(table) {
1203
+ function useTablesWithDataLoaded() {
1291
1204
  var env = host.useDataEnv();
1292
1205
  var tables = useTables();
1293
1206
 
@@ -1295,39 +1208,33 @@ function useRow(table) {
1295
1208
  return undefined;
1296
1209
  }
1297
1210
 
1298
- if (table) {
1299
- return {
1300
- table: table,
1301
- row: env[mkRowContextKey(table)]
1302
- };
1303
- }
1304
-
1305
1211
  if (!tables) {
1306
1212
  return undefined;
1307
1213
  }
1308
1214
 
1309
1215
  var matchingKeys = getClosestMatchingKeys(env, rowContextPrefix);
1310
-
1311
- var _loop2 = function _loop2() {
1312
- var key = _step2.value;
1313
- var inferredTable = tables.find(function (t) {
1314
- return mkRowContextKey(t.identifier) === key;
1216
+ return tables.filter(function (table) {
1217
+ return matchingKeys.some(function (key) {
1218
+ return mkRowContextKey(table.identifier) === key;
1315
1219
  });
1220
+ });
1221
+ }
1222
+ function useRow(tables, table) {
1223
+ var env = host.useDataEnv();
1316
1224
 
1317
- if (inferredTable) {
1318
- return {
1319
- v: {
1320
- table: inferredTable.identifier,
1321
- row: env[key]
1322
- }
1323
- };
1324
- }
1325
- };
1225
+ if (!env) {
1226
+ return undefined;
1227
+ }
1326
1228
 
1327
- for (var _iterator2 = _createForOfIteratorHelperLoose(matchingKeys), _step2; !(_step2 = _iterator2()).done;) {
1328
- var _ret2 = _loop2();
1229
+ if (!table && tables && tables.length > 0) {
1230
+ table = tables[0].identifier;
1231
+ }
1329
1232
 
1330
- if (typeof _ret2 === "object") return _ret2.v;
1233
+ if (table) {
1234
+ return {
1235
+ table: table,
1236
+ row: env[mkRowContextKey(table)]
1237
+ };
1331
1238
  }
1332
1239
 
1333
1240
  return undefined;
@@ -1388,15 +1295,8 @@ var _excluded = ["children"],
1388
1295
  _excluded3 = ["table", "field", "valueProp", "children", "setControlContextData"];
1389
1296
  var modulePath = "@plasmicpkgs/plasmic-cms";
1390
1297
  var componentPrefix = "hostless-plasmic-cms";
1391
- var fetcherComponentPropMetas = {
1392
- hideIfNotFound: {
1393
- type: "boolean",
1394
- defaultValue: false,
1395
- description: "Whether to show an error if no result is found"
1396
- }
1397
- };
1398
1298
 
1399
- function renderMaybeData(maybeData, renderFn, loaderProps) {
1299
+ function renderMaybeData(maybeData, renderFn, loaderProps, loadingMessage, forceLoadingState) {
1400
1300
  if ("error" in maybeData) {
1401
1301
  var error = maybeData.error;
1402
1302
 
@@ -1411,8 +1311,8 @@ function renderMaybeData(maybeData, renderFn, loaderProps) {
1411
1311
  }
1412
1312
  }
1413
1313
 
1414
- if (!("data" in maybeData)) {
1415
- return React.createElement("div", null, "Loading...");
1314
+ if (!("data" in maybeData) || forceLoadingState) {
1315
+ return React.createElement(React.Fragment, null, loadingMessage != null ? loadingMessage : React.createElement("div", null, "Loading..."));
1416
1316
  }
1417
1317
 
1418
1318
  return renderFn(maybeData.data);
@@ -1422,6 +1322,7 @@ var defaultHost = "https://studio.plasmic.app";
1422
1322
  var cmsCredentialsProviderMeta = {
1423
1323
  name: componentPrefix + "-credentials-provider",
1424
1324
  displayName: "CMS Credentials Provider",
1325
+ description: "Find your CMS in the [dashboard](https://studio.plasmic.app), and go to the Settings tab for the ID and token.",
1425
1326
  importName: "CmsCredentialsProvider",
1426
1327
  importPath: modulePath,
1427
1328
  props: {
@@ -1501,204 +1402,26 @@ function TablesFetcher(_ref2) {
1501
1402
  });
1502
1403
  }
1503
1404
 
1504
- var cmsQueryLoaderMeta = {
1505
- name: componentPrefix + "-query-loader",
1506
- displayName: "CMS Data Loader",
1507
- importName: "CmsQueryLoader",
1508
- importPath: modulePath,
1509
- props: {
1510
- children: {
1511
- type: "slot",
1512
- defaultValue: {
1513
- type: "component",
1514
- name: componentPrefix + "-row-repeater"
1515
- }
1516
- },
1517
- table: {
1518
- type: "choice",
1519
- displayName: "Model",
1520
- description: "CMS model (table) to query.",
1521
- options: function options(_, ctx) {
1522
- return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1523
- }
1524
- },
1525
- useDraft: {
1526
- type: "boolean",
1527
- displayName: "Use drafts?",
1528
- description: "If set, also query unpublished content.",
1529
- defaultValue: false
1530
- },
1531
- where: {
1532
- type: "object",
1533
- displayName: "Filter",
1534
- description: "Filter clause, in JSON format."
1535
- },
1536
- orderBy: {
1537
- type: "choice",
1538
- displayName: "Order by",
1539
- description: "Field to order by.",
1540
- options: function options(_ref4, ctx) {
1541
- var table = _ref4.table;
1542
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, table);
1543
- }
1544
- },
1545
- desc: {
1546
- type: "boolean",
1547
- displayName: "Sort descending?",
1548
- description: 'Sort descending by "Order by" field.',
1549
- defaultValue: false
1550
- },
1551
- limit: {
1552
- type: "number",
1553
- displayName: "Limit",
1554
- description: "Maximum number of entries to fetch (0 for unlimited).",
1555
- defaultValue: 0
1556
- }
1557
- }
1558
- };
1559
-
1560
1405
  function isDatabaseConfigured(config) {
1561
1406
  return (config == null ? void 0 : config.databaseId) && (config == null ? void 0 : config.databaseToken);
1562
1407
  }
1563
1408
 
1564
- function CmsQueryLoader(_ref5) {
1565
- var table = _ref5.table,
1566
- children = _ref5.children,
1567
- setControlContextData = _ref5.setControlContextData,
1568
- where = _ref5.where,
1569
- useDraft = _ref5.useDraft,
1570
- orderBy = _ref5.orderBy,
1571
- desc = _ref5.desc,
1572
- limit = _ref5.limit;
1573
- var databaseConfig = useDatabase();
1574
- var tables = useTables();
1575
-
1576
- if (tables) {
1577
- // TODO: Only include table if __plasmic_cms_row_{table} exists.
1578
- setControlContextData == null ? void 0 : setControlContextData({
1579
- tables: tables
1580
- });
1581
- }
1582
-
1583
- var params = {
1584
- where: where,
1585
- useDraft: useDraft,
1586
- orderBy: orderBy,
1587
- desc: desc,
1588
- limit: limit
1589
- };
1590
- var cacheKey = JSON.stringify({
1591
- component: "CmsQueryLoader",
1592
- table: table,
1593
- databaseConfig: databaseConfig,
1594
- params: params
1595
- });
1596
- var maybeData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1597
- return runtime_1.wrap(function _callee2$(_context2) {
1598
- while (1) {
1599
- switch (_context2.prev = _context2.next) {
1600
- case 0:
1601
- if (isDatabaseConfigured(databaseConfig)) {
1602
- _context2.next = 2;
1603
- break;
1604
- }
1605
-
1606
- throw new Error("You must specify the CMS ID and API key");
1607
-
1608
- case 2:
1609
- if (table) {
1610
- _context2.next = 6;
1611
- break;
1612
- }
1613
-
1614
- throw new Error("You must select a model to query");
1615
-
1616
- case 6:
1617
- if (!(tables && !tables.find(function (t) {
1618
- return t.identifier === table;
1619
- }))) {
1620
- _context2.next = 8;
1621
- break;
1622
- }
1623
-
1624
- throw new Error("There is no model called \"" + table + "\"");
1625
-
1626
- case 8:
1627
- return _context2.abrupt("return", mkApi(databaseConfig).query(table, params));
1628
-
1629
- case 9:
1630
- case "end":
1631
- return _context2.stop();
1632
- }
1633
- }
1634
- }, _callee2);
1635
- })));
1636
- return renderMaybeData(maybeData, function (rows) {
1637
- return React.createElement(QueryResultProvider, {
1638
- table: table,
1639
- rows: rows
1640
- }, children);
1641
- }, {
1642
- hideIfNotFound: false
1643
- });
1644
- }
1645
- var cmsRowRepeaterMeta = {
1646
- name: componentPrefix + "-row-repeater",
1647
- displayName: "CMS Entry Repeater",
1648
- importName: "CmsRowRepeater",
1649
- importPath: modulePath,
1650
- props: {
1651
- children: {
1652
- type: "slot",
1653
- defaultValue: {
1654
- type: "component",
1655
- name: componentPrefix + "-row-field"
1656
- }
1657
- },
1658
- table: {
1659
- type: "choice",
1660
- displayName: "Model",
1661
- description: "CMS model (table) to use.",
1662
- options: function options(_, ctx) {
1663
- return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1664
- }
1665
- }
1666
- }
1667
- };
1668
- function CmsRowRepeater(_ref7) {
1669
- var table = _ref7.table,
1670
- children = _ref7.children,
1671
- setControlContextData = _ref7.setControlContextData;
1672
- var tables = useTables();
1673
-
1674
- if (tables) {
1675
- setControlContextData == null ? void 0 : setControlContextData({
1676
- tables: tables
1677
- });
1678
- }
1679
-
1680
- var res = useQueryResults(table);
1681
-
1682
- if (!res) {
1683
- return React.createElement("div", null, "Error: No CMS query result to repeat.");
1684
- }
1685
-
1686
- return React.createElement(React.Fragment, null, res.rows.map(function (row, index) {
1687
- return React.createElement(RowProvider, {
1688
- table: res.table,
1689
- row: row
1690
- }, host.repeatedElement(index === 0, children));
1691
- }));
1692
- }
1693
1409
  var cmsQueryRepeaterMeta = {
1694
1410
  name: componentPrefix + "-query-repeater",
1695
1411
  displayName: "CMS Data Loader",
1696
1412
  description: "Fetches CMS data and repeats content of children once for every row fetched.",
1697
1413
  importName: "CmsQueryRepeater",
1698
1414
  importPath: modulePath,
1415
+ defaultStyles: {
1416
+ display: "flex",
1417
+ width: "stretch",
1418
+ maxWidth: "100%",
1419
+ flexDirection: "column"
1420
+ },
1699
1421
  props: {
1700
1422
  children: {
1701
1423
  type: "slot",
1424
+ isRepeated: true,
1702
1425
  defaultValue: {
1703
1426
  type: "vbox",
1704
1427
  children: [{
@@ -1713,13 +1436,19 @@ var cmsQueryRepeaterMeta = {
1713
1436
  description: "CMS model (table) to query.",
1714
1437
  options: function options(_, ctx) {
1715
1438
  return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1439
+ },
1440
+ defaultValueHint: function defaultValueHint(_, ctx) {
1441
+ return ctx == null ? void 0 : ctx.table;
1716
1442
  }
1717
1443
  },
1718
1444
  useDraft: {
1719
1445
  type: "boolean",
1720
1446
  displayName: "Use drafts?",
1721
1447
  description: "If set, also query unpublished content.",
1722
- defaultValue: false
1448
+ defaultValue: false,
1449
+ hidden: function hidden() {
1450
+ return true;
1451
+ }
1723
1452
  },
1724
1453
  where: {
1725
1454
  type: "object",
@@ -1733,9 +1462,8 @@ var cmsQueryRepeaterMeta = {
1733
1462
  type: "choice",
1734
1463
  displayName: "Order by",
1735
1464
  description: "Field to order by.",
1736
- options: function options(_ref8, ctx) {
1737
- var table = _ref8.table;
1738
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, table);
1465
+ options: function options(_, ctx) {
1466
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, ctx == null ? void 0 : ctx.table);
1739
1467
  }
1740
1468
  },
1741
1469
  desc: {
@@ -1749,28 +1477,51 @@ var cmsQueryRepeaterMeta = {
1749
1477
  displayName: "Limit",
1750
1478
  description: "Maximum number of entries to fetch (0 for unlimited).",
1751
1479
  defaultValue: 0
1480
+ },
1481
+ emptyMessage: {
1482
+ type: "slot",
1483
+ defaultValue: {
1484
+ type: "text",
1485
+ value: "No matching published entries found."
1486
+ }
1487
+ },
1488
+ forceEmptyState: {
1489
+ type: "boolean",
1490
+ displayName: "Force empty state",
1491
+ description: "If set, will render as if no matching entries were found.",
1492
+ defaultValue: false
1493
+ },
1494
+ loadingMessage: {
1495
+ type: "slot",
1496
+ defaultValue: {
1497
+ type: "text",
1498
+ value: "Loading..."
1499
+ }
1500
+ },
1501
+ forceLoadingState: {
1502
+ type: "boolean",
1503
+ displayName: "Force loading state",
1504
+ description: "If set, will render as if it is waiting for the query to run.",
1505
+ defaultValue: false
1752
1506
  }
1753
1507
  }
1754
1508
  };
1755
- function CmsQueryRepeater(_ref9) {
1756
- var table = _ref9.table,
1757
- children = _ref9.children,
1758
- setControlContextData = _ref9.setControlContextData,
1759
- where = _ref9.where,
1760
- useDraft = _ref9.useDraft,
1761
- orderBy = _ref9.orderBy,
1762
- desc = _ref9.desc,
1763
- limit = _ref9.limit;
1509
+ function CmsQueryRepeater(_ref4) {
1510
+ var table = _ref4.table,
1511
+ children = _ref4.children,
1512
+ setControlContextData = _ref4.setControlContextData,
1513
+ where = _ref4.where,
1514
+ useDraft = _ref4.useDraft,
1515
+ orderBy = _ref4.orderBy,
1516
+ desc = _ref4.desc,
1517
+ limit = _ref4.limit,
1518
+ emptyMessage = _ref4.emptyMessage,
1519
+ forceEmptyState = _ref4.forceEmptyState,
1520
+ loadingMessage = _ref4.loadingMessage,
1521
+ forceLoadingState = _ref4.forceLoadingState,
1522
+ className = _ref4.className;
1764
1523
  var databaseConfig = useDatabase();
1765
1524
  var tables = useTables();
1766
-
1767
- if (tables) {
1768
- // TODO: Only include table if __plasmic_cms_row_{table} exists.
1769
- setControlContextData == null ? void 0 : setControlContextData({
1770
- tables: tables
1771
- });
1772
- }
1773
-
1774
1525
  var params = {
1775
1526
  where: where,
1776
1527
  useDraft: useDraft,
@@ -1789,13 +1540,21 @@ function CmsQueryRepeater(_ref9) {
1789
1540
  table = tables[0].identifier;
1790
1541
  }
1791
1542
 
1792
- var maybeData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1793
- return runtime_1.wrap(function _callee3$(_context3) {
1543
+ if (tables) {
1544
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
1545
+ setControlContextData == null ? void 0 : setControlContextData({
1546
+ tables: tables,
1547
+ table: table
1548
+ });
1549
+ }
1550
+
1551
+ var maybeData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1552
+ return runtime_1.wrap(function _callee2$(_context2) {
1794
1553
  while (1) {
1795
- switch (_context3.prev = _context3.next) {
1554
+ switch (_context2.prev = _context2.next) {
1796
1555
  case 0:
1797
1556
  if (isDatabaseConfigured(databaseConfig)) {
1798
- _context3.next = 2;
1557
+ _context2.next = 2;
1799
1558
  break;
1800
1559
  }
1801
1560
 
@@ -1803,7 +1562,7 @@ function CmsQueryRepeater(_ref9) {
1803
1562
 
1804
1563
  case 2:
1805
1564
  if (table) {
1806
- _context3.next = 6;
1565
+ _context2.next = 6;
1807
1566
  break;
1808
1567
  }
1809
1568
 
@@ -1813,25 +1572,30 @@ function CmsQueryRepeater(_ref9) {
1813
1572
  if (!(tables && !tables.find(function (t) {
1814
1573
  return t.identifier === table;
1815
1574
  }))) {
1816
- _context3.next = 10;
1575
+ _context2.next = 10;
1817
1576
  break;
1818
1577
  }
1819
1578
 
1820
1579
  throw new Error("There is no model called \"" + table + "\"");
1821
1580
 
1822
1581
  case 10:
1823
- return _context3.abrupt("return", mkApi(databaseConfig).query(table, params));
1582
+ return _context2.abrupt("return", mkApi(databaseConfig).query(table, params));
1824
1583
 
1825
1584
  case 11:
1826
1585
  case "end":
1827
- return _context3.stop();
1586
+ return _context2.stop();
1828
1587
  }
1829
1588
  }
1830
- }, _callee3);
1589
+ }, _callee2);
1831
1590
  })));
1832
- return renderMaybeData(maybeData, function (rows) {
1833
- if (rows.length === 0) {
1834
- return React.createElement("div", null, "No matching entries found.");
1591
+ return React.createElement("div", {
1592
+ className: className
1593
+ }, renderMaybeData(maybeData, function (rows) {
1594
+ if (rows.length === 0 || forceEmptyState) {
1595
+ return React.createElement(QueryResultProvider, {
1596
+ table: table,
1597
+ rows: rows
1598
+ }, emptyMessage);
1835
1599
  }
1836
1600
 
1837
1601
  return React.createElement(QueryResultProvider, {
@@ -1845,7 +1609,7 @@ function CmsQueryRepeater(_ref9) {
1845
1609
  }));
1846
1610
  }, {
1847
1611
  hideIfNotFound: false
1848
- });
1612
+ }, loadingMessage, forceLoadingState));
1849
1613
  }
1850
1614
  var cmsRowFieldMeta = {
1851
1615
  name: componentPrefix + "-row-field",
@@ -1859,24 +1623,32 @@ var cmsRowFieldMeta = {
1859
1623
  description: "CMS model (table) to use.",
1860
1624
  options: function options(_, ctx) {
1861
1625
  return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1626
+ },
1627
+ defaultValueHint: function defaultValueHint(_, ctx) {
1628
+ return ctx == null ? void 0 : ctx.table;
1862
1629
  }
1863
1630
  },
1864
1631
  field: {
1865
1632
  type: "choice",
1866
1633
  displayName: "Field",
1867
1634
  description: "Field (from model schema) to use.",
1868
- options: function options(_ref11, ctx) {
1635
+ options: function options(_ref6, ctx) {
1869
1636
  var _ctx$table;
1870
1637
 
1871
- var table = _ref11.table;
1638
+ var table = _ref6.table;
1872
1639
  return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table = ctx == null ? void 0 : ctx.table) != null ? _ctx$table : table, ["number", "boolean", "text", "long-text", "date-time", "rich-text", "image"]);
1640
+ },
1641
+ defaultValueHint: function defaultValueHint(_, ctx) {
1642
+ var _ctx$fieldMeta, _ctx$fieldMeta2;
1643
+
1644
+ return (ctx == null ? void 0 : (_ctx$fieldMeta = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta.name) || (ctx == null ? void 0 : (_ctx$fieldMeta2 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta2.identifier);
1873
1645
  }
1874
1646
  },
1875
1647
  dateFormat: {
1876
1648
  type: "choice",
1877
1649
  displayName: "Date Format",
1878
- hidden: function hidden(_ref12, ctx) {
1879
- var field = _ref12.field;
1650
+ hidden: function hidden(_ref7, ctx) {
1651
+ var field = _ref7.field;
1880
1652
 
1881
1653
  if (!ctx) {
1882
1654
  return true;
@@ -1945,18 +1717,18 @@ var cmsRowFieldMeta = {
1945
1717
  }
1946
1718
  }
1947
1719
  };
1948
- function CmsRowField(_ref13) {
1720
+ function CmsRowField(_ref8) {
1949
1721
  var _res$row$data;
1950
1722
 
1951
- var className = _ref13.className,
1952
- table = _ref13.table,
1953
- field = _ref13.field,
1954
- dateFormat = _ref13.dateFormat,
1955
- setControlContextData = _ref13.setControlContextData,
1956
- rest = _objectWithoutPropertiesLoose(_ref13, _excluded2);
1723
+ var className = _ref8.className,
1724
+ table = _ref8.table,
1725
+ field = _ref8.field,
1726
+ dateFormat = _ref8.dateFormat,
1727
+ setControlContextData = _ref8.setControlContextData,
1728
+ rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
1957
1729
 
1958
- var tables = useTables();
1959
- var res = useRow(table);
1730
+ var tables = useTablesWithDataLoaded();
1731
+ var res = useRow(tables, table);
1960
1732
 
1961
1733
  if (!res) {
1962
1734
  return React.createElement("div", {
@@ -1970,22 +1742,23 @@ function CmsRowField(_ref13) {
1970
1742
  }, "Error: No CMS Entry found");
1971
1743
  }
1972
1744
 
1745
+ var fieldMeta = deriveInferredTableField({
1746
+ table: res.table,
1747
+ tables: tables,
1748
+ field: field,
1749
+ typeFilters: ["text", "long-text", "rich-text"]
1750
+ });
1751
+
1973
1752
  if (tables) {
1974
1753
  // TODO: Only include table if __plasmic_cms_row_{table} exists.
1975
1754
  setControlContextData == null ? void 0 : setControlContextData({
1976
1755
  tables: tables,
1977
1756
  table: res.table,
1978
- row: res.row
1757
+ row: res.row,
1758
+ fieldMeta: fieldMeta
1979
1759
  });
1980
1760
  }
1981
1761
 
1982
- var fieldMeta = deriveInferredTableField({
1983
- table: res.table,
1984
- tables: tables,
1985
- field: field,
1986
- typeFilters: ["text", "long-text", "rich-text"]
1987
- });
1988
-
1989
1762
  if (!fieldMeta) {
1990
1763
  throw new Error("Please select an entry field to display.");
1991
1764
  }
@@ -2013,6 +1786,7 @@ function deriveInferredTableField(opts) {
2013
1786
  tables = opts.tables,
2014
1787
  field = opts.field,
2015
1788
  typeFilters = opts.typeFilters;
1789
+ if (!table) return undefined;
2016
1790
  var schema = tables == null ? void 0 : (_tables$find = tables.find(function (t) {
2017
1791
  return t.identifier === table;
2018
1792
  })) == null ? void 0 : _tables$find.schema;
@@ -2048,8 +1822,11 @@ function renderValue(value, type, props) {
2048
1822
  if (value && typeof value === "object" && value.url && value.imageMeta) {
2049
1823
  return React.createElement("img", Object.assign({
2050
1824
  src: value.url,
2051
- width: value.imageMeta.height,
2052
- height: value.imageMeta.height
1825
+ width: value.imageMeta.width,
1826
+ height: value.imageMeta.height,
1827
+ style: {
1828
+ objectFit: "cover"
1829
+ }
2053
1830
  }, props));
2054
1831
  }
2055
1832
 
@@ -2080,17 +1857,25 @@ var cmsRowLinkMeta = {
2080
1857
  description: "CMS model (table) to use.",
2081
1858
  options: function options(_, ctx) {
2082
1859
  return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1860
+ },
1861
+ defaultValueHint: function defaultValueHint(_, ctx) {
1862
+ return ctx == null ? void 0 : ctx.table;
2083
1863
  }
2084
1864
  },
2085
1865
  field: {
2086
1866
  type: "choice",
2087
1867
  displayName: "Field",
2088
1868
  description: "Field (from model schema) to use.",
2089
- options: function options(_ref14, ctx) {
1869
+ options: function options(_ref9, ctx) {
2090
1870
  var _ctx$table2;
2091
1871
 
2092
- var table = _ref14.table;
1872
+ var table = _ref9.table;
2093
1873
  return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table2 = ctx == null ? void 0 : ctx.table) != null ? _ctx$table2 : table);
1874
+ },
1875
+ defaultValueHint: function defaultValueHint(_, ctx) {
1876
+ var _ctx$fieldMeta3, _ctx$fieldMeta4;
1877
+
1878
+ return (ctx == null ? void 0 : (_ctx$fieldMeta3 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta3.name) || (ctx == null ? void 0 : (_ctx$fieldMeta4 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta4.identifier);
2094
1879
  }
2095
1880
  },
2096
1881
  hrefProp: {
@@ -2111,31 +1896,23 @@ var cmsRowLinkMeta = {
2111
1896
  }
2112
1897
  }
2113
1898
  };
2114
- function CmsRowLink(_ref15) {
1899
+ function CmsRowLink(_ref10) {
2115
1900
  var _res$row$data2;
2116
1901
 
2117
- var table = _ref15.table,
2118
- field = _ref15.field,
2119
- hrefProp = _ref15.hrefProp,
2120
- children = _ref15.children,
2121
- setControlContextData = _ref15.setControlContextData,
2122
- prefix = _ref15.prefix,
2123
- suffix = _ref15.suffix;
2124
- var tables = useTables();
2125
- var res = useRow(table);
1902
+ var table = _ref10.table,
1903
+ field = _ref10.field,
1904
+ hrefProp = _ref10.hrefProp,
1905
+ children = _ref10.children,
1906
+ setControlContextData = _ref10.setControlContextData,
1907
+ prefix = _ref10.prefix,
1908
+ suffix = _ref10.suffix;
1909
+ var tables = useTablesWithDataLoaded();
1910
+ var res = useRow(tables, table);
2126
1911
 
2127
1912
  if (!res || !res.row) {
2128
1913
  return React.createElement(React.Fragment, null, children);
2129
1914
  }
2130
1915
 
2131
- if (tables) {
2132
- // TODO: Only include table if __plasmic_cms_row_{table} exists.
2133
- setControlContextData == null ? void 0 : setControlContextData({
2134
- tables: tables,
2135
- table: res.table
2136
- });
2137
- }
2138
-
2139
1916
  var fieldMeta = deriveInferredTableField({
2140
1917
  table: res.table,
2141
1918
  tables: tables,
@@ -2143,6 +1920,16 @@ function CmsRowLink(_ref15) {
2143
1920
  typeFilters: ["text"]
2144
1921
  });
2145
1922
 
1923
+ if (tables) {
1924
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
1925
+ setControlContextData == null ? void 0 : setControlContextData({
1926
+ tables: tables,
1927
+ table: res.table,
1928
+ row: res.row,
1929
+ fieldMeta: fieldMeta
1930
+ });
1931
+ }
1932
+
2146
1933
  if (!fieldMeta) {
2147
1934
  return React.createElement(React.Fragment, null, children);
2148
1935
  }
@@ -2182,17 +1969,25 @@ var cmsRowImageMeta = {
2182
1969
  description: "CMS model (table) to use.",
2183
1970
  options: function options(_, ctx) {
2184
1971
  return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1972
+ },
1973
+ defaultValueHint: function defaultValueHint(_, ctx) {
1974
+ return ctx == null ? void 0 : ctx.table;
2185
1975
  }
2186
1976
  },
2187
1977
  field: {
2188
1978
  type: "choice",
2189
1979
  displayName: "Field",
2190
1980
  description: "Field (from model schema) to use.",
2191
- options: function options(_ref16, ctx) {
1981
+ options: function options(_ref11, ctx) {
2192
1982
  var _ctx$table3;
2193
1983
 
2194
- var table = _ref16.table;
2195
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table3 = ctx == null ? void 0 : ctx.table) != null ? _ctx$table3 : table);
1984
+ var table = _ref11.table;
1985
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table3 = ctx == null ? void 0 : ctx.table) != null ? _ctx$table3 : table, ["image"]);
1986
+ },
1987
+ defaultValueHint: function defaultValueHint(_, ctx) {
1988
+ var _ctx$fieldMeta5, _ctx$fieldMeta6;
1989
+
1990
+ return (ctx == null ? void 0 : (_ctx$fieldMeta5 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta5.name) || (ctx == null ? void 0 : (_ctx$fieldMeta6 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta6.identifier);
2196
1991
  }
2197
1992
  },
2198
1993
  srcProp: {
@@ -2203,29 +1998,21 @@ var cmsRowImageMeta = {
2203
1998
  }
2204
1999
  }
2205
2000
  };
2206
- function CmsRowImage(_ref17) {
2001
+ function CmsRowImage(_ref12) {
2207
2002
  var _res$row$data3;
2208
2003
 
2209
- var table = _ref17.table,
2210
- field = _ref17.field,
2211
- srcProp = _ref17.srcProp,
2212
- children = _ref17.children,
2213
- setControlContextData = _ref17.setControlContextData;
2214
- var tables = useTables();
2215
- var res = useRow(table);
2004
+ var table = _ref12.table,
2005
+ field = _ref12.field,
2006
+ srcProp = _ref12.srcProp,
2007
+ children = _ref12.children,
2008
+ setControlContextData = _ref12.setControlContextData;
2009
+ var tables = useTablesWithDataLoaded();
2010
+ var res = useRow(tables, table);
2216
2011
 
2217
2012
  if (!res || !res.row) {
2218
2013
  return React.createElement(React.Fragment, null, children);
2219
2014
  }
2220
2015
 
2221
- if (tables) {
2222
- // TODO: Only include table if __plasmic_cms_row_{table} exists.
2223
- setControlContextData == null ? void 0 : setControlContextData({
2224
- tables: tables,
2225
- table: res.table
2226
- });
2227
- }
2228
-
2229
2016
  var fieldMeta = deriveInferredTableField({
2230
2017
  table: res.table,
2231
2018
  tables: tables,
@@ -2233,6 +2020,16 @@ function CmsRowImage(_ref17) {
2233
2020
  typeFilters: ["image"]
2234
2021
  });
2235
2022
 
2023
+ if (tables) {
2024
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
2025
+ setControlContextData == null ? void 0 : setControlContextData({
2026
+ tables: tables,
2027
+ table: res.table,
2028
+ row: res.row,
2029
+ fieldMeta: fieldMeta
2030
+ });
2031
+ }
2032
+
2236
2033
  if (!fieldMeta) {
2237
2034
  return React.createElement(React.Fragment, null, children);
2238
2035
  }
@@ -2274,17 +2071,25 @@ var cmsRowFieldValueMeta = {
2274
2071
  description: "CMS model (table) to use.",
2275
2072
  options: function options(_, ctx) {
2276
2073
  return mkTableOptions(ctx == null ? void 0 : ctx.tables);
2074
+ },
2075
+ defaultValueHint: function defaultValueHint(_, ctx) {
2076
+ return ctx == null ? void 0 : ctx.table;
2277
2077
  }
2278
2078
  },
2279
2079
  field: {
2280
2080
  type: "choice",
2281
2081
  displayName: "Field",
2282
2082
  description: "Field (from model schema) to use.",
2283
- options: function options(_ref18, ctx) {
2083
+ options: function options(_ref13, ctx) {
2284
2084
  var _ctx$table4;
2285
2085
 
2286
- var table = _ref18.table;
2086
+ var table = _ref13.table;
2287
2087
  return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table4 = ctx == null ? void 0 : ctx.table) != null ? _ctx$table4 : table);
2088
+ },
2089
+ defaultValueHint: function defaultValueHint(_, ctx) {
2090
+ var _ctx$fieldMeta7, _ctx$fieldMeta8;
2091
+
2092
+ return (ctx == null ? void 0 : (_ctx$fieldMeta7 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta7.name) || (ctx == null ? void 0 : (_ctx$fieldMeta8 = ctx.fieldMeta) == null ? void 0 : _ctx$fieldMeta8.identifier);
2288
2093
  }
2289
2094
  },
2290
2095
  valueProp: {
@@ -2295,31 +2100,23 @@ var cmsRowFieldValueMeta = {
2295
2100
  }
2296
2101
  }
2297
2102
  };
2298
- function CmsRowFieldValue(_ref19) {
2103
+ function CmsRowFieldValue(_ref14) {
2299
2104
  var _res$row$data4;
2300
2105
 
2301
- var table = _ref19.table,
2302
- field = _ref19.field,
2303
- valueProp = _ref19.valueProp,
2304
- children = _ref19.children,
2305
- setControlContextData = _ref19.setControlContextData,
2306
- rest = _objectWithoutPropertiesLoose(_ref19, _excluded3);
2106
+ var table = _ref14.table,
2107
+ field = _ref14.field,
2108
+ valueProp = _ref14.valueProp,
2109
+ children = _ref14.children,
2110
+ setControlContextData = _ref14.setControlContextData,
2111
+ rest = _objectWithoutPropertiesLoose(_ref14, _excluded3);
2307
2112
 
2308
- var tables = useTables();
2309
- var res = useRow(table);
2113
+ var tables = useTablesWithDataLoaded();
2114
+ var res = useRow(tables, table);
2310
2115
 
2311
2116
  if (!res || !res.row) {
2312
2117
  return React.createElement(React.Fragment, null, children);
2313
2118
  }
2314
2119
 
2315
- if (tables) {
2316
- // TODO: Only include table if __plasmic_cms_row_{table} exists.
2317
- setControlContextData == null ? void 0 : setControlContextData({
2318
- tables: tables,
2319
- table: res.table
2320
- });
2321
- }
2322
-
2323
2120
  var fieldMeta = deriveInferredTableField({
2324
2121
  table: res.table,
2325
2122
  tables: tables,
@@ -2327,6 +2124,16 @@ function CmsRowFieldValue(_ref19) {
2327
2124
  typeFilters: ["text"]
2328
2125
  });
2329
2126
 
2127
+ if (tables) {
2128
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
2129
+ setControlContextData == null ? void 0 : setControlContextData({
2130
+ tables: tables,
2131
+ table: res.table,
2132
+ row: res.row,
2133
+ fieldMeta: fieldMeta
2134
+ });
2135
+ }
2136
+
2330
2137
  if (!fieldMeta) {
2331
2138
  return React.createElement(React.Fragment, null, children);
2332
2139
  }
@@ -2343,106 +2150,6 @@ function CmsRowFieldValue(_ref19) {
2343
2150
  });
2344
2151
  return React.createElement(React.Fragment, null, childrenWithProps);
2345
2152
  }
2346
- var cmsRowLoaderMeta = {
2347
- name: componentPrefix + "-row-loader",
2348
- displayName: "CMS Row Loader",
2349
- importName: "CmsRowLoader",
2350
- importPath: modulePath,
2351
- props: /*#__PURE__*/_extends({
2352
- children: {
2353
- type: "slot",
2354
- defaultValue: {
2355
- type: "component",
2356
- name: componentPrefix + "-row-field"
2357
- }
2358
- },
2359
- row: {
2360
- type: "string",
2361
- displayName: "Entry ID",
2362
- description: "Row identifier to query."
2363
- },
2364
- table: {
2365
- type: "choice",
2366
- displayName: "Model",
2367
- description: "CMS model (table) to query.",
2368
- options: function options(_, ctx) {
2369
- return mkTableOptions(ctx == null ? void 0 : ctx.tables);
2370
- }
2371
- },
2372
- useDraft: {
2373
- type: "boolean",
2374
- displayName: "Use drafts?",
2375
- description: "If set, also query unpublished content.",
2376
- defaultValue: false
2377
- }
2378
- }, fetcherComponentPropMetas)
2379
- };
2380
- function CmsRowLoader(_ref20) {
2381
- var table = _ref20.table,
2382
- row = _ref20.row,
2383
- children = _ref20.children,
2384
- useDraft = _ref20.useDraft,
2385
- hideIfNotFound = _ref20.hideIfNotFound,
2386
- setControlContextData = _ref20.setControlContextData;
2387
- var databaseConfig = useDatabase();
2388
- var tables = useTables();
2389
-
2390
- if (tables) {
2391
- setControlContextData == null ? void 0 : setControlContextData({
2392
- tables: tables
2393
- });
2394
- }
2395
-
2396
- var cacheKey = JSON.stringify({
2397
- component: "CmsRowLoader",
2398
- table: table,
2399
- row: row,
2400
- databaseConfig: databaseConfig,
2401
- useDraft: useDraft
2402
- });
2403
- var maybeData = query.usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
2404
- return runtime_1.wrap(function _callee4$(_context4) {
2405
- while (1) {
2406
- switch (_context4.prev = _context4.next) {
2407
- case 0:
2408
- if (table) {
2409
- _context4.next = 2;
2410
- break;
2411
- }
2412
-
2413
- throw new Error("You must specify a model to fetch from.");
2414
-
2415
- case 2:
2416
- if (row) {
2417
- _context4.next = 4;
2418
- break;
2419
- }
2420
-
2421
- throw new Error("You must specify an entry name to fetch.");
2422
-
2423
- case 4:
2424
- _context4.next = 6;
2425
- return mkApi(databaseConfig).fetchRow(table, row, useDraft);
2426
-
2427
- case 6:
2428
- return _context4.abrupt("return", _context4.sent);
2429
-
2430
- case 7:
2431
- case "end":
2432
- return _context4.stop();
2433
- }
2434
- }
2435
- }, _callee4);
2436
- })));
2437
- return renderMaybeData(maybeData, function (row) {
2438
- return React.createElement(RowProvider, {
2439
- table: table,
2440
- row: row
2441
- }, children);
2442
- }, {
2443
- hideIfNotFound: hideIfNotFound
2444
- });
2445
- }
2446
2153
 
2447
2154
  function registerAll(loader) {
2448
2155
  //const registerContext = loader?.registerContext ?? hostRegisterContext;
@@ -2463,9 +2170,7 @@ function registerAll(loader) {
2463
2170
  }
2464
2171
  };
2465
2172
 
2466
- _registerGlobalContext(CmsCredentialsProvider, cmsCredentialsProviderMeta); // _registerComponent(CmsQueryLoader, cmsQueryLoaderMeta);
2467
- // _registerComponent(CmsRowRepeater, cmsRowRepeaterMeta);
2468
-
2173
+ _registerGlobalContext(CmsCredentialsProvider, cmsCredentialsProviderMeta);
2469
2174
 
2470
2175
  _registerComponent(CmsQueryRepeater, cmsQueryRepeaterMeta);
2471
2176
 
@@ -2475,27 +2180,20 @@ function registerAll(loader) {
2475
2180
 
2476
2181
  _registerComponent(CmsRowImage, cmsRowImageMeta);
2477
2182
 
2478
- _registerComponent(CmsRowFieldValue, cmsRowFieldValueMeta); // _registerComponent(CmsRowLoader, cmsRowLoaderMeta);
2479
-
2183
+ _registerComponent(CmsRowFieldValue, cmsRowFieldValueMeta);
2480
2184
  }
2481
2185
 
2482
2186
  exports.CmsCredentialsProvider = CmsCredentialsProvider;
2483
- exports.CmsQueryLoader = CmsQueryLoader;
2484
2187
  exports.CmsQueryRepeater = CmsQueryRepeater;
2485
2188
  exports.CmsRowField = CmsRowField;
2486
2189
  exports.CmsRowFieldValue = CmsRowFieldValue;
2487
2190
  exports.CmsRowImage = CmsRowImage;
2488
2191
  exports.CmsRowLink = CmsRowLink;
2489
- exports.CmsRowLoader = CmsRowLoader;
2490
- exports.CmsRowRepeater = CmsRowRepeater;
2491
2192
  exports.cmsCredentialsProviderMeta = cmsCredentialsProviderMeta;
2492
- exports.cmsQueryLoaderMeta = cmsQueryLoaderMeta;
2493
2193
  exports.cmsQueryRepeaterMeta = cmsQueryRepeaterMeta;
2494
2194
  exports.cmsRowFieldMeta = cmsRowFieldMeta;
2495
2195
  exports.cmsRowFieldValueMeta = cmsRowFieldValueMeta;
2496
2196
  exports.cmsRowImageMeta = cmsRowImageMeta;
2497
2197
  exports.cmsRowLinkMeta = cmsRowLinkMeta;
2498
- exports.cmsRowLoaderMeta = cmsRowLoaderMeta;
2499
- exports.cmsRowRepeaterMeta = cmsRowRepeaterMeta;
2500
2198
  exports.registerAll = registerAll;
2501
2199
  //# sourceMappingURL=plasmic-cms.cjs.development.js.map