@dotcms/react 1.2.5 → 1.2.6-next.1
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/README.md +71 -17
- package/_virtual/_commonjsHelpers.esm.js +3 -0
- package/_virtual/_style-inject.esm.js +30 -0
- package/_virtual/make-built-in.esm.js +3 -0
- package/_virtual/new-promise-capability.esm.js +3 -0
- package/_virtual/object-define-properties.esm.js +3 -0
- package/_virtual/object-define-property.esm.js +3 -0
- package/_virtual/object-get-own-property-descriptor.esm.js +3 -0
- package/_virtual/object-get-own-property-names.esm.js +3 -0
- package/_virtual/object-get-own-property-symbols.esm.js +3 -0
- package/_virtual/object-property-is-enumerable.esm.js +3 -0
- package/_virtual/shared-store.esm.js +3 -0
- package/index.esm.js +9 -7097
- package/index.server.d.ts +1 -0
- package/index.server.esm.js +8 -0
- package/libs/sdk/react/src/lib/next/components/Column/Column.esm.js +50 -0
- package/libs/sdk/react/src/lib/next/components/Column/Column.module.css.esm.js +8 -0
- package/libs/sdk/react/src/lib/next/components/Container/Container.esm.js +58 -0
- package/libs/sdk/react/src/lib/next/components/Container/ContainerFallbacks.esm.js +61 -0
- package/libs/sdk/react/src/lib/next/components/Contentlet/Contentlet.esm.js +88 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.esm.js +46 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.esm.js +182 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Code.esm.js +37 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.esm.js +47 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/GridBlock.esm.js +47 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Image.esm.js +22 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Lists.esm.js +43 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/NoComponentProvided.esm.js +40 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.esm.js +55 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Texts.esm.js +158 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Video.esm.js +43 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSEditableText/DotCMSEditableText.esm.js +190 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSEditableText/utils.esm.js +13 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.esm.js +44 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSLayoutBody/DotCMSPageProvider.esm.js +30 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.esm.js +43 -0
- package/libs/sdk/react/src/lib/next/components/DotCMSShow/DotCMSShow.esm.js +49 -0
- package/libs/sdk/react/src/lib/next/components/FallbackComponent/FallbackComponent.esm.js +55 -0
- package/libs/sdk/react/src/lib/next/components/Row/Row.esm.js +32 -0
- package/libs/sdk/react/src/lib/next/components/Row/Row.module.css.esm.js +8 -0
- package/libs/sdk/react/src/lib/next/contexts/DotCMSPageContext.esm.js +16 -0
- package/libs/sdk/react/src/lib/next/hooks/useAISearch.esm.js +131 -0
- package/libs/sdk/react/src/lib/next/hooks/useCheckVisibleContent.esm.js +42 -0
- package/libs/sdk/react/src/lib/next/hooks/useDotCMSShowWhen.esm.js +44 -0
- package/libs/sdk/react/src/lib/next/hooks/useEditableDotCMSPage.esm.js +133 -0
- package/libs/sdk/react/src/lib/next/hooks/useIsDevMode.esm.js +37 -0
- package/libs/sdk/react/src/lib/next/hooks/useStyleEditorSchemas.esm.js +15 -0
- package/libs/sdk/react/src/lib/next/utils/buildSlots.esm.js +46 -0
- package/package.json +3 -2
- package/src/index.d.ts +1 -0
- package/src/index.server.d.ts +11 -0
- package/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.d.ts +2 -1
- package/src/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.d.ts +2 -1
- package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.d.ts +2 -1
- package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/GridBlock.d.ts +19 -0
- package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +20 -1
- package/src/lib/next/components/DotCMSLayoutBody/DotCMSPageProvider.d.ts +18 -0
- package/src/lib/next/contexts/DotCMSPageContext.d.ts +3 -0
- package/src/lib/next/utils/buildSlots.d.ts +24 -0
package/README.md
CHANGED
|
@@ -210,24 +210,39 @@ All components and hooks should be imported from `@dotcms/react`:
|
|
|
210
210
|
| ------------ | ------------------------ | -------- | -------------- | ---------------------------------------------- |
|
|
211
211
|
| `page` | `DotCMSPageAsset` | ✅ | - | The page asset containing the layout to render |
|
|
212
212
|
| `components` | `DotCMSPageComponent` | ✅ | `{}` | [Map of content type → React component](#component-mapping) |
|
|
213
|
-
| `mode` | `DotCMSPageRendererMode` | ❌ |
|
|
213
|
+
| `mode` | `DotCMSPageRendererMode` | ❌ | `’production’` | [Rendering mode (‘production’ or ‘development’)](#layout-body-modes) |
|
|
214
|
+
| `slots` | `Record<string, ReactNode>` | ❌ | `{}` | Pre-rendered server component nodes keyed by contentlet identifier. See [`buildSlots`](#buildslots). |
|
|
214
215
|
|
|
215
|
-
####
|
|
216
|
+
#### Next.js App Router
|
|
216
217
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
`DotCMSLayoutBody` requires a `"use client"` parent because `components` is a map of React component functions, which React cannot serialize across the server→client boundary. The recommended pattern is to fetch data in the server page and pass the plain result to a client wrapper:
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
// page.tsx — server component, fetches data only
|
|
222
|
+
export default async function Page() {
|
|
223
|
+
const pageContent = await getDotCMSPage(path);
|
|
224
|
+
return <PageView pageContent={pageContent} />;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
// PageView.tsx — "use client", owns components and renders layout
|
|
230
|
+
‘use client’;
|
|
231
|
+
|
|
232
|
+
export function PageView({ pageContent }) {
|
|
233
|
+
const { pageAsset } = useEditableDotCMSPage(pageContent);
|
|
234
|
+
return <DotCMSLayoutBody page={pageAsset} components={pageComponents} />;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
222
237
|
|
|
223
238
|
#### Usage
|
|
224
239
|
|
|
225
240
|
```tsx
|
|
226
|
-
import type { DotCMSPageAsset } from
|
|
227
|
-
import { DotCMSLayoutBody } from
|
|
241
|
+
import type { DotCMSPageAsset } from ‘@dotcms/types’;
|
|
242
|
+
import { DotCMSLayoutBody } from ‘@dotcms/react’;
|
|
228
243
|
|
|
229
|
-
import { MyBlogCard } from
|
|
230
|
-
import { DotCMSProductComponent } from
|
|
244
|
+
import { MyBlogCard } from ‘./MyBlogCard’;
|
|
245
|
+
import { DotCMSProductComponent } from ‘./DotCMSProductComponent’;
|
|
231
246
|
|
|
232
247
|
const COMPONENTS_MAP = {
|
|
233
248
|
Blog: MyBlogCard,
|
|
@@ -239,6 +254,23 @@ const MyPage = ({ pageAsset }: DotCMSPageResponse) => {
|
|
|
239
254
|
};
|
|
240
255
|
```
|
|
241
256
|
|
|
257
|
+
#### buildSlots
|
|
258
|
+
|
|
259
|
+
Use `buildSlots` when you have Next.js async server components that need to fetch their own data. Since async server components can’t be called from inside a client component tree, pre-render them on the server and pass the result into the layout via `slots`:
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
import { buildSlots, DotCMSLayoutBody } from ‘@dotcms/react’;
|
|
263
|
+
|
|
264
|
+
// BlogListContainer is an async server component that fetches its own data
|
|
265
|
+
const slots = buildSlots(pageContent.pageAsset.containers, {
|
|
266
|
+
BlogList: BlogListContainer,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
<DotCMSLayoutBody page={pageAsset} components={pageComponents} slots={slots} />
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The layout renders the pre-rendered slot node for a contentlet if one exists, otherwise falls back to the matching entry in `components`.
|
|
273
|
+
|
|
242
274
|
#### Layout Body Modes
|
|
243
275
|
|
|
244
276
|
- `production`: Performance-optimized mode that only renders content with explicitly mapped components, leaving unmapped content empty.
|
|
@@ -313,12 +345,13 @@ export default MyBannerComponent;
|
|
|
313
345
|
|
|
314
346
|
`DotCMSBlockEditorRenderer` is a component for rendering [Block Editor](https://dev.dotcms.com/docs/block-editor) content from dotCMS with support for custom block renderers.
|
|
315
347
|
|
|
316
|
-
| Input | Type | Required | Description |
|
|
317
|
-
| ----------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
|
|
318
|
-
| `blocks` | `BlockEditorContent` | ✅ | The [Block Editor](https://dev.dotcms.com/docs/block-editor) content to render |
|
|
319
|
-
| `customRenderers` | `CustomRenderers` | ❌ | Custom rendering functions for specific [block types](https://dev.dotcms.com/docs/block-editor#BlockTypes) |
|
|
320
|
-
| `className` | `string` | ❌ | CSS class to apply to the container |
|
|
321
|
-
| `style` | `CSSProperties` | ❌ | Inline styles for the container |
|
|
348
|
+
| Input | Type | Required | Default | Description |
|
|
349
|
+
| ----------------- | -------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------- |
|
|
350
|
+
| `blocks` | `BlockEditorContent` | ✅ | - | The [Block Editor](https://dev.dotcms.com/docs/block-editor) content to render |
|
|
351
|
+
| `customRenderers` | `CustomRenderers` | ❌ | - | Custom rendering functions for specific [block types](https://dev.dotcms.com/docs/block-editor#BlockTypes) |
|
|
352
|
+
| `className` | `string` | ❌ | - | CSS class to apply to the container |
|
|
353
|
+
| `style` | `CSSProperties` | ❌ | - | Inline styles for the container |
|
|
354
|
+
| `isDevMode` | `boolean` | ❌ | `false` | When `true`, shows a visible error message if the `blocks` data is invalid. When `false` (default), invalid blocks render nothing silently. |
|
|
322
355
|
|
|
323
356
|
#### Usage
|
|
324
357
|
|
|
@@ -344,6 +377,27 @@ const DetailPage = ({ contentlet }: { contentlet: DotCMSBasicContentlet }) => {
|
|
|
344
377
|
};
|
|
345
378
|
```
|
|
346
379
|
|
|
380
|
+
#### Next.js Server Components
|
|
381
|
+
|
|
382
|
+
`DotCMSBlockEditorRenderer` can be used directly in a Next.js server component — it has no hooks or browser dependencies:
|
|
383
|
+
|
|
384
|
+
```tsx
|
|
385
|
+
// app/article/page.tsx — server component
|
|
386
|
+
import { DotCMSBlockEditorRenderer } from '@dotcms/react';
|
|
387
|
+
|
|
388
|
+
export default async function ArticlePage() {
|
|
389
|
+
const { pageAsset } = await getDotCMSPage('/article');
|
|
390
|
+
const blocks = pageAsset.containers['...'].contentlets[0].blockEditorContent;
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<DotCMSBlockEditorRenderer
|
|
394
|
+
blocks={blocks}
|
|
395
|
+
isDevMode={process.env.NODE_ENV === 'development'}
|
|
396
|
+
/>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
347
401
|
#### Recommendations
|
|
348
402
|
|
|
349
403
|
- Should not be used with [`DotCMSEditableText`](#dotcmseditabletext)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function styleInject(css, ref) {
|
|
2
|
+
if (ref === void 0) ref = {};
|
|
3
|
+
var insertAt = ref.insertAt;
|
|
4
|
+
|
|
5
|
+
if (typeof document === 'undefined') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
10
|
+
var style = document.createElement('style');
|
|
11
|
+
style.type = 'text/css';
|
|
12
|
+
|
|
13
|
+
if (insertAt === 'top') {
|
|
14
|
+
if (head.firstChild) {
|
|
15
|
+
head.insertBefore(style, head.firstChild);
|
|
16
|
+
} else {
|
|
17
|
+
head.appendChild(style);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
head.appendChild(style);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (style.styleSheet) {
|
|
24
|
+
style.styleSheet.cssText = css;
|
|
25
|
+
} else {
|
|
26
|
+
style.appendChild(document.createTextNode(css));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { styleInject as default, styleInject };
|