@dotcms/react 0.0.1-beta.30 → 0.0.1-beta.32
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
|
|
@@ -691,30 +695,31 @@ function DotCMSEditableText({
|
|
|
691
695
|
const [scriptSrc, setScriptSrc] = useState('');
|
|
692
696
|
const [initEditor, setInitEditor] = useState(false);
|
|
693
697
|
const [content, setContent] = useState((contentlet == null ? void 0 : contentlet[fieldName]) || '');
|
|
698
|
+
useEffect(() => {
|
|
699
|
+
setContent((contentlet == null ? void 0 : contentlet[fieldName]) || '');
|
|
700
|
+
}, [fieldName, contentlet]);
|
|
694
701
|
useEffect(() => {
|
|
695
702
|
var _state$dotCMSHost, _editorRef$current;
|
|
696
703
|
const state = getUVEState();
|
|
697
704
|
setInitEditor((state == null ? void 0 : state.mode) === UVE_MODE.EDIT && !!(state != null && (_state$dotCMSHost = state.dotCMSHost) != null && _state$dotCMSHost.length));
|
|
698
705
|
if (!contentlet || !fieldName) {
|
|
699
|
-
console.error('DotCMSEditableText: contentlet or fieldName is missing', 'Ensure that all needed props are passed to view and edit the content');
|
|
706
|
+
console.error('[DotCMSEditableText]: contentlet or fieldName is missing', 'Ensure that all needed props are passed to view and edit the content');
|
|
700
707
|
return;
|
|
701
708
|
}
|
|
702
709
|
if (state && state.mode !== UVE_MODE.EDIT) {
|
|
703
|
-
console.warn('DotCMSEditableText: TinyMCE is not available in the current mode');
|
|
710
|
+
console.warn('[DotCMSEditableText]: TinyMCE is not available in the current mode');
|
|
704
711
|
return;
|
|
705
712
|
}
|
|
706
713
|
if (!(state != null && state.dotCMSHost)) {
|
|
707
|
-
console.warn('The `dotCMSHost` parameter is not defined. Check that the UVE is sending the correct parameters.');
|
|
714
|
+
console.warn('[DotCMSEditableText]: The `dotCMSHost` parameter is not defined. Check that the UVE is sending the correct parameters.');
|
|
708
715
|
return;
|
|
709
716
|
}
|
|
710
717
|
const createURL = new URL(__TINYMCE_PATH_ON_DOTCMS__, state.dotCMSHost);
|
|
711
718
|
setScriptSrc(createURL.toString());
|
|
712
|
-
const content = (contentlet == null ? void 0 : contentlet[fieldName]) || '';
|
|
713
719
|
(_editorRef$current = editorRef.current) == null || _editorRef$current.setContent(content, {
|
|
714
720
|
format
|
|
715
721
|
});
|
|
716
|
-
|
|
717
|
-
}, [format, fieldName, contentlet]);
|
|
722
|
+
}, [format, fieldName, contentlet, content]);
|
|
718
723
|
useEffect(() => {
|
|
719
724
|
var _getUVEState;
|
|
720
725
|
if (((_getUVEState = getUVEState()) == null ? void 0 : _getUVEState.mode) !== UVE_MODE.EDIT) {
|
|
@@ -851,6 +856,45 @@ const BlockQuote = ({
|
|
|
851
856
|
});
|
|
852
857
|
};
|
|
853
858
|
|
|
859
|
+
const NoComponentProvided = ({
|
|
860
|
+
contentType
|
|
861
|
+
}) => {
|
|
862
|
+
const style = {
|
|
863
|
+
backgroundColor: '#fffaf0',
|
|
864
|
+
color: '#333',
|
|
865
|
+
padding: '1rem',
|
|
866
|
+
borderRadius: '0.5rem',
|
|
867
|
+
marginBottom: '1rem',
|
|
868
|
+
marginTop: '1rem',
|
|
869
|
+
border: '1px solid #ed8936'
|
|
870
|
+
};
|
|
871
|
+
return jsxs("div", {
|
|
872
|
+
"data-testid": "no-component-provided",
|
|
873
|
+
style: style,
|
|
874
|
+
children: [jsx("strong", {
|
|
875
|
+
style: {
|
|
876
|
+
color: '#c05621'
|
|
877
|
+
},
|
|
878
|
+
children: "Dev Warning"
|
|
879
|
+
}), ": No component or custom renderer provided for content type", jsx("strong", {
|
|
880
|
+
style: {
|
|
881
|
+
color: '#c05621'
|
|
882
|
+
},
|
|
883
|
+
children: contentType || 'Unknown'
|
|
884
|
+
}), ".", jsx("br", {}), "Please refer to the", jsx("a", {
|
|
885
|
+
href: "https://dev.dotcms.com/docs/block-editor",
|
|
886
|
+
target: "_blank",
|
|
887
|
+
rel: "noopener noreferrer",
|
|
888
|
+
style: {
|
|
889
|
+
color: '#c05621'
|
|
890
|
+
},
|
|
891
|
+
children: "Block Editor Custom Renderers Documentation"
|
|
892
|
+
}), ' ', "for guidance."]
|
|
893
|
+
});
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
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.';
|
|
897
|
+
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
898
|
/**
|
|
855
899
|
* Renders a DotContent component.
|
|
856
900
|
*
|
|
@@ -862,23 +906,29 @@ const DotContent = ({
|
|
|
862
906
|
node
|
|
863
907
|
}) => {
|
|
864
908
|
const isDevMode = useIsDevMode();
|
|
865
|
-
const
|
|
866
|
-
|
|
909
|
+
const {
|
|
910
|
+
attrs = {}
|
|
911
|
+
} = node;
|
|
912
|
+
const {
|
|
913
|
+
data
|
|
914
|
+
} = attrs;
|
|
867
915
|
if (!data) {
|
|
868
|
-
console.error(
|
|
916
|
+
console.error(DOT_CONTENT_NO_DATA_MESSAGE);
|
|
869
917
|
return null;
|
|
870
918
|
}
|
|
871
|
-
const
|
|
919
|
+
const {
|
|
920
|
+
contentType = 'Unknown Content Type'
|
|
921
|
+
} = data;
|
|
872
922
|
const Component = customRenderers[contentType];
|
|
873
|
-
|
|
923
|
+
/* In dev mode, show a helpful message for unknown content types */
|
|
874
924
|
if (isDevMode && !Component) {
|
|
875
|
-
return
|
|
876
|
-
|
|
925
|
+
return jsx(NoComponentProvided, {
|
|
926
|
+
contentType: contentType
|
|
877
927
|
});
|
|
878
928
|
}
|
|
879
|
-
|
|
929
|
+
/* In production, use default component if no matching component found */
|
|
880
930
|
if (!Component) {
|
|
881
|
-
console.
|
|
931
|
+
console.warn(DOT_CONTENT_NO_MATCHING_COMPONENT_MESSAGE(contentType));
|
|
882
932
|
return null;
|
|
883
933
|
}
|
|
884
934
|
return jsx(Component, Object.assign({}, node));
|
|
@@ -1203,6 +1253,7 @@ const BlockEditorBlock = ({
|
|
|
1203
1253
|
return content == null ? void 0 : content.map((node, index) => {
|
|
1204
1254
|
var _node$content;
|
|
1205
1255
|
const CustomRendererComponent = customRenderers == null ? void 0 : customRenderers[node.type];
|
|
1256
|
+
const key = `${node.type}-${index}`;
|
|
1206
1257
|
if (CustomRendererComponent) {
|
|
1207
1258
|
return jsx(CustomRendererComponent, {
|
|
1208
1259
|
content: node.content,
|
|
@@ -1210,7 +1261,7 @@ const BlockEditorBlock = ({
|
|
|
1210
1261
|
content: node.content,
|
|
1211
1262
|
customRenderers: customRenderers
|
|
1212
1263
|
})
|
|
1213
|
-
},
|
|
1264
|
+
}, key);
|
|
1214
1265
|
}
|
|
1215
1266
|
switch (node.type) {
|
|
1216
1267
|
case BlockEditorDefaultBlocks.PARAGRAPH:
|
|
@@ -1220,7 +1271,7 @@ const BlockEditorBlock = ({
|
|
|
1220
1271
|
content: node.content,
|
|
1221
1272
|
customRenderers: customRenderers
|
|
1222
1273
|
})
|
|
1223
|
-
},
|
|
1274
|
+
}, key);
|
|
1224
1275
|
case BlockEditorDefaultBlocks.HEADING:
|
|
1225
1276
|
return jsx(Heading, {
|
|
1226
1277
|
node: node,
|
|
@@ -1228,37 +1279,37 @@ const BlockEditorBlock = ({
|
|
|
1228
1279
|
content: node.content,
|
|
1229
1280
|
customRenderers: customRenderers
|
|
1230
1281
|
})
|
|
1231
|
-
},
|
|
1282
|
+
}, key);
|
|
1232
1283
|
case BlockEditorDefaultBlocks.TEXT:
|
|
1233
|
-
return jsx(TextBlock, Object.assign({}, node),
|
|
1284
|
+
return jsx(TextBlock, Object.assign({}, node), key);
|
|
1234
1285
|
case BlockEditorDefaultBlocks.BULLET_LIST:
|
|
1235
1286
|
return jsx(BulletList, {
|
|
1236
1287
|
children: jsx(BlockEditorBlock, {
|
|
1237
1288
|
content: node.content,
|
|
1238
1289
|
customRenderers: customRenderers
|
|
1239
1290
|
})
|
|
1240
|
-
},
|
|
1291
|
+
}, key);
|
|
1241
1292
|
case BlockEditorDefaultBlocks.ORDERED_LIST:
|
|
1242
1293
|
return jsx(OrderedList, {
|
|
1243
1294
|
children: jsx(BlockEditorBlock, {
|
|
1244
1295
|
content: node.content,
|
|
1245
1296
|
customRenderers: customRenderers
|
|
1246
1297
|
})
|
|
1247
|
-
},
|
|
1298
|
+
}, key);
|
|
1248
1299
|
case BlockEditorDefaultBlocks.LIST_ITEM:
|
|
1249
1300
|
return jsx(ListItem, {
|
|
1250
1301
|
children: jsx(BlockEditorBlock, {
|
|
1251
1302
|
content: node.content,
|
|
1252
1303
|
customRenderers: customRenderers
|
|
1253
1304
|
})
|
|
1254
|
-
},
|
|
1305
|
+
}, key);
|
|
1255
1306
|
case BlockEditorDefaultBlocks.BLOCK_QUOTE:
|
|
1256
1307
|
return jsx(BlockQuote, {
|
|
1257
1308
|
children: jsx(BlockEditorBlock, {
|
|
1258
1309
|
content: node.content,
|
|
1259
1310
|
customRenderers: customRenderers
|
|
1260
1311
|
})
|
|
1261
|
-
},
|
|
1312
|
+
}, key);
|
|
1262
1313
|
case BlockEditorDefaultBlocks.CODE_BLOCK:
|
|
1263
1314
|
return jsx(CodeBlock, {
|
|
1264
1315
|
node: node,
|
|
@@ -1266,36 +1317,74 @@ const BlockEditorBlock = ({
|
|
|
1266
1317
|
content: node.content,
|
|
1267
1318
|
customRenderers: customRenderers
|
|
1268
1319
|
})
|
|
1269
|
-
},
|
|
1320
|
+
}, key);
|
|
1270
1321
|
case BlockEditorDefaultBlocks.HARDBREAK:
|
|
1271
|
-
return jsx("br", {},
|
|
1322
|
+
return jsx("br", {}, key);
|
|
1272
1323
|
case BlockEditorDefaultBlocks.HORIZONTAL_RULE:
|
|
1273
|
-
return jsx("hr", {},
|
|
1324
|
+
return jsx("hr", {}, key);
|
|
1274
1325
|
case BlockEditorDefaultBlocks.DOT_IMAGE:
|
|
1275
1326
|
return jsx(DotCMSImage, {
|
|
1276
1327
|
node: node
|
|
1277
|
-
},
|
|
1328
|
+
}, key);
|
|
1278
1329
|
case BlockEditorDefaultBlocks.DOT_VIDEO:
|
|
1279
1330
|
return jsx(DotCMSVideo, {
|
|
1280
1331
|
node: node
|
|
1281
|
-
},
|
|
1332
|
+
}, key);
|
|
1282
1333
|
case BlockEditorDefaultBlocks.TABLE:
|
|
1283
1334
|
return jsx(TableRenderer, {
|
|
1284
1335
|
content: (_node$content = node.content) != null ? _node$content : [],
|
|
1285
1336
|
blockEditorItem: BlockEditorBlock
|
|
1286
|
-
},
|
|
1337
|
+
}, key);
|
|
1287
1338
|
case BlockEditorDefaultBlocks.DOT_CONTENT:
|
|
1288
1339
|
return jsx(DotContent, {
|
|
1289
1340
|
customRenderers: customRenderers,
|
|
1290
1341
|
node: node
|
|
1291
|
-
},
|
|
1342
|
+
}, key);
|
|
1292
1343
|
default:
|
|
1293
|
-
return
|
|
1294
|
-
|
|
1295
|
-
},
|
|
1344
|
+
return jsx(UnknownBlock, {
|
|
1345
|
+
node: node
|
|
1346
|
+
}, key);
|
|
1296
1347
|
}
|
|
1297
1348
|
});
|
|
1298
1349
|
};
|
|
1350
|
+
/**
|
|
1351
|
+
* Renders an unknown block type with a warning message in development mode.
|
|
1352
|
+
*
|
|
1353
|
+
* @param node - The block editor node to render.
|
|
1354
|
+
* @returns The rendered block or null if in production mode.
|
|
1355
|
+
*/
|
|
1356
|
+
const UnknownBlock = ({
|
|
1357
|
+
node
|
|
1358
|
+
}) => {
|
|
1359
|
+
const style = {
|
|
1360
|
+
backgroundColor: '#fff5f5',
|
|
1361
|
+
color: '#333',
|
|
1362
|
+
padding: '1rem',
|
|
1363
|
+
borderRadius: '0.5rem',
|
|
1364
|
+
marginBottom: '1rem',
|
|
1365
|
+
marginTop: '1rem',
|
|
1366
|
+
border: '1px solid #fc8181'
|
|
1367
|
+
};
|
|
1368
|
+
if (getUVEState()) {
|
|
1369
|
+
return jsxs("div", {
|
|
1370
|
+
style: style,
|
|
1371
|
+
children: [jsx("strong", {
|
|
1372
|
+
style: {
|
|
1373
|
+
color: '#c53030'
|
|
1374
|
+
},
|
|
1375
|
+
children: "Warning:"
|
|
1376
|
+
}), " The block type", ' ', jsx("strong", {
|
|
1377
|
+
children: node.type
|
|
1378
|
+
}), " is not recognized. Please check your", ' ', jsx("a", {
|
|
1379
|
+
href: "https://dev.dotcms.com/docs/block-editor",
|
|
1380
|
+
target: "_blank",
|
|
1381
|
+
rel: "noopener noreferrer",
|
|
1382
|
+
children: "configuration"
|
|
1383
|
+
}), ' ', "or contact support for assistance."]
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
return null;
|
|
1387
|
+
};
|
|
1299
1388
|
|
|
1300
1389
|
/**
|
|
1301
1390
|
* 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.
|
|
3
|
+
"version": "0.0.1-beta.32",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=18",
|
|
6
6
|
"react-dom": ">=18",
|
|
7
|
-
"@dotcms/client": "0.0.1-beta.
|
|
8
|
-
"@dotcms/uve": "0.0.1-beta.
|
|
7
|
+
"@dotcms/client": "0.0.1-beta.32",
|
|
8
|
+
"@dotcms/uve": "0.0.1-beta.32",
|
|
9
9
|
"@tinymce/tinymce-react": "^6.0.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
File without changes
|