@enonic/nextjs-adapter 4.0.0 → 5.0.0-beta.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 +155 -129
- package/dist/common/UrlProcessor.d.ts +2 -8
- package/dist/common/UrlProcessor.js +33 -90
- package/dist/common/UrlProcessor.js.map +1 -1
- package/dist/common/constants.d.ts +2 -1
- package/dist/common/constants.js +26 -25
- package/dist/common/constants.js.map +1 -1
- package/dist/guillotine/buildErrorResponse.d.ts +1 -1
- package/dist/guillotine/buildErrorResponse.js +4 -2
- package/dist/guillotine/buildErrorResponse.js.map +1 -1
- package/dist/guillotine/collectComponentDescriptors.d.ts +5 -3
- package/dist/guillotine/collectComponentDescriptors.js +5 -3
- package/dist/guillotine/collectComponentDescriptors.js.map +1 -1
- package/dist/guillotine/combineMultipleQueries.js +22 -13
- package/dist/guillotine/combineMultipleQueries.js.map +1 -1
- package/dist/guillotine/createMetaData.d.ts +4 -2
- package/dist/guillotine/createMetaData.js +4 -2
- package/dist/guillotine/createMetaData.js.map +1 -1
- package/dist/guillotine/fetchContent.js +27 -17
- package/dist/guillotine/fetchContent.js.map +1 -1
- package/dist/guillotine/fetchContentData.d.ts +1 -1
- package/dist/guillotine/fetchContentData.js +12 -4
- package/dist/guillotine/fetchContentData.js.map +1 -1
- package/dist/guillotine/fetchContentPathsForAllLocales.d.ts +1 -1
- package/dist/guillotine/fetchContentPathsForAllLocales.js +3 -3
- package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -1
- package/dist/guillotine/fetchContentPathsForLocale.d.ts +1 -1
- package/dist/guillotine/fetchContentPathsForLocale.js +13 -13
- package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -1
- package/dist/guillotine/fetchFromApi.d.ts +2 -2
- package/dist/guillotine/fetchFromApi.js +3 -5
- package/dist/guillotine/fetchFromApi.js.map +1 -1
- package/dist/guillotine/fetchGuillotine.d.ts +2 -2
- package/dist/guillotine/fetchGuillotine.js +2 -2
- package/dist/guillotine/fetchGuillotine.js.map +1 -1
- package/dist/guillotine/fetchMetaData.d.ts +1 -1
- package/dist/guillotine/fetchMetaData.js +6 -3
- package/dist/guillotine/fetchMetaData.js.map +1 -1
- package/dist/guillotine/getMetaData.d.ts +2 -0
- package/dist/guillotine/getMetaData.js +17 -10
- package/dist/guillotine/getMetaData.js.map +1 -1
- package/dist/guillotine/getQueryAndVariables.d.ts +2 -2
- package/dist/guillotine/getQueryAndVariables.js +12 -5
- package/dist/guillotine/getQueryAndVariables.js.map +1 -1
- package/dist/guillotine/{getCleanContentPathArrayOrThrow400.d.ts → getSiteRelativePathOrThrow.d.ts} +1 -1
- package/dist/guillotine/{getCleanContentPathArrayOrThrow400.js → getSiteRelativePathOrThrow.js} +2 -2
- package/dist/guillotine/getSiteRelativePathOrThrow.js.map +1 -0
- package/dist/guillotine/metadata/richTextQuery.js +1 -0
- package/dist/guillotine/metadata/richTextQuery.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/query/Shortcut.d.ts +1 -1
- package/dist/query/Shortcut.js +11 -15
- package/dist/query/Shortcut.js.map +1 -1
- package/dist/types/component.d.ts +9 -6
- package/dist/types/componentProps.d.ts +4 -4
- package/dist/utils/decryptParams.d.ts +1 -0
- package/dist/utils/decryptParams.js +20 -0
- package/dist/utils/decryptParams.js.map +1 -0
- package/dist/utils/encryptParams.d.ts +1 -0
- package/dist/utils/encryptParams.js +12 -0
- package/dist/utils/encryptParams.js.map +1 -0
- package/dist/utils/fixDoubleSlashes.d.ts +3 -0
- package/dist/utils/fixDoubleSlashes.js +9 -0
- package/dist/utils/fixDoubleSlashes.js.map +1 -1
- package/dist/utils/getContentBranch.d.ts +2 -0
- package/dist/utils/getContentBranch.js +11 -0
- package/dist/utils/getContentBranch.js.map +1 -0
- package/dist/utils/getRenderMode.d.ts +1 -1
- package/dist/utils/getRenderMode.js +1 -1
- package/dist/utils/getRenderMode.js.map +1 -1
- package/dist/views/BaseMacro.jsx +1 -30
- package/dist/views/BaseMacro.jsx.map +1 -1
- package/dist/views/RichTextView.jsx +8 -8
- package/dist/views/RichTextView.jsx.map +1 -1
- package/dist/views/Text.jsx +1 -1
- package/dist/views/Text.jsx.map +1 -1
- package/package.json +16 -16
- package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +0 -1
- package/dist/utils/getContentApiUrl.d.ts +0 -2
- package/dist/utils/getContentApiUrl.js +0 -15
- package/dist/utils/getContentApiUrl.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ import {fetchContent} from "@enonic/nextjs-adapter/server";
|
|
|
27
27
|
import MainView from "@enonic/nextjs-adapter/views/MainView"
|
|
28
28
|
|
|
29
29
|
// ...
|
|
30
|
-
const props = await fetchContent(
|
|
30
|
+
const props = await fetchContent({
|
|
31
31
|
contentPath: '/content/path',
|
|
32
32
|
locale: 'en',
|
|
33
33
|
});
|
|
@@ -44,13 +44,13 @@ They are available at `@enonic/nextjs-adapter/server`
|
|
|
44
44
|
|
|
45
45
|
<br/>
|
|
46
46
|
|
|
47
|
-
#### <a id="fetch-content"></a>`fetchContent(
|
|
47
|
+
#### <a id="fetch-content"></a>`fetchContent(context: Context) => Promise<FetchContentResult>`
|
|
48
48
|
|
|
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
|
|
53
|
-
|
|
52
|
+
| Argument | Description |
|
|
53
|
+
|-----------|-------------------|
|
|
54
54
|
| `context` | Execution context |
|
|
55
55
|
|
|
56
56
|
Usage:
|
|
@@ -85,28 +85,22 @@ type FetchContentResult = {
|
|
|
85
85
|
|
|
86
86
|
<br/>
|
|
87
87
|
|
|
88
|
-
#### <a id="fetch-guillotine"></a>`fetchGuillotine(
|
|
88
|
+
#### <a id="fetch-guillotine"></a>`fetchGuillotine(contentApiUrl: string, options?: FetchOptions) => Promise<GuillotineResult>`
|
|
89
89
|
|
|
90
90
|
Makes a custom request to Guillotine. Used by [fetchContent()](#fetch-content) method.
|
|
91
91
|
|
|
92
|
-
| Argument
|
|
93
|
-
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `options` | Request and Next.js config options _(Optional)_ |
|
|
92
|
+
| Argument | Description |
|
|
93
|
+
|-----------------|-------------------------------------------------|
|
|
94
|
+
| `contentApiUrl` | Guillotine API URL |
|
|
95
|
+
| `options` | Request and Next.js config options _(Optional)_ |
|
|
97
96
|
|
|
98
97
|
Usage:
|
|
99
98
|
|
|
100
99
|
```tsx
|
|
101
100
|
import {fetchGuillotine} from '@enonic/nextjs-adapter/server';
|
|
102
|
-
import {getLocaleMapping} from '@enonic/nextjs-adapter';
|
|
103
101
|
|
|
104
102
|
const apiUrl = 'http://domain:8000/graphql/api';
|
|
105
103
|
|
|
106
|
-
const mapping = getLocaleMapping({
|
|
107
|
-
contentPath: '/current/content/path',
|
|
108
|
-
});
|
|
109
|
-
|
|
110
104
|
const body = {
|
|
111
105
|
query: 'qraphql query as string',
|
|
112
106
|
variables: {
|
|
@@ -128,7 +122,7 @@ const opts = {
|
|
|
128
122
|
}
|
|
129
123
|
};
|
|
130
124
|
|
|
131
|
-
const result = fetchGuillotine(apiUrl,
|
|
125
|
+
const result = fetchGuillotine(apiUrl, opts);
|
|
132
126
|
```
|
|
133
127
|
|
|
134
128
|
Response type:
|
|
@@ -145,28 +139,22 @@ type GuillotineResult = {
|
|
|
145
139
|
|
|
146
140
|
<br/>
|
|
147
141
|
|
|
148
|
-
#### `fetchFromApi(apiUrl: string,
|
|
142
|
+
#### `fetchFromApi(apiUrl: string, options?: FetchOptions) => Promise<GuillotineResponseJson>`
|
|
149
143
|
|
|
150
144
|
Makes custom third-party service request. Used by the [fetchGuillotine()](#fetch-guillotine) method.
|
|
151
145
|
|
|
152
|
-
| Argument | Description
|
|
153
|
-
|
|
154
|
-
| `apiUrl` | Service API URL
|
|
155
|
-
| `
|
|
156
|
-
| `options` | Request and Next.js config options _(Optional)_ |
|
|
146
|
+
| Argument | Description |
|
|
147
|
+
|-----------|-------------------------------------------------|
|
|
148
|
+
| `apiUrl` | Service API URL |
|
|
149
|
+
| `options` | Request and Next.js config options _(Optional)_ |
|
|
157
150
|
|
|
158
151
|
Usage:
|
|
159
152
|
|
|
160
153
|
```tsx
|
|
161
154
|
import {fetchFromApi} from '@enonic/nextjs-adapter/server';
|
|
162
|
-
import {getLocaleMapping} from '@enonic/nextjs-adapter';
|
|
163
155
|
|
|
164
156
|
const apiUrl = 'http://domain:8000/graphql/api';
|
|
165
157
|
|
|
166
|
-
const mapping = getLocaleMapping({
|
|
167
|
-
contentPath: '/current/content/path',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
158
|
const body = {
|
|
171
159
|
query: 'qraphql query as string',
|
|
172
160
|
variables: {
|
|
@@ -188,22 +176,22 @@ const opts = {
|
|
|
188
176
|
}
|
|
189
177
|
};
|
|
190
178
|
|
|
191
|
-
const result = fetchFromApi(apiUrl,
|
|
179
|
+
const result = fetchFromApi(apiUrl, opts);
|
|
192
180
|
```
|
|
193
181
|
|
|
194
182
|
<br/>
|
|
195
183
|
|
|
196
|
-
#### <a id="fetch-paths-for-all-locales"></a
|
|
184
|
+
#### <a id="fetch-paths-for-all-locales"></a>
|
|
185
|
+
`fetchContentPathsForAllLocales(query?: string, countPerLocale?: number) => Promise<ContentPathItem[]>`
|
|
197
186
|
|
|
198
187
|
Loads all content paths for all locales. Generally used for static site generation.
|
|
199
188
|
|
|
200
|
-
| Argument
|
|
201
|
-
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `count` | Max result count _(Optional, defaults to 999)_ |
|
|
189
|
+
| Argument | Description |
|
|
190
|
+
|------------------|-----------------------------------------------------------|
|
|
191
|
+
| `query` | Custom GraphQL query _(Optional)_ * |
|
|
192
|
+
| `countPerLocale` | Max result count per locale _(Optional, defaults to 999)_ |
|
|
205
193
|
|
|
206
|
-
* Default query gets up to `
|
|
194
|
+
* Default query gets up to `countPerLocale` results, sorts them by `modifiedTime` and excludes following content types:
|
|
207
195
|
|
|
208
196
|
```
|
|
209
197
|
"base:shortcut",
|
|
@@ -218,22 +206,21 @@ Usage:
|
|
|
218
206
|
```tsx
|
|
219
207
|
import {fetchContentPathsForAllLocales} from '@enonic/nextjs-adapter/server';
|
|
220
208
|
|
|
221
|
-
const contentPaths =
|
|
209
|
+
const contentPaths = fetchContentPathsForAllLocales('custom graphql query', 1001);
|
|
222
210
|
```
|
|
223
211
|
|
|
224
212
|
<br/>
|
|
225
213
|
|
|
226
|
-
#### `fetchContentPathsForLocale(
|
|
214
|
+
#### `fetchContentPathsForLocale(mapping: LocaleMapping, query?: string, count?: number) => Promise<ContentPathItem[]>`
|
|
227
215
|
|
|
228
216
|
Loads all content paths for the current locale. Generally used for static site generation.
|
|
229
217
|
Used by [fetchContentPathsForAllLocales()](#fetch-paths-for-all-locales)
|
|
230
218
|
|
|
231
|
-
| Argument | Description
|
|
232
|
-
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `
|
|
236
|
-
| `count` | Max result count _(Optional, defaults to 999)_ |
|
|
219
|
+
| Argument | Description |
|
|
220
|
+
|-----------|---------------------------------------------------------------------------------------|
|
|
221
|
+
| `mapping` | [Mapping](#locale-mapping-type) locale to project |
|
|
222
|
+
| `query` | Custom GraphQL query _(Optional, [default value here](#fetch-paths-for-all-locales))_ |
|
|
223
|
+
| `count` | Max result count _(Optional, defaults to 999)_ |
|
|
237
224
|
|
|
238
225
|
Usage:
|
|
239
226
|
|
|
@@ -245,7 +232,7 @@ const mapping = getLocaleMapping({
|
|
|
245
232
|
contentPath: '/current/content/path',
|
|
246
233
|
});
|
|
247
234
|
|
|
248
|
-
const contentPaths = fetchContentPathsForLocale(
|
|
235
|
+
const contentPaths = fetchContentPathsForLocale(mapping, 'custom graphql query', 1001);
|
|
249
236
|
```
|
|
250
237
|
|
|
251
238
|
<br/>
|
|
@@ -339,29 +326,6 @@ const urlRelativeToViewer = getUrl('/some/content/url', meta);
|
|
|
339
326
|
|
|
340
327
|
<br/>
|
|
341
328
|
|
|
342
|
-
#### <a id="get-asset"></a>`getAsset(url: string, meta: MetaData) => string`
|
|
343
|
-
|
|
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).
|
|
345
|
-
|
|
346
|
-
> **INFO:** For your URLs to work both in Enonic XP and Next.js you need to:
|
|
347
|
-
> 1. Use relative URL to local asset
|
|
348
|
-
> 2. Wrap them with `getAsset()` function in the views
|
|
349
|
-
|
|
350
|
-
| Argument | Description |
|
|
351
|
-
|----------|---------------------------------------------------------|
|
|
352
|
-
| `url` | asset URL you want to transform |
|
|
353
|
-
| `meta` | Runtime data returned by [fetchContent](#fetch-content) |
|
|
354
|
-
|
|
355
|
-
Usage:
|
|
356
|
-
|
|
357
|
-
```tsx
|
|
358
|
-
import {getAsset} from '@enonic/nextjs-adapter';
|
|
359
|
-
|
|
360
|
-
const urlRelativeToViewer = getAsset('/some/asset/url', meta);
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
<br/>
|
|
364
|
-
|
|
365
329
|
#### <a id="rich-text-query"></a>`richTextQuery(fieldName: string) => string`
|
|
366
330
|
|
|
367
331
|
This is a utility function for querying for `RichTextData` needed for [RichTextView](#rich-text-view). It creates a graphql query string for
|
|
@@ -391,7 +355,8 @@ const query = `query($path:ID!){
|
|
|
391
355
|
|
|
392
356
|
#### `validateData(props: FetchContentResult) => void`
|
|
393
357
|
|
|
394
|
-
Utility method to validate data returned by [fetchContent()](#fetch-content) method. Throws an error or notFound() if data
|
|
358
|
+
Utility method to validate data returned by [fetchContent()](#fetch-content) method. Throws an error or calls Next.js `notFound()` if data
|
|
359
|
+
is invalid. Also prevents shortcut content types from being rendered in preview/edit modes.
|
|
395
360
|
|
|
396
361
|
| Argument | Description |
|
|
397
362
|
|----------|-----------------------------|
|
|
@@ -403,7 +368,7 @@ Usage:
|
|
|
403
368
|
import {fetchContent} from '@enonic/nextjs-adapter/server';
|
|
404
369
|
import {validateData} from '@enonic/nextjs-adapter';
|
|
405
370
|
|
|
406
|
-
const data = fetchContent({
|
|
371
|
+
const data = await fetchContent({
|
|
407
372
|
contentPath: '/path/to/content',
|
|
408
373
|
locale: 'en',
|
|
409
374
|
});
|
|
@@ -413,6 +378,71 @@ validateData(data);
|
|
|
413
378
|
|
|
414
379
|
<br/>
|
|
415
380
|
|
|
381
|
+
#### <a id="get-content-branch"></a>`getContentBranch(context?: Context) => string`
|
|
382
|
+
|
|
383
|
+
Resolves the Enonic XP branch (`master` or `draft`) for the current request based on its render mode.
|
|
384
|
+
Returns `master` for `LIVE` and `NEXT` render modes, and `draft` otherwise (e.g. `EDIT`, `PREVIEW`, `INLINE`).
|
|
385
|
+
|
|
386
|
+
| Argument | Description |
|
|
387
|
+
|-----------|-------------------------------|
|
|
388
|
+
| `context` | `Context` object _(Optional)_ |
|
|
389
|
+
|
|
390
|
+
Usage:
|
|
391
|
+
|
|
392
|
+
```tsx
|
|
393
|
+
import {getContentBranch} from '@enonic/nextjs-adapter';
|
|
394
|
+
|
|
395
|
+
const branch = getContentBranch({
|
|
396
|
+
contentPath: '/current/content/path',
|
|
397
|
+
locale: 'en',
|
|
398
|
+
});
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
<br/>
|
|
402
|
+
|
|
403
|
+
#### <a id="encrypt-params"></a>`encryptParams(params: Record<string, any>, secret: string) => string`
|
|
404
|
+
|
|
405
|
+
Symmetrically encrypts a params object into a base64url string using AES-256-GCM. The `secret` is hashed with SHA-256
|
|
406
|
+
to derive the key, so any string length works. Pair with [decryptParams()](#decrypt-params) to read the value back.
|
|
407
|
+
|
|
408
|
+
| Argument | Description |
|
|
409
|
+
|----------|-------------------------------------------------|
|
|
410
|
+
| `params` | Plain object to encrypt |
|
|
411
|
+
| `secret` | Secret string used to derive the encryption key |
|
|
412
|
+
|
|
413
|
+
Usage:
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
import {encryptParams} from '@enonic/nextjs-adapter';
|
|
417
|
+
|
|
418
|
+
const blob = encryptParams({userId: '123', role: 'editor'}, process.env.ENONIC_API_TOKEN);
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
<br/>
|
|
422
|
+
|
|
423
|
+
#### <a id="decrypt-params"></a>`decryptParams(blob: string, secret: string) => Record<string, any> | null`
|
|
424
|
+
|
|
425
|
+
Decrypts a base64url string produced by [encryptParams()](#encrypt-params). Returns `null` if the input is malformed,
|
|
426
|
+
tampered with, or was encrypted with a different secret.
|
|
427
|
+
|
|
428
|
+
| Argument | Description |
|
|
429
|
+
|----------|----------------------------------------------|
|
|
430
|
+
| `blob` | Base64url string produced by `encryptParams` |
|
|
431
|
+
| `secret` | Same secret used during encryption |
|
|
432
|
+
|
|
433
|
+
Usage:
|
|
434
|
+
|
|
435
|
+
```tsx
|
|
436
|
+
import {decryptParams} from '@enonic/nextjs-adapter';
|
|
437
|
+
|
|
438
|
+
const params = decryptParams(blob, process.env.ENONIC_API_TOKEN);
|
|
439
|
+
if (params) {
|
|
440
|
+
// use params.userId, params.role, ...
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
<br/>
|
|
445
|
+
|
|
416
446
|
### `ComponentRegistry`
|
|
417
447
|
|
|
418
448
|
Registry containing definitions of all components (i.e. pages, parts, layouts, macros, etc. ). It is used in the runtime by `nextjs-adapter`
|
|
@@ -435,9 +465,12 @@ import {ComponentRegistry} from '@enonic/nextjs-adapter';
|
|
|
435
465
|
|
|
436
466
|
const query = {
|
|
437
467
|
query: 'graphql query',
|
|
438
|
-
variables: (path, context, config) => {
|
|
468
|
+
variables: ({path, siteKey, branch, project}, context, config) => {
|
|
439
469
|
return {
|
|
440
|
-
path: path + '/some/processing'
|
|
470
|
+
path: path + '/some/processing',
|
|
471
|
+
siteKey,
|
|
472
|
+
branch,
|
|
473
|
+
project,
|
|
441
474
|
};
|
|
442
475
|
}
|
|
443
476
|
}
|
|
@@ -454,6 +487,17 @@ Gets the common query definition.
|
|
|
454
487
|
<a id="query-def"></a>Response type:
|
|
455
488
|
|
|
456
489
|
```tsx
|
|
490
|
+
interface GlobalVariables {
|
|
491
|
+
path: string;
|
|
492
|
+
siteKey: string;
|
|
493
|
+
branch: string;
|
|
494
|
+
project: string;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
type QueryGetter = (vars: GlobalVariables, context?: Context, config?: any) => string;
|
|
498
|
+
|
|
499
|
+
type VariablesGetter = (vars: GlobalVariables, context?: Context, config?: any) => GlobalVariables & Record<string, any>;
|
|
500
|
+
|
|
457
501
|
type SelectedQueryMaybeVariablesFunc =
|
|
458
502
|
string |
|
|
459
503
|
QueryGetter |
|
|
@@ -504,17 +548,17 @@ interface ComponentDefinition {
|
|
|
504
548
|
|
|
505
549
|
<br/>
|
|
506
550
|
|
|
507
|
-
#### `static addMacro(name: string, obj:
|
|
551
|
+
#### `static addMacro(name: string, obj: ComponentDefinitionParams): void`
|
|
508
552
|
|
|
509
|
-
#### `static addPart(name: string, obj:
|
|
553
|
+
#### `static addPart(name: string, obj: ComponentDefinitionParams): void`
|
|
510
554
|
|
|
511
|
-
#### `static addLayout(name: string, obj:
|
|
555
|
+
#### `static addLayout(name: string, obj: ComponentDefinitionParams): void`
|
|
512
556
|
|
|
513
|
-
#### `static
|
|
557
|
+
#### `static addPage(name: string, obj: ComponentDefinitionParams): void`
|
|
514
558
|
|
|
515
|
-
#### `static addContentType(name: string, obj:
|
|
559
|
+
#### `static addContentType(name: string, obj: ComponentDefinitionParams): void`
|
|
516
560
|
|
|
517
|
-
#### `static addComponent(name: string, obj:
|
|
561
|
+
#### `static addComponent(name: string, obj: ComponentDefinitionParams): void`
|
|
518
562
|
|
|
519
563
|
Saves the component definition in ComponentRegistry by name.
|
|
520
564
|
|
|
@@ -570,19 +614,19 @@ Response type: [component definition](#comp-def)
|
|
|
570
614
|
|
|
571
615
|
<br/>
|
|
572
616
|
|
|
573
|
-
#### `static getMacros(): ComponentDefinition[]`
|
|
617
|
+
#### `static getMacros(): [string, ComponentDefinition][]`
|
|
574
618
|
|
|
575
|
-
#### `static getParts(): ComponentDefinition[]`
|
|
619
|
+
#### `static getParts(): [string, ComponentDefinition][]`
|
|
576
620
|
|
|
577
|
-
#### `static getLayouts(): ComponentDefinition[]`
|
|
621
|
+
#### `static getLayouts(): [string, ComponentDefinition][]`
|
|
578
622
|
|
|
579
|
-
#### `static getPages(): ComponentDefinition[]`
|
|
623
|
+
#### `static getPages(): [string, ComponentDefinition][]`
|
|
580
624
|
|
|
581
|
-
#### `static getContentTypes(): ComponentDefinition[]`
|
|
625
|
+
#### `static getContentTypes(): [string, ComponentDefinition][]`
|
|
582
626
|
|
|
583
|
-
#### `static getComponents(): ComponentDefinition[]`
|
|
627
|
+
#### `static getComponents(): [string, ComponentDefinition][]`
|
|
584
628
|
|
|
585
|
-
Gets all component
|
|
629
|
+
Gets all component entries (`[name, definition]` tuples) stored in ComponentRegistry.
|
|
586
630
|
|
|
587
631
|
> **NOTE:** Read [addComponent](#add-comp) note before using `getComponents`.
|
|
588
632
|
|
|
@@ -594,7 +638,7 @@ import {ComponentRegistry} from '@enonic/nextjs-adapter';
|
|
|
594
638
|
const macros = ComponentRegistry.getMacros();
|
|
595
639
|
```
|
|
596
640
|
|
|
597
|
-
Response type:
|
|
641
|
+
Response type: list of `[name, ComponentDefinition]` tuples — see [component definition](#comp-def).
|
|
598
642
|
|
|
599
643
|
<br/>
|
|
600
644
|
|
|
@@ -609,7 +653,7 @@ Helper singleton for processing URLs.
|
|
|
609
653
|
Processes the absolute URL to become relative for the current viewer, while keeping in mind Next.js assets and Enonic XP binary content
|
|
610
654
|
links
|
|
611
655
|
|
|
612
|
-
> **NOTE:** There
|
|
656
|
+
> **NOTE:** There is a convenience alias to this function called [getUrl()](#get-url)
|
|
613
657
|
|
|
614
658
|
| Argument | Description |
|
|
615
659
|
|--------------|------------------------------------------------------------------------------|
|
|
@@ -647,26 +691,6 @@ const url = UrlProcessor.processSrcSet('<srcset value>', meta);
|
|
|
647
691
|
|
|
648
692
|
<br/>
|
|
649
693
|
|
|
650
|
-
#### `static setSiteKey(key: string): void`
|
|
651
|
-
|
|
652
|
-
> **DEPRECATED:** It is automatically done by `nextjs-adapter` now and have no effect.
|
|
653
|
-
|
|
654
|
-
Sets the site key value that is needed for correct absolute URL processing.
|
|
655
|
-
|
|
656
|
-
| Argument | Description |
|
|
657
|
-
|----------|-------------|
|
|
658
|
-
| `key` | Site key |
|
|
659
|
-
|
|
660
|
-
Usage:
|
|
661
|
-
|
|
662
|
-
```tsx
|
|
663
|
-
import {UrlProcessor} from '@enonic/nextjs-adapter';
|
|
664
|
-
|
|
665
|
-
UrlProcessor.setSiteKey('<site key>');
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
<br/>
|
|
669
|
-
|
|
670
694
|
#### `static isMediaLink(ref: string, linkData: LinkData[]): boolean`
|
|
671
695
|
|
|
672
696
|
Checks if link data array contains link with provided ref. Positive result means that this is a link to Enonic XP content.
|
|
@@ -784,7 +808,7 @@ const mapping = getLocaleMappingByLocale('en', true);
|
|
|
784
808
|
|
|
785
809
|
<br/>
|
|
786
810
|
|
|
787
|
-
#### `getRequestLocaleInfo(context: Context):
|
|
811
|
+
#### `getRequestLocaleInfo(context: Context): LocaleInfo`
|
|
788
812
|
|
|
789
813
|
Attempts to get the locale info from the request. Along with that it also returns the default locale and all configured locales.
|
|
790
814
|
|
|
@@ -903,9 +927,9 @@ There is also a number of utility constants and functions available at `@enonic/
|
|
|
903
927
|
|
|
904
928
|
<br/>
|
|
905
929
|
|
|
906
|
-
|
|
907
|
-
import {CATCH_ALL} from './constants';
|
|
930
|
+
All of the following are exported from `@enonic/nextjs-adapter`:
|
|
908
931
|
|
|
932
|
+
```tsx
|
|
909
933
|
IS_DEV_MODE; // True if current mode == development
|
|
910
934
|
|
|
911
935
|
APP_NAME; // Name of the app defined in .env files
|
|
@@ -953,11 +977,10 @@ enum XP_COMPONENT_TYPE { // Enum for XP component types
|
|
|
953
977
|
|
|
954
978
|
// Sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
|
|
955
979
|
const sanitizeGraphqlName = (text: string) => string;
|
|
956
|
-
|
|
957
|
-
// Returns full content api URL with current project and branch appended
|
|
958
|
-
const getContentApiUrl = (context: Context) => string;
|
|
959
980
|
```
|
|
960
981
|
|
|
982
|
+
See also: [getContentBranch](#get-content-branch), [encryptParams](#encrypt-params), [decryptParams](#decrypt-params).
|
|
983
|
+
|
|
961
984
|
### Views
|
|
962
985
|
|
|
963
986
|
They are located in `@enonic/nextjs-adapter/views` folder. Each view is a default export in the corresponding file.
|
|
@@ -979,10 +1002,13 @@ Usage:
|
|
|
979
1002
|
|
|
980
1003
|
```tsx
|
|
981
1004
|
import MainView from '@enonic/nextjs-adapter/views/MainView';
|
|
982
|
-
import fetchContent from '@enonic/nextjs-adapter';
|
|
1005
|
+
import {fetchContent} from '@enonic/nextjs-adapter/server';
|
|
983
1006
|
|
|
984
1007
|
export async function getServerSideProps(context: Context) {
|
|
985
|
-
const props = fetchContent(
|
|
1008
|
+
const props = await fetchContent({
|
|
1009
|
+
contentPath: '/content/path',
|
|
1010
|
+
locale: 'en',
|
|
1011
|
+
});
|
|
986
1012
|
return {
|
|
987
1013
|
props
|
|
988
1014
|
}
|
|
@@ -993,37 +1019,37 @@ export default MainView;
|
|
|
993
1019
|
|
|
994
1020
|
<br/>
|
|
995
1021
|
|
|
996
|
-
#### `<StaticContent condition=
|
|
1022
|
+
#### `<StaticContent condition={true} element="div">`
|
|
997
1023
|
|
|
998
1024
|
Tag for disabling client side hydration if the condition is true. This will remove interactivity from children.
|
|
999
1025
|
|
|
1000
1026
|
| Argument | Type | Description |
|
|
1001
1027
|
|--------------------|-----------|------------------------------------|
|
|
1002
1028
|
| `condition = true` | `Boolean` | Condition to trigger static output |
|
|
1003
|
-
| `
|
|
1029
|
+
| `element = 'div'` | `String` | Html tag to use for static output |
|
|
1004
1030
|
|
|
1005
1031
|
Usage:
|
|
1006
1032
|
|
|
1007
1033
|
```tsx
|
|
1008
1034
|
import StaticContent from '@enonic/nextjs-adapter/views/StaticContent';
|
|
1009
1035
|
|
|
1010
|
-
<StaticContent condition={true}
|
|
1036
|
+
<StaticContent condition={true} element="div"> ...child elements... </StaticContent>
|
|
1011
1037
|
```
|
|
1012
1038
|
|
|
1013
1039
|
<br/>
|
|
1014
1040
|
|
|
1015
|
-
#### <a id="rich-text-view"></a
|
|
1041
|
+
#### <a id="rich-text-view"></a>
|
|
1042
|
+
`<RichTextView className="css-class" tag="section" data={data} meta={meta} customReplacer={customReplacerFn}>`
|
|
1016
1043
|
|
|
1017
1044
|
Tag for displaying contents of html area input types. Takes care of processing macros, URLs and images inside.
|
|
1018
1045
|
|
|
1019
|
-
| Argument
|
|
1020
|
-
|
|
1021
|
-
| `data`
|
|
1022
|
-
| `meta`
|
|
1023
|
-
| `customReplacer`
|
|
1024
|
-
| `className`
|
|
1025
|
-
| `
|
|
1026
|
-
| `tag = 'div'` | `String` | Html tag to use as a root |
|
|
1046
|
+
| Argument | Type | Description |
|
|
1047
|
+
|------------------|----------------|---------------------------------------------------------------------------------------------------|
|
|
1048
|
+
| `data` | `RichTextData` | Rich text data |
|
|
1049
|
+
| `meta` | `MetaData` | Runtime data returned by fetchContent method. |
|
|
1050
|
+
| `customReplacer` | `Replacer` | Function to do custom element processing. Not invoked for image, link and macro nodes. _Optional_ |
|
|
1051
|
+
| `className` | `String` | Class name to add to the root html element. _Optional_ |
|
|
1052
|
+
| `tag = 'div'` | `String` | Html tag to use as a root |
|
|
1027
1053
|
|
|
1028
1054
|
> **TIP!** There is a utility function [richTextQuery(fieldName)](#rich-text-query) generating part of the graphql query to
|
|
1029
1055
|
> obtain `RichTextData` for html area input types.
|
|
@@ -1033,7 +1059,7 @@ Usage:
|
|
|
1033
1059
|
```tsx
|
|
1034
1060
|
import RichTextView from '@enonic/nextjs-adapter/views/RichTextView';
|
|
1035
1061
|
|
|
1036
|
-
<RichTextView data={richTextData} meta={meta} tag="section" className="rich-text-view"
|
|
1062
|
+
<RichTextView data={richTextData} meta={meta} tag="section" className="rich-text-view"></RichTextView>
|
|
1037
1063
|
```
|
|
1038
1064
|
|
|
1039
1065
|
<br/>
|
|
@@ -1053,7 +1079,7 @@ All necessary data can be acquired by running [fetchContent()](#fetch-content)
|
|
|
1053
1079
|
Usage:
|
|
1054
1080
|
|
|
1055
1081
|
```tsx
|
|
1056
|
-
import
|
|
1082
|
+
import Regions from '@enonic/nextjs-adapter/views/Region';
|
|
1057
1083
|
|
|
1058
|
-
<
|
|
1084
|
+
<Regions page={page} meta={meta} name="main" common={common}/>
|
|
1059
1085
|
```
|
|
@@ -7,19 +7,13 @@ export declare class UrlProcessor {
|
|
|
7
7
|
static LINK_ATTR: string;
|
|
8
8
|
static MACRO_ATTR: string;
|
|
9
9
|
private static IMG_ATMT_REGEXP;
|
|
10
|
-
private static endSlashPattern;
|
|
11
|
-
private static startSlashPattern;
|
|
12
|
-
private static localhostPattern;
|
|
13
10
|
static process(url: string, meta: MetaData, serverSide?: boolean, isResource?: boolean): string;
|
|
14
|
-
static
|
|
11
|
+
private static normalizeBaseUrl;
|
|
15
12
|
static isMediaLink(ref: string, linkData: LinkData[]): boolean;
|
|
16
13
|
static isContentImage(ref: string, imageData: ImageData[]): boolean;
|
|
17
14
|
static processSrcSet(srcset: string, meta: MetaData): string;
|
|
18
|
-
private static stripApiUrl;
|
|
19
15
|
private static isAttachmentUrl;
|
|
20
16
|
private static startsWithHash;
|
|
21
|
-
private static
|
|
22
|
-
private static getApiUrl;
|
|
17
|
+
private static isAbsolute;
|
|
23
18
|
}
|
|
24
19
|
export declare function getUrl(url: string, meta: MetaData): string;
|
|
25
|
-
export declare function getAsset(url: string, meta: MetaData): string;
|