@plasmicpkgs/plasmic-cms 0.0.70 → 0.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +0 -1
- package/dist/plasmic-cms.cjs.development.js +50 -82
- package/dist/plasmic-cms.cjs.development.js.map +1 -1
- package/dist/plasmic-cms.cjs.production.min.js +1 -1
- package/dist/plasmic-cms.cjs.production.min.js.map +1 -1
- package/dist/plasmic-cms.esm.js +11 -44
- package/dist/plasmic-cms.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/api.d.ts
CHANGED
|
@@ -22,7 +22,6 @@ declare class API {
|
|
|
22
22
|
get(endpoint: string, params?: {}): Promise<any>;
|
|
23
23
|
fetchTables(): Promise<ApiCmsTable[]>;
|
|
24
24
|
query(table: string, params: QueryParams): Promise<ApiCmsRow[]>;
|
|
25
|
-
fetchRow(table: string, row: string, useDraft: boolean): Promise<ApiCmsRow>;
|
|
26
25
|
}
|
|
27
26
|
export declare function mkApi(config: DatabaseConfig | undefined): API;
|
|
28
27
|
export {};
|
|
@@ -9,7 +9,8 @@ var registerGlobalContext = _interopDefault(require('@plasmicapp/host/registerGl
|
|
|
9
9
|
var host = require('@plasmicapp/host');
|
|
10
10
|
var query = require('@plasmicapp/query');
|
|
11
11
|
var dayjs = _interopDefault(require('dayjs'));
|
|
12
|
-
var React =
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var React__default = _interopDefault(React);
|
|
13
14
|
|
|
14
15
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
15
16
|
try {
|
|
@@ -1097,45 +1098,6 @@ var API = /*#__PURE__*/function () {
|
|
|
1097
1098
|
return query;
|
|
1098
1099
|
}();
|
|
1099
1100
|
|
|
1100
|
-
_proto.fetchRow = /*#__PURE__*/function () {
|
|
1101
|
-
var _fetchRow = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(table, row, useDraft) {
|
|
1102
|
-
var response;
|
|
1103
|
-
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1104
|
-
while (1) {
|
|
1105
|
-
switch (_context4.prev = _context4.next) {
|
|
1106
|
-
case 0:
|
|
1107
|
-
_context4.prev = 0;
|
|
1108
|
-
_context4.next = 3;
|
|
1109
|
-
return this.get("/tables/" + table + "/rows/" + row, {
|
|
1110
|
-
draft: Number(useDraft),
|
|
1111
|
-
locale: this.config.locale
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
case 3:
|
|
1115
|
-
response = _context4.sent;
|
|
1116
|
-
return _context4.abrupt("return", response);
|
|
1117
|
-
|
|
1118
|
-
case 7:
|
|
1119
|
-
_context4.prev = 7;
|
|
1120
|
-
_context4.t0 = _context4["catch"](0);
|
|
1121
|
-
console.error(_context4.t0);
|
|
1122
|
-
throw _context4.t0;
|
|
1123
|
-
|
|
1124
|
-
case 11:
|
|
1125
|
-
case "end":
|
|
1126
|
-
return _context4.stop();
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}, _callee4, this, [[0, 7]]);
|
|
1130
|
-
}));
|
|
1131
|
-
|
|
1132
|
-
function fetchRow(_x5, _x6, _x7) {
|
|
1133
|
-
return _fetchRow.apply(this, arguments);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
return fetchRow;
|
|
1137
|
-
}();
|
|
1138
|
-
|
|
1139
1101
|
return API;
|
|
1140
1102
|
}();
|
|
1141
1103
|
|
|
@@ -1168,7 +1130,7 @@ function useDatabase() {
|
|
|
1168
1130
|
function DatabaseProvider(_ref) {
|
|
1169
1131
|
var config = _ref.config,
|
|
1170
1132
|
children = _ref.children;
|
|
1171
|
-
return
|
|
1133
|
+
return React__default.createElement(host.DataProvider, {
|
|
1172
1134
|
name: databaseContextKey,
|
|
1173
1135
|
data: config
|
|
1174
1136
|
}, children);
|
|
@@ -1179,7 +1141,7 @@ function useTables() {
|
|
|
1179
1141
|
function TablesProvider(_ref2) {
|
|
1180
1142
|
var children = _ref2.children,
|
|
1181
1143
|
tables = _ref2.tables;
|
|
1182
|
-
return
|
|
1144
|
+
return React__default.createElement(host.DataProvider, {
|
|
1183
1145
|
name: tablesContextKey,
|
|
1184
1146
|
data: tables
|
|
1185
1147
|
}, children);
|
|
@@ -1195,7 +1157,7 @@ function QueryResultProvider(_ref3) {
|
|
|
1195
1157
|
var children = _ref3.children,
|
|
1196
1158
|
table = _ref3.table,
|
|
1197
1159
|
rows = _ref3.rows;
|
|
1198
|
-
return
|
|
1160
|
+
return React__default.createElement(host.DataProvider, {
|
|
1199
1161
|
name: mkQueryContextKey(table),
|
|
1200
1162
|
data: rows
|
|
1201
1163
|
}, children);
|
|
@@ -1243,7 +1205,7 @@ function RowProvider(_ref4) {
|
|
|
1243
1205
|
var children = _ref4.children,
|
|
1244
1206
|
table = _ref4.table,
|
|
1245
1207
|
row = _ref4.row;
|
|
1246
|
-
return
|
|
1208
|
+
return React__default.createElement(host.DataProvider, {
|
|
1247
1209
|
name: mkRowContextKey(table),
|
|
1248
1210
|
data: row
|
|
1249
1211
|
}, children);
|
|
@@ -1296,23 +1258,27 @@ var _excluded = ["children"],
|
|
|
1296
1258
|
var modulePath = "@plasmicpkgs/plasmic-cms";
|
|
1297
1259
|
var componentPrefix = "hostless-plasmic-cms";
|
|
1298
1260
|
|
|
1299
|
-
function renderMaybeData(maybeData, renderFn, loaderProps, loadingMessage, forceLoadingState) {
|
|
1261
|
+
function renderMaybeData(maybeData, renderFn, loaderProps, inEditor, loadingMessage, forceLoadingState) {
|
|
1300
1262
|
if ("error" in maybeData) {
|
|
1301
1263
|
var error = maybeData.error;
|
|
1302
1264
|
|
|
1265
|
+
if (!inEditor) {
|
|
1266
|
+
return React__default.createElement(React__default.Fragment, null, loadingMessage != null ? loadingMessage : React__default.createElement("div", null, "Loading..."));
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1303
1269
|
if (error && error instanceof HttpError && error.status === 404) {
|
|
1304
1270
|
if (loaderProps.hideIfNotFound) {
|
|
1305
1271
|
return null;
|
|
1306
1272
|
} else {
|
|
1307
|
-
return
|
|
1273
|
+
return React__default.createElement("div", null, "Error: Data not found");
|
|
1308
1274
|
}
|
|
1309
1275
|
} else {
|
|
1310
|
-
return
|
|
1276
|
+
return React__default.createElement("div", null, "Error: ", error == null ? void 0 : error.message);
|
|
1311
1277
|
}
|
|
1312
1278
|
}
|
|
1313
1279
|
|
|
1314
1280
|
if (!("data" in maybeData) || forceLoadingState) {
|
|
1315
|
-
return
|
|
1281
|
+
return React__default.createElement(React__default.Fragment, null, loadingMessage != null ? loadingMessage : React__default.createElement("div", null, "Loading..."));
|
|
1316
1282
|
}
|
|
1317
1283
|
|
|
1318
1284
|
return renderFn(maybeData.data);
|
|
@@ -1355,9 +1321,9 @@ function CmsCredentialsProvider(_ref) {
|
|
|
1355
1321
|
config = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1356
1322
|
|
|
1357
1323
|
config.host = config.host || defaultHost;
|
|
1358
|
-
return
|
|
1324
|
+
return React__default.createElement(DatabaseProvider, {
|
|
1359
1325
|
config: config
|
|
1360
|
-
},
|
|
1326
|
+
}, React__default.createElement(TablesFetcher, null, children));
|
|
1361
1327
|
}
|
|
1362
1328
|
|
|
1363
1329
|
function TablesFetcher(_ref2) {
|
|
@@ -1393,13 +1359,14 @@ function TablesFetcher(_ref2) {
|
|
|
1393
1359
|
}
|
|
1394
1360
|
}, _callee);
|
|
1395
1361
|
})));
|
|
1362
|
+
var inEditor = !!React.useContext(host.PlasmicCanvasContext);
|
|
1396
1363
|
return renderMaybeData(maybeData, function (tables) {
|
|
1397
|
-
return
|
|
1364
|
+
return React__default.createElement(TablesProvider, {
|
|
1398
1365
|
tables: tables
|
|
1399
1366
|
}, children);
|
|
1400
1367
|
}, {
|
|
1401
1368
|
hideIfNotFound: false
|
|
1402
|
-
}, children);
|
|
1369
|
+
}, inEditor, children);
|
|
1403
1370
|
}
|
|
1404
1371
|
|
|
1405
1372
|
function isDatabaseConfigured(config) {
|
|
@@ -1620,27 +1587,28 @@ function CmsQueryRepeater(_ref5) {
|
|
|
1620
1587
|
}
|
|
1621
1588
|
}, _callee2);
|
|
1622
1589
|
})));
|
|
1590
|
+
var inEditor = !!React.useContext(host.PlasmicCanvasContext);
|
|
1623
1591
|
var node = renderMaybeData(maybeData, function (rows) {
|
|
1624
1592
|
if (rows.length === 0 || forceEmptyState) {
|
|
1625
|
-
return
|
|
1593
|
+
return React__default.createElement(QueryResultProvider, {
|
|
1626
1594
|
table: table,
|
|
1627
1595
|
rows: rows
|
|
1628
1596
|
}, emptyMessage);
|
|
1629
1597
|
}
|
|
1630
1598
|
|
|
1631
|
-
return
|
|
1599
|
+
return React__default.createElement(QueryResultProvider, {
|
|
1632
1600
|
table: table,
|
|
1633
1601
|
rows: rows
|
|
1634
1602
|
}, rows.map(function (row, index) {
|
|
1635
|
-
return
|
|
1603
|
+
return React__default.createElement(RowProvider, {
|
|
1636
1604
|
table: table,
|
|
1637
1605
|
row: row
|
|
1638
1606
|
}, host.repeatedElement(index === 0, children));
|
|
1639
1607
|
}));
|
|
1640
1608
|
}, {
|
|
1641
1609
|
hideIfNotFound: false
|
|
1642
|
-
}, loadingMessage, forceLoadingState);
|
|
1643
|
-
return noLayout ?
|
|
1610
|
+
}, inEditor, loadingMessage, forceLoadingState);
|
|
1611
|
+
return noLayout ? React__default.createElement(React__default.Fragment, null, " ", node, " ") : React__default.createElement("div", {
|
|
1644
1612
|
className: className
|
|
1645
1613
|
}, " ", node, " ");
|
|
1646
1614
|
}
|
|
@@ -1762,7 +1730,7 @@ function CmsRowField(_ref9) {
|
|
|
1762
1730
|
|
|
1763
1731
|
var tables = useTablesWithDataLoaded();
|
|
1764
1732
|
var res = useRow(tables, table);
|
|
1765
|
-
var unknown =
|
|
1733
|
+
var unknown = React__default.createElement("div", Object.assign({
|
|
1766
1734
|
className: className
|
|
1767
1735
|
}, rest), "Field ", table != null ? table : "Unknown Model", ".", field != null ? field : "Unknown Field");
|
|
1768
1736
|
|
|
@@ -1771,7 +1739,7 @@ function CmsRowField(_ref9) {
|
|
|
1771
1739
|
}
|
|
1772
1740
|
|
|
1773
1741
|
if (!res.row) {
|
|
1774
|
-
return
|
|
1742
|
+
return React__default.createElement("div", {
|
|
1775
1743
|
className: className
|
|
1776
1744
|
}, "Error: No CMS Entry found");
|
|
1777
1745
|
}
|
|
@@ -1843,10 +1811,10 @@ function renderValue(value, type, props) {
|
|
|
1843
1811
|
case "text":
|
|
1844
1812
|
case "long-text":
|
|
1845
1813
|
case "date-time":
|
|
1846
|
-
return
|
|
1814
|
+
return React__default.createElement("div", Object.assign({}, props), value);
|
|
1847
1815
|
|
|
1848
1816
|
case "rich-text":
|
|
1849
|
-
return
|
|
1817
|
+
return React__default.createElement("div", Object.assign({
|
|
1850
1818
|
dangerouslySetInnerHTML: {
|
|
1851
1819
|
__html: value
|
|
1852
1820
|
}
|
|
@@ -1854,7 +1822,7 @@ function renderValue(value, type, props) {
|
|
|
1854
1822
|
|
|
1855
1823
|
case "image":
|
|
1856
1824
|
if (value && typeof value === "object" && value.url && value.imageMeta) {
|
|
1857
|
-
return
|
|
1825
|
+
return React__default.createElement("img", Object.assign({
|
|
1858
1826
|
src: value.url,
|
|
1859
1827
|
width: value.imageMeta.width,
|
|
1860
1828
|
height: value.imageMeta.height,
|
|
@@ -1868,7 +1836,7 @@ function renderValue(value, type, props) {
|
|
|
1868
1836
|
|
|
1869
1837
|
case "file":
|
|
1870
1838
|
if (value && typeof value === "object" && value.url && value.name) {
|
|
1871
|
-
return
|
|
1839
|
+
return React__default.createElement("a", Object.assign({
|
|
1872
1840
|
href: value.url,
|
|
1873
1841
|
target: "_blank"
|
|
1874
1842
|
}, props), value.name);
|
|
@@ -1964,7 +1932,7 @@ function CmsRowLink(_ref11) {
|
|
|
1964
1932
|
var res = useRow(tables, table);
|
|
1965
1933
|
|
|
1966
1934
|
if (!res || !res.row) {
|
|
1967
|
-
return
|
|
1935
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
1968
1936
|
}
|
|
1969
1937
|
|
|
1970
1938
|
var fieldMeta = deriveInferredTableField({
|
|
@@ -1985,7 +1953,7 @@ function CmsRowLink(_ref11) {
|
|
|
1985
1953
|
}
|
|
1986
1954
|
|
|
1987
1955
|
if (!fieldMeta) {
|
|
1988
|
-
return
|
|
1956
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
1989
1957
|
}
|
|
1990
1958
|
|
|
1991
1959
|
if (!children) {
|
|
@@ -1993,16 +1961,16 @@ function CmsRowLink(_ref11) {
|
|
|
1993
1961
|
}
|
|
1994
1962
|
|
|
1995
1963
|
var value = ((_res$row$data2 = res.row.data) == null ? void 0 : _res$row$data2[fieldMeta.identifier]) || "";
|
|
1996
|
-
var childrenWithProps =
|
|
1997
|
-
if (
|
|
1964
|
+
var childrenWithProps = React__default.Children.map(children, function (child) {
|
|
1965
|
+
if (React__default.isValidElement(child)) {
|
|
1998
1966
|
var _React$cloneElement;
|
|
1999
1967
|
|
|
2000
|
-
return
|
|
1968
|
+
return React__default.cloneElement(child, (_React$cloneElement = {}, _React$cloneElement[hrefProp] = fieldMeta.type === "file" ? value.url : prefix || suffix ? "" + (prefix || "") + value + (suffix || "") : value, _React$cloneElement));
|
|
2001
1969
|
}
|
|
2002
1970
|
|
|
2003
1971
|
return child;
|
|
2004
1972
|
});
|
|
2005
|
-
return
|
|
1973
|
+
return React__default.createElement(React__default.Fragment, null, childrenWithProps != null ? childrenWithProps : null);
|
|
2006
1974
|
}
|
|
2007
1975
|
var cmsRowImageMeta = {
|
|
2008
1976
|
name: componentPrefix + "-row-image",
|
|
@@ -2064,7 +2032,7 @@ function CmsRowImage(_ref13) {
|
|
|
2064
2032
|
var res = useRow(tables, table);
|
|
2065
2033
|
|
|
2066
2034
|
if (!res || !res.row) {
|
|
2067
|
-
return
|
|
2035
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
2068
2036
|
}
|
|
2069
2037
|
|
|
2070
2038
|
var fieldMeta = deriveInferredTableField({
|
|
@@ -2085,30 +2053,30 @@ function CmsRowImage(_ref13) {
|
|
|
2085
2053
|
}
|
|
2086
2054
|
|
|
2087
2055
|
if (!fieldMeta) {
|
|
2088
|
-
return
|
|
2056
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
2089
2057
|
}
|
|
2090
2058
|
|
|
2091
2059
|
var value = ((_res$row$data3 = res.row.data) == null ? void 0 : _res$row$data3[fieldMeta.identifier]) || "";
|
|
2092
|
-
var childrenWithProps =
|
|
2093
|
-
if (
|
|
2060
|
+
var childrenWithProps = React__default.Children.map(children, function (child) {
|
|
2061
|
+
if (React__default.isValidElement(child) && value) {
|
|
2094
2062
|
var _React$cloneElement3;
|
|
2095
2063
|
|
|
2096
2064
|
if (typeof value === "object" && value.url && value.imageMeta) {
|
|
2097
2065
|
var _React$cloneElement2;
|
|
2098
2066
|
|
|
2099
|
-
return
|
|
2067
|
+
return React__default.cloneElement(child, (_React$cloneElement2 = {}, _React$cloneElement2[srcProp] = {
|
|
2100
2068
|
src: value.url,
|
|
2101
2069
|
fullHeight: value.imageMeta.height,
|
|
2102
2070
|
fullWidth: value.imageMeta.width
|
|
2103
2071
|
}, _React$cloneElement2));
|
|
2104
2072
|
}
|
|
2105
2073
|
|
|
2106
|
-
return
|
|
2074
|
+
return React__default.cloneElement(child, (_React$cloneElement3 = {}, _React$cloneElement3[srcProp] = value, _React$cloneElement3));
|
|
2107
2075
|
}
|
|
2108
2076
|
|
|
2109
2077
|
return child;
|
|
2110
2078
|
});
|
|
2111
|
-
return
|
|
2079
|
+
return React__default.createElement(React__default.Fragment, null, childrenWithProps);
|
|
2112
2080
|
}
|
|
2113
2081
|
var cmsRowFieldValueMeta = {
|
|
2114
2082
|
name: componentPrefix + "-row-value",
|
|
@@ -2168,7 +2136,7 @@ function CmsRowFieldValue(_ref15) {
|
|
|
2168
2136
|
var res = useRow(tables, table);
|
|
2169
2137
|
|
|
2170
2138
|
if (!res || !res.row) {
|
|
2171
|
-
return
|
|
2139
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
2172
2140
|
}
|
|
2173
2141
|
|
|
2174
2142
|
var fieldMeta = deriveInferredTableField({
|
|
@@ -2189,20 +2157,20 @@ function CmsRowFieldValue(_ref15) {
|
|
|
2189
2157
|
}
|
|
2190
2158
|
|
|
2191
2159
|
if (!fieldMeta) {
|
|
2192
|
-
return
|
|
2160
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
|
2193
2161
|
}
|
|
2194
2162
|
|
|
2195
2163
|
var value = ((_res$row$data4 = res.row.data) == null ? void 0 : _res$row$data4[fieldMeta.identifier]) || "";
|
|
2196
|
-
var childrenWithProps =
|
|
2197
|
-
if (
|
|
2164
|
+
var childrenWithProps = React__default.Children.map(children, function (child) {
|
|
2165
|
+
if (React__default.isValidElement(child)) {
|
|
2198
2166
|
var _extends2;
|
|
2199
2167
|
|
|
2200
|
-
return
|
|
2168
|
+
return React__default.cloneElement(child, _extends({}, rest, (_extends2 = {}, _extends2[valueProp] = value, _extends2)));
|
|
2201
2169
|
}
|
|
2202
2170
|
|
|
2203
2171
|
return child;
|
|
2204
2172
|
});
|
|
2205
|
-
return
|
|
2173
|
+
return React__default.createElement(React__default.Fragment, null, childrenWithProps);
|
|
2206
2174
|
}
|
|
2207
2175
|
|
|
2208
2176
|
function registerAll(loader) {
|