@enonic/nextjs-adapter 3.1.0-B5 → 3.1.0

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.
Files changed (2) hide show
  1. package/README.md +25 -40
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -49,17 +49,23 @@ They are available at `@enonic/nextjs-adapter/server`
49
49
  Fetches the content/component by path with component queries optimization, page structure as well as runtime info calculation. This is the
50
50
  main method for querying content.
51
51
 
52
- | Argument | Description |
53
- |-----------|-------------------|
54
- | `path` | Path to content |
52
+ | Argument | Description |
53
+ |----------|-------------------|
55
54
  | `context` | Execution context |
56
55
 
57
56
  Usage:
58
57
 
59
58
  ```tsx
60
59
  import {fetchContent} from '@enonic/nextjs-adapter/server';
60
+ import {headers} from 'next/headers';
61
61
 
62
- const response = fetchContent('/path/to/content', context);
62
+ const context = {
63
+ contentPath: '/current/content/path',
64
+ locale: 'en',
65
+ headers: headers(),
66
+ };
67
+
68
+ const response = fetchContent(context);
63
69
  ```
64
70
 
65
71
  Response type:
@@ -193,7 +199,7 @@ Loads all content paths for all locales. Generally used for static site generati
193
199
 
194
200
  | Argument | Description |
195
201
  |----------|---------------------------------------------------|
196
- | `apiUrl` | Service API URL |
202
+ | `path` | Root content path |
197
203
  | `query` | Request and Next.js config options _(Optional)_ * |
198
204
  | `count` | Max result count _(Optional, defaults to 999)_ |
199
205
 
@@ -212,7 +218,7 @@ Usage:
212
218
  ```tsx
213
219
  import {fetchContentPathsForAllLocales} from '@enonic/nextjs-adapter/server';
214
220
 
215
- const contentPaths = fetchContentPathsForLocale('/', 'custom graphql query', 1001);
221
+ const contentPaths = fetchContentPathsForLocale('/site-name', 'custom graphql query', 1001);
216
222
  ```
217
223
 
218
224
  <br/>
@@ -224,7 +230,7 @@ Used by [fetchContentPathsForAllLocales()](#fetch-paths-for-all-locales)
224
230
 
225
231
  | Argument | Description |
226
232
  |-----------|-----------------------------------------------------------------------------------------------------|
227
- | `apiUrl` | Service API URL |
233
+ | `path` | Root content path |
228
234
  | `mapping` | [Mapping](#locale-mapping-type) locale to project |
229
235
  | `query` | Request and Next.js config options _(Optional, [default value here](#fetch-paths-for-all-locales))_ |
230
236
  | `count` | Max result count _(Optional, defaults to 999)_ |
@@ -290,8 +296,14 @@ Usage:
290
296
  import {useLocaleContext} from '@enonic/nextjs-adapter/client';
291
297
 
292
298
  export default function ClientSideComponent() {
293
- const {locale, localize} = useLocaleContext();
299
+ const {locale, localize, setLocale} = useLocaleContext();
300
+ console.log(`Current locale: ${locale}`);
301
+
294
302
  const localizedText = localize('text.key');
303
+
304
+ setLocale('en').then((dict) => {
305
+ console.log(`New locale: ${locale}`);
306
+ });
295
307
  // ...
296
308
  }
297
309
  ```
@@ -329,8 +341,7 @@ const urlRelativeToViewer = getUrl('/some/content/url', meta);
329
341
 
330
342
  #### <a id="get-asset"></a>`getAsset(url: string, meta: MetaData) => string`
331
343
 
332
- Converts a local asset URL to relative one for current viewer (Next.js/Enonic XP). It doesn't append locales unlike [getUrl()]
333
- (#get-url).
344
+ Converts a local asset URL to relative one for current viewer (Next.js/Enonic XP). It doesn't append locales unlike the [getUrl()](#get-url).
334
345
 
335
346
  > **INFO:** For your URLs to work both in Enonic XP and Next.js you need to:
336
347
  > 1. Use relative URL to local asset
@@ -380,7 +391,7 @@ const query = `query($path:ID!){
380
391
 
381
392
  #### `validateData(props: FetchContentResult) => void`
382
393
 
383
- Validates data returned by [fetchContent()](#fetch-content) method. Throws an error or notFound() if data is invalid.
394
+ Utility method to validate data returned by [fetchContent()](#fetch-content) method. Throws an error or notFound() if data is invalid. Also prevents shortcut content types from being rendered in preview/edit modes.
384
395
 
385
396
  | Argument | Description |
386
397
  |----------|-----------------------------|
@@ -638,10 +649,9 @@ const url = UrlProcessor.processSrcSet('<srcset value>', meta);
638
649
 
639
650
  #### `static setSiteKey(key: string): void`
640
651
 
641
- Sets the site key value that is needed for correct absolute URL processing. It is automatically done by `nextjs-adapter` so you don't
642
- have to do it.
652
+ > **DEPRECATED:** It is automatically done by `nextjs-adapter` now and have no effect.
643
653
 
644
- > **WARNING:** Overriding this value may result in wrong URL processing !
654
+ Sets the site key value that is needed for correct absolute URL processing.
645
655
 
646
656
  | Argument | Description |
647
657
  |----------|-------------|
@@ -944,9 +954,6 @@ enum XP_COMPONENT_TYPE { // Enum for XP component types
944
954
  // Sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
945
955
  const sanitizeGraphqlName = (text: string) => string;
946
956
 
947
- // Returns common part of 2 strings
948
- const commonChars = (s1?: string, s2?: string) => string;
949
-
950
957
  // Returns full content api URL with current project and branch appended
951
958
  const getContentApiUrl = (context: Context) => string;
952
959
  ```
@@ -959,8 +966,7 @@ They are located in `@enonic/nextjs-adapter/views` folder. Each view is a defaul
959
966
 
960
967
  #### `<MainView common="common" data="data" page="page" meta="meta">`
961
968
 
962
- The main view of the application. It accepts the result of [fetchContent](#fetch-content) method.
963
- Should be default export from your [next.js route](https://nextjs.org/docs/routing/introduction)
969
+ The main view of the application. It accepts the result of [fetchContent](#fetch-content) method and is intended to be used as a view for your [next.js route](https://nextjs.org/docs/routing/introduction)
964
970
 
965
971
  | Argument | Type | Description |
966
972
  |----------|-----------------------------------|-----------------------------|
@@ -1051,24 +1057,3 @@ import StaticContent from '@enonic/nextjs-adapter/views/StaticContent';
1051
1057
 
1052
1058
  <StaticContent condition={true} tag="div"> ...child elements... </StaticContent>
1053
1059
  ```
1054
-
1055
- ## Known problems
1056
-
1057
-
1058
- In some cases, when using in NextJS application, a build errors related to the JSX may appear, that state the following:
1059
-
1060
- ```
1061
- You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
1062
- ```
1063
-
1064
- To prevent these errors, it is necessary to transpile the library using something
1065
- like [`next-transpile-modules`](https://www.npmjs.com/package/next-transpile-modules).
1066
- Install it as dev dependency and call it explicitly from you NextJS config:
1067
-
1068
- `next.config.js`
1069
-
1070
- ```js
1071
- const withTM = require('next-transpile-modules')(['@enonic/nextjs-adapter']);
1072
-
1073
- module.exports = withTM({});
1074
- ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "3.1.0-B5",
3
+ "version": "3.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "index.js",
6
6
  "author": "Pavel Milkevich <pmi@enonic.com>",
@@ -50,7 +50,7 @@
50
50
  "test": "jest --no-cache --coverage"
51
51
  },
52
52
  "dependencies": {
53
- "@enonic/react-components": "^5.0.0-RC5",
53
+ "@enonic/react-components": "^5.0.0",
54
54
  "@formatjs/intl-localematcher": "^0.5.4",
55
55
  "gqlmin": "^0.2.2",
56
56
  "html-react-parser": "^5.1.18",