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