@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.
Files changed (83) hide show
  1. package/README.md +129 -155
  2. package/dist/common/UrlProcessor.d.ts +8 -2
  3. package/dist/common/UrlProcessor.js +89 -32
  4. package/dist/common/UrlProcessor.js.map +1 -1
  5. package/dist/common/constants.d.ts +1 -2
  6. package/dist/common/constants.js +25 -26
  7. package/dist/common/constants.js.map +1 -1
  8. package/dist/guillotine/buildErrorResponse.d.ts +1 -1
  9. package/dist/guillotine/buildErrorResponse.js +2 -4
  10. package/dist/guillotine/buildErrorResponse.js.map +1 -1
  11. package/dist/guillotine/collectComponentDescriptors.d.ts +3 -5
  12. package/dist/guillotine/collectComponentDescriptors.js +3 -5
  13. package/dist/guillotine/collectComponentDescriptors.js.map +1 -1
  14. package/dist/guillotine/combineMultipleQueries.js +13 -22
  15. package/dist/guillotine/combineMultipleQueries.js.map +1 -1
  16. package/dist/guillotine/createMetaData.d.ts +2 -4
  17. package/dist/guillotine/createMetaData.js +2 -4
  18. package/dist/guillotine/createMetaData.js.map +1 -1
  19. package/dist/guillotine/fetchContent.js +17 -27
  20. package/dist/guillotine/fetchContent.js.map +1 -1
  21. package/dist/guillotine/fetchContentData.d.ts +1 -1
  22. package/dist/guillotine/fetchContentData.js +4 -12
  23. package/dist/guillotine/fetchContentData.js.map +1 -1
  24. package/dist/guillotine/fetchContentPathsForAllLocales.d.ts +1 -1
  25. package/dist/guillotine/fetchContentPathsForAllLocales.js +3 -3
  26. package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -1
  27. package/dist/guillotine/fetchContentPathsForLocale.d.ts +1 -1
  28. package/dist/guillotine/fetchContentPathsForLocale.js +13 -13
  29. package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -1
  30. package/dist/guillotine/fetchFromApi.d.ts +2 -2
  31. package/dist/guillotine/fetchFromApi.js +5 -3
  32. package/dist/guillotine/fetchFromApi.js.map +1 -1
  33. package/dist/guillotine/fetchGuillotine.d.ts +2 -2
  34. package/dist/guillotine/fetchGuillotine.js +2 -2
  35. package/dist/guillotine/fetchGuillotine.js.map +1 -1
  36. package/dist/guillotine/fetchMetaData.d.ts +1 -1
  37. package/dist/guillotine/fetchMetaData.js +3 -6
  38. package/dist/guillotine/fetchMetaData.js.map +1 -1
  39. package/dist/guillotine/{getSiteRelativePathOrThrow.d.ts → getCleanContentPathArrayOrThrow400.d.ts} +1 -1
  40. package/dist/guillotine/{getSiteRelativePathOrThrow.js → getCleanContentPathArrayOrThrow400.js} +2 -2
  41. package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  42. package/dist/guillotine/getMetaData.d.ts +0 -2
  43. package/dist/guillotine/getMetaData.js +10 -17
  44. package/dist/guillotine/getMetaData.js.map +1 -1
  45. package/dist/guillotine/getQueryAndVariables.d.ts +2 -2
  46. package/dist/guillotine/getQueryAndVariables.js +5 -12
  47. package/dist/guillotine/getQueryAndVariables.js.map +1 -1
  48. package/dist/guillotine/metadata/richTextQuery.js +0 -1
  49. package/dist/guillotine/metadata/richTextQuery.js.map +1 -1
  50. package/dist/index.d.ts +2 -4
  51. package/dist/index.js +2 -4
  52. package/dist/index.js.map +1 -1
  53. package/dist/query/Shortcut.d.ts +1 -1
  54. package/dist/query/Shortcut.js +15 -11
  55. package/dist/query/Shortcut.js.map +1 -1
  56. package/dist/types/component.d.ts +6 -9
  57. package/dist/types/componentProps.d.ts +4 -4
  58. package/dist/utils/fixDoubleSlashes.d.ts +0 -3
  59. package/dist/utils/fixDoubleSlashes.js +0 -9
  60. package/dist/utils/fixDoubleSlashes.js.map +1 -1
  61. package/dist/utils/getContentApiUrl.d.ts +2 -0
  62. package/dist/utils/getContentApiUrl.js +15 -0
  63. package/dist/utils/getContentApiUrl.js.map +1 -0
  64. package/dist/utils/getRenderMode.d.ts +1 -1
  65. package/dist/utils/getRenderMode.js +1 -1
  66. package/dist/utils/getRenderMode.js.map +1 -1
  67. package/dist/views/BaseMacro.jsx +30 -1
  68. package/dist/views/BaseMacro.jsx.map +1 -1
  69. package/dist/views/RichTextView.jsx +8 -8
  70. package/dist/views/RichTextView.jsx.map +1 -1
  71. package/dist/views/Text.jsx +1 -1
  72. package/dist/views/Text.jsx.map +1 -1
  73. package/package.json +13 -13
  74. package/dist/guillotine/getSiteRelativePathOrThrow.js.map +0 -1
  75. package/dist/utils/decryptParams.d.ts +0 -1
  76. package/dist/utils/decryptParams.js +0 -20
  77. package/dist/utils/decryptParams.js.map +0 -1
  78. package/dist/utils/encryptParams.d.ts +0 -1
  79. package/dist/utils/encryptParams.js +0 -12
  80. package/dist/utils/encryptParams.js.map +0 -1
  81. package/dist/utils/getContentBranch.d.ts +0 -2
  82. package/dist/utils/getContentBranch.js +0 -11
  83. 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 | Description |
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(contentApiUrl: string, options?: FetchOptions) => Promise<GuillotineResult>`
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 | Description |
93
- |-----------------|-------------------------------------------------|
94
- | `contentApiUrl` | Guillotine API URL |
95
- | `options` | Request and Next.js config options _(Optional)_ |
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
- | `options` | Request and Next.js config options _(Optional)_ |
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 | Description |
190
- |------------------|-----------------------------------------------------------|
191
- | `query` | Custom GraphQL query _(Optional)_ * |
192
- | `countPerLocale` | Max result count per locale _(Optional, defaults to 999)_ |
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
- &ast; Default query gets up to `countPerLocale` results, sorts them by `modifiedTime` and excludes following content types:
206
+ &ast; 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 = fetchContentPathsForAllLocales('custom graphql query', 1001);
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
- | `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)_ |
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 calls Next.js `notFound()` if data
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 = await fetchContent({
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: ({path, siteKey, branch, project}, context, config) => {
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: ComponentDefinitionParams): void`
507
+ #### `static addMacro(name: string, obj: ComponentDefinition): void`
552
508
 
553
- #### `static addPart(name: string, obj: ComponentDefinitionParams): void`
509
+ #### `static addPart(name: string, obj: ComponentDefinition): void`
554
510
 
555
- #### `static addLayout(name: string, obj: ComponentDefinitionParams): void`
511
+ #### `static addLayout(name: string, obj: ComponentDefinition): void`
556
512
 
557
- #### `static addPage(name: string, obj: ComponentDefinitionParams): void`
513
+ #### `static addCPage(name: string, obj: ComponentDefinition): void`
558
514
 
559
- #### `static addContentType(name: string, obj: ComponentDefinitionParams): void`
515
+ #### `static addContentType(name: string, obj: ComponentDefinition): void`
560
516
 
561
- #### `static addComponent(name: string, obj: ComponentDefinitionParams): void`
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(): [string, ComponentDefinition][]`
573
+ #### `static getMacros(): ComponentDefinition[]`
618
574
 
619
- #### `static getParts(): [string, ComponentDefinition][]`
575
+ #### `static getParts(): ComponentDefinition[]`
620
576
 
621
- #### `static getLayouts(): [string, ComponentDefinition][]`
577
+ #### `static getLayouts(): ComponentDefinition[]`
622
578
 
623
- #### `static getPages(): [string, ComponentDefinition][]`
579
+ #### `static getPages(): ComponentDefinition[]`
624
580
 
625
- #### `static getContentTypes(): [string, ComponentDefinition][]`
581
+ #### `static getContentTypes(): ComponentDefinition[]`
626
582
 
627
- #### `static getComponents(): [string, ComponentDefinition][]`
583
+ #### `static getComponents(): ComponentDefinition[]`
628
584
 
629
- Gets all component entries (`[name, definition]` tuples) stored in ComponentRegistry.
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: list of `[name, ComponentDefinition]` tuples — see [component definition](#comp-def).
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 is a convenience alias to this function called [getUrl()](#get-url)
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): LocaleInfo`
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
- See also: [getContentBranch](#get-content-branch), [encryptParams](#encrypt-params), [decryptParams](#decrypt-params).
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 {fetchContent} from '@enonic/nextjs-adapter/server';
982
+ import fetchContent from '@enonic/nextjs-adapter';
1006
983
 
1007
984
  export async function getServerSideProps(context: Context) {
1008
- const props = await fetchContent({
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={true} element="div">`
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
- | `element = 'div'` | `String` | Html tag to use for static output |
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} element="div"> ...child elements... </StaticContent>
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 | 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 |
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 Regions from '@enonic/nextjs-adapter/views/Region';
1056
+ import StaticContent from '@enonic/nextjs-adapter/views/StaticContent';
1083
1057
 
1084
- <Regions page={page} meta={meta} name="main" common={common}/>
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
- private static normalizeBaseUrl;
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 isAbsolute;
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;