@dotcms/react 0.0.1-beta.30 → 0.0.1-beta.31

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/next.esm.js CHANGED
@@ -618,6 +618,10 @@ const useEditableDotCMSPage = pageResponse => {
618
618
  if (!getUVEState()) {
619
619
  return;
620
620
  }
621
+ if (!pageResponse) {
622
+ console.warn('[useEditableDotCMSPage]: No DotCMSPageResponse provided');
623
+ return;
624
+ }
621
625
  const pageURI = pageResponse == null || (_pageResponse$pageAss = pageResponse.pageAsset) == null || (_pageResponse$pageAss = _pageResponse$pageAss.page) == null ? void 0 : _pageResponse$pageAss.pageURI;
622
626
  const {
623
627
  destroyUVESubscriptions
@@ -851,6 +855,45 @@ const BlockQuote = ({
851
855
  });
852
856
  };
853
857
 
858
+ const NoComponentProvided = ({
859
+ contentType
860
+ }) => {
861
+ const style = {
862
+ backgroundColor: '#fffaf0',
863
+ color: '#333',
864
+ padding: '1rem',
865
+ borderRadius: '0.5rem',
866
+ marginBottom: '1rem',
867
+ marginTop: '1rem',
868
+ border: '1px solid #ed8936'
869
+ };
870
+ return jsxs("div", {
871
+ "data-testid": "no-component-provided",
872
+ style: style,
873
+ children: [jsx("strong", {
874
+ style: {
875
+ color: '#c05621'
876
+ },
877
+ children: "Dev Warning"
878
+ }), ": No component or custom renderer provided for content type", jsx("strong", {
879
+ style: {
880
+ color: '#c05621'
881
+ },
882
+ children: contentType || 'Unknown'
883
+ }), ".", jsx("br", {}), "Please refer to the", jsx("a", {
884
+ href: "https://dev.dotcms.com/docs/block-editor",
885
+ target: "_blank",
886
+ rel: "noopener noreferrer",
887
+ style: {
888
+ color: '#c05621'
889
+ },
890
+ children: "Block Editor Custom Renderers Documentation"
891
+ }), ' ', "for guidance."]
892
+ });
893
+ };
894
+
895
+ const DOT_CONTENT_NO_DATA_MESSAGE = '[DotCMSBlockEditorRenderer]: No data provided for Contentlet Block. Try to add a contentlet to the block editor. If the error persists, please contact the DotCMS support team.';
896
+ const DOT_CONTENT_NO_MATCHING_COMPONENT_MESSAGE = contentType => `[DotCMSBlockEditorRenderer]: No matching component found for content type: ${contentType}. Provide a custom renderer for this content type to fix this error.`;
854
897
  /**
855
898
  * Renders a DotContent component.
856
899
  *
@@ -862,23 +905,29 @@ const DotContent = ({
862
905
  node
863
906
  }) => {
864
907
  const isDevMode = useIsDevMode();
865
- const attrs = (node == null ? void 0 : node.attrs) || {};
866
- const data = attrs.data;
908
+ const {
909
+ attrs = {}
910
+ } = node;
911
+ const {
912
+ data
913
+ } = attrs;
867
914
  if (!data) {
868
- console.error('DotContent: No data provided');
915
+ console.error(DOT_CONTENT_NO_DATA_MESSAGE);
869
916
  return null;
870
917
  }
871
- const contentType = data.contentType || 'Unknown Content Type';
918
+ const {
919
+ contentType = 'Unknown Content Type'
920
+ } = data;
872
921
  const Component = customRenderers[contentType];
873
- // In dev mode, show a helpful message for unknown content types
922
+ /* In dev mode, show a helpful message for unknown content types */
874
923
  if (isDevMode && !Component) {
875
- return jsxs("div", {
876
- children: ["Unknown ContentType: ", contentType]
924
+ return jsx(NoComponentProvided, {
925
+ contentType: contentType
877
926
  });
878
927
  }
879
- // In production, use default component if no matching component found
928
+ /* In production, use default component if no matching component found */
880
929
  if (!Component) {
881
- console.error('DotContent: No matching component found for content type', contentType);
930
+ console.warn(DOT_CONTENT_NO_MATCHING_COMPONENT_MESSAGE(contentType));
882
931
  return null;
883
932
  }
884
933
  return jsx(Component, Object.assign({}, node));
@@ -1203,6 +1252,7 @@ const BlockEditorBlock = ({
1203
1252
  return content == null ? void 0 : content.map((node, index) => {
1204
1253
  var _node$content;
1205
1254
  const CustomRendererComponent = customRenderers == null ? void 0 : customRenderers[node.type];
1255
+ const key = `${node.type}-${index}`;
1206
1256
  if (CustomRendererComponent) {
1207
1257
  return jsx(CustomRendererComponent, {
1208
1258
  content: node.content,
@@ -1210,7 +1260,7 @@ const BlockEditorBlock = ({
1210
1260
  content: node.content,
1211
1261
  customRenderers: customRenderers
1212
1262
  })
1213
- }, `${node.type}-${index}`);
1263
+ }, key);
1214
1264
  }
1215
1265
  switch (node.type) {
1216
1266
  case BlockEditorDefaultBlocks.PARAGRAPH:
@@ -1220,7 +1270,7 @@ const BlockEditorBlock = ({
1220
1270
  content: node.content,
1221
1271
  customRenderers: customRenderers
1222
1272
  })
1223
- }, `${node.type}-${index}`);
1273
+ }, key);
1224
1274
  case BlockEditorDefaultBlocks.HEADING:
1225
1275
  return jsx(Heading, {
1226
1276
  node: node,
@@ -1228,37 +1278,37 @@ const BlockEditorBlock = ({
1228
1278
  content: node.content,
1229
1279
  customRenderers: customRenderers
1230
1280
  })
1231
- }, `${node.type}-${index}`);
1281
+ }, key);
1232
1282
  case BlockEditorDefaultBlocks.TEXT:
1233
- return jsx(TextBlock, Object.assign({}, node), `${node.type}-${index}`);
1283
+ return jsx(TextBlock, Object.assign({}, node), key);
1234
1284
  case BlockEditorDefaultBlocks.BULLET_LIST:
1235
1285
  return jsx(BulletList, {
1236
1286
  children: jsx(BlockEditorBlock, {
1237
1287
  content: node.content,
1238
1288
  customRenderers: customRenderers
1239
1289
  })
1240
- }, `${node.type}-${index}`);
1290
+ }, key);
1241
1291
  case BlockEditorDefaultBlocks.ORDERED_LIST:
1242
1292
  return jsx(OrderedList, {
1243
1293
  children: jsx(BlockEditorBlock, {
1244
1294
  content: node.content,
1245
1295
  customRenderers: customRenderers
1246
1296
  })
1247
- }, `${node.type}-${index}`);
1297
+ }, key);
1248
1298
  case BlockEditorDefaultBlocks.LIST_ITEM:
1249
1299
  return jsx(ListItem, {
1250
1300
  children: jsx(BlockEditorBlock, {
1251
1301
  content: node.content,
1252
1302
  customRenderers: customRenderers
1253
1303
  })
1254
- }, `${node.type}-${index}`);
1304
+ }, key);
1255
1305
  case BlockEditorDefaultBlocks.BLOCK_QUOTE:
1256
1306
  return jsx(BlockQuote, {
1257
1307
  children: jsx(BlockEditorBlock, {
1258
1308
  content: node.content,
1259
1309
  customRenderers: customRenderers
1260
1310
  })
1261
- }, `${node.type}-${index}`);
1311
+ }, key);
1262
1312
  case BlockEditorDefaultBlocks.CODE_BLOCK:
1263
1313
  return jsx(CodeBlock, {
1264
1314
  node: node,
@@ -1266,36 +1316,74 @@ const BlockEditorBlock = ({
1266
1316
  content: node.content,
1267
1317
  customRenderers: customRenderers
1268
1318
  })
1269
- }, `${node.type}-${index}`);
1319
+ }, key);
1270
1320
  case BlockEditorDefaultBlocks.HARDBREAK:
1271
- return jsx("br", {}, `${node.type}-${index}`);
1321
+ return jsx("br", {}, key);
1272
1322
  case BlockEditorDefaultBlocks.HORIZONTAL_RULE:
1273
- return jsx("hr", {}, `${node.type}-${index}`);
1323
+ return jsx("hr", {}, key);
1274
1324
  case BlockEditorDefaultBlocks.DOT_IMAGE:
1275
1325
  return jsx(DotCMSImage, {
1276
1326
  node: node
1277
- }, `${node.type}-${index}`);
1327
+ }, key);
1278
1328
  case BlockEditorDefaultBlocks.DOT_VIDEO:
1279
1329
  return jsx(DotCMSVideo, {
1280
1330
  node: node
1281
- }, `${node.type}-${index}`);
1331
+ }, key);
1282
1332
  case BlockEditorDefaultBlocks.TABLE:
1283
1333
  return jsx(TableRenderer, {
1284
1334
  content: (_node$content = node.content) != null ? _node$content : [],
1285
1335
  blockEditorItem: BlockEditorBlock
1286
- }, `${node.type}-${index}`);
1336
+ }, key);
1287
1337
  case BlockEditorDefaultBlocks.DOT_CONTENT:
1288
1338
  return jsx(DotContent, {
1289
1339
  customRenderers: customRenderers,
1290
1340
  node: node
1291
- }, `${node.type}-${index}`);
1341
+ }, key);
1292
1342
  default:
1293
- return jsxs("div", {
1294
- children: ["Unknown Block Type ", node.type]
1295
- }, `${node.type}-${index}`);
1343
+ return jsx(UnknownBlock, {
1344
+ node: node
1345
+ }, key);
1296
1346
  }
1297
1347
  });
1298
1348
  };
1349
+ /**
1350
+ * Renders an unknown block type with a warning message in development mode.
1351
+ *
1352
+ * @param node - The block editor node to render.
1353
+ * @returns The rendered block or null if in production mode.
1354
+ */
1355
+ const UnknownBlock = ({
1356
+ node
1357
+ }) => {
1358
+ const style = {
1359
+ backgroundColor: '#fff5f5',
1360
+ color: '#333',
1361
+ padding: '1rem',
1362
+ borderRadius: '0.5rem',
1363
+ marginBottom: '1rem',
1364
+ marginTop: '1rem',
1365
+ border: '1px solid #fc8181'
1366
+ };
1367
+ if (getUVEState()) {
1368
+ return jsxs("div", {
1369
+ style: style,
1370
+ children: [jsx("strong", {
1371
+ style: {
1372
+ color: '#c53030'
1373
+ },
1374
+ children: "Warning:"
1375
+ }), " The block type", ' ', jsx("strong", {
1376
+ children: node.type
1377
+ }), " is not recognized. Please check your", ' ', jsx("a", {
1378
+ href: "https://dev.dotcms.com/docs/block-editor",
1379
+ target: "_blank",
1380
+ rel: "noopener noreferrer",
1381
+ children: "configuration"
1382
+ }), ' ', "or contact support for assistance."]
1383
+ });
1384
+ }
1385
+ return null;
1386
+ };
1299
1387
 
1300
1388
  /**
1301
1389
  * BlockEditorRenderer component for rendering block editor field.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dotcms/react",
3
- "version": "0.0.1-beta.30",
3
+ "version": "0.0.1-beta.31",
4
4
  "peerDependencies": {
5
5
  "react": ">=18",
6
6
  "react-dom": ">=18",
7
- "@dotcms/client": "0.0.1-beta.30",
8
- "@dotcms/uve": "0.0.1-beta.30",
7
+ "@dotcms/client": "0.0.1-beta.31",
8
+ "@dotcms/uve": "0.0.1-beta.31",
9
9
  "@tinymce/tinymce-react": "^6.0.0"
10
10
  },
11
11
  "devDependencies": {
@@ -0,0 +1,3 @@
1
+ export declare const NoComponentProvided: ({ contentType }: {
2
+ contentType: string;
3
+ }) => import("react/jsx-runtime").JSX.Element;