@enonic/nextjs-adapter 3.2.1 → 3.3.0-B1
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/package.json +44 -25
- package/src/baseMappings.ts +9 -9
- package/src/common/ComponentRegistry.ts +2 -5
- package/src/common/constants.ts +4 -4
- package/src/common/env.ts +1 -1
- package/src/guillotine/applyProcessors.ts +3 -7
- package/src/guillotine/buildComponentTree.ts +1 -1
- package/src/guillotine/buildErrorResponse.ts +3 -3
- package/src/guillotine/buildPage.ts +2 -2
- package/src/guillotine/collectComponentDescriptors.ts +6 -13
- package/src/guillotine/combineMultipleQueries.ts +3 -6
- package/src/guillotine/createMetaData.ts +2 -2
- package/src/guillotine/fetchContent.ts +8 -14
- package/src/guillotine/fetchContentData.ts +4 -10
- package/src/guillotine/fetchContentPathsForAllLocales.ts +3 -3
- package/src/guillotine/fetchContentPathsForLocale.ts +7 -7
- package/src/guillotine/fetchFromApi.ts +8 -8
- package/src/guillotine/fetchGuillotine.ts +22 -9
- package/src/guillotine/fetchMetaData.ts +5 -5
- package/src/guillotine/getCleanContentPathArrayOrThrow400.ts +2 -2
- package/src/guillotine/getParentRegion.ts +2 -2
- package/src/guillotine/getQueryAndVariables.ts +5 -9
- package/src/guillotine/metadata/configQuery.ts +2 -2
- package/src/guillotine/parseComponentPath.ts +4 -7
- package/src/guillotine/processComponentConfig.ts +1 -1
- package/src/guillotine/restrictComponentsToPath.ts +1 -1
- package/src/i18n/LocaleContext.tsx +3 -3
- package/src/index.ts +3 -3
- package/src/types/component.ts +1 -1
- package/src/types/componentProps.ts +4 -3
- package/src/types/guillotine.ts +1 -1
- package/src/types/index.ts +3 -3
- package/src/utils/buildGuillotineRequestHeaders.ts +4 -7
- package/src/utils/fixDoubleSlashes.ts +1 -1
- package/src/utils/getLocaleMappings.ts +1 -1
- package/src/utils/getRenderMode.ts +2 -5
- package/src/views/BaseComponent.tsx +5 -5
- package/src/views/BaseContent.tsx +1 -1
- package/src/views/BaseMacro.tsx +1 -1
- package/src/views/PropsView.tsx +1 -1
- package/src/views/RichTextView.tsx +68 -25
- package/src/views/StaticContent.tsx +1 -1
- package/baseMappings.d.ts +0 -1
- package/baseMappings.js +0 -43
- package/baseMappings.js.map +0 -1
- package/client/getClientHydratedHtml.d.ts +0 -1
- package/client/getClientHydratedHtml.jsx +0 -9
- package/client/getClientHydratedHtml.jsx.map +0 -1
- package/client.d.ts +0 -1
- package/client.js +0 -3
- package/client.js.map +0 -1
- package/common/ComponentRegistry.d.ts +0 -34
- package/common/ComponentRegistry.js +0 -121
- package/common/ComponentRegistry.js.map +0 -1
- package/common/UrlProcessor.d.ts +0 -25
- package/common/UrlProcessor.js +0 -151
- package/common/UrlProcessor.js.map +0 -1
- package/common/constants.d.ts +0 -51
- package/common/constants.js +0 -86
- package/common/constants.js.map +0 -1
- package/common/env.d.ts +0 -12
- package/common/env.js +0 -30
- package/common/env.js.map +0 -1
- package/guillotine/applyProcessors.d.ts +0 -2
- package/guillotine/applyProcessors.js +0 -33
- package/guillotine/applyProcessors.js.map +0 -1
- package/guillotine/buildComponentTree.d.ts +0 -2
- package/guillotine/buildComponentTree.js +0 -45
- package/guillotine/buildComponentTree.js.map +0 -1
- package/guillotine/buildErrorResponse.d.ts +0 -3
- package/guillotine/buildErrorResponse.js +0 -27
- package/guillotine/buildErrorResponse.js.map +0 -1
- package/guillotine/buildPage.d.ts +0 -2
- package/guillotine/buildPage.js +0 -10
- package/guillotine/buildPage.js.map +0 -1
- package/guillotine/collectComponentDescriptors.d.ts +0 -6
- package/guillotine/collectComponentDescriptors.js +0 -43
- package/guillotine/collectComponentDescriptors.js.map +0 -1
- package/guillotine/combineMultipleQueries.d.ts +0 -2
- package/guillotine/combineMultipleQueries.js +0 -58
- package/guillotine/combineMultipleQueries.js.map +0 -1
- package/guillotine/createMetaData.d.ts +0 -18
- package/guillotine/createMetaData.js +0 -45
- package/guillotine/createMetaData.js.map +0 -1
- package/guillotine/fetchContent.d.ts +0 -9
- package/guillotine/fetchContent.js +0 -222
- package/guillotine/fetchContent.js.map +0 -1
- package/guillotine/fetchContentData.d.ts +0 -2
- package/guillotine/fetchContentData.js +0 -30
- package/guillotine/fetchContentData.js.map +0 -1
- package/guillotine/fetchContentPathsForAllLocales.d.ts +0 -2
- package/guillotine/fetchContentPathsForAllLocales.js +0 -21
- package/guillotine/fetchContentPathsForAllLocales.js.map +0 -1
- package/guillotine/fetchContentPathsForLocale.d.ts +0 -2
- package/guillotine/fetchContentPathsForLocale.js +0 -41
- package/guillotine/fetchContentPathsForLocale.js.map +0 -1
- package/guillotine/fetchFromApi.d.ts +0 -3
- package/guillotine/fetchFromApi.js +0 -76
- package/guillotine/fetchFromApi.js.map +0 -1
- package/guillotine/fetchGuillotine.d.ts +0 -3
- package/guillotine/fetchGuillotine.js +0 -62
- package/guillotine/fetchGuillotine.js.map +0 -1
- package/guillotine/fetchMetaData.d.ts +0 -2
- package/guillotine/fetchMetaData.js +0 -33
- package/guillotine/fetchMetaData.js.map +0 -1
- package/guillotine/getCleanContentPathArrayOrThrow400.d.ts +0 -2
- package/guillotine/getCleanContentPathArrayOrThrow400.js +0 -20
- package/guillotine/getCleanContentPathArrayOrThrow400.js.map +0 -1
- package/guillotine/getComponentConfig.d.ts +0 -2
- package/guillotine/getComponentConfig.js +0 -5
- package/guillotine/getComponentConfig.js.map +0 -1
- package/guillotine/getContentAndComponentPaths.d.ts +0 -1
- package/guillotine/getContentAndComponentPaths.js +0 -12
- package/guillotine/getContentAndComponentPaths.js.map +0 -1
- package/guillotine/getMetaData.d.ts +0 -2
- package/guillotine/getMetaData.js +0 -67
- package/guillotine/getMetaData.js.map +0 -1
- package/guillotine/getParentRegion.d.ts +0 -2
- package/guillotine/getParentRegion.js +0 -40
- package/guillotine/getParentRegion.js.map +0 -1
- package/guillotine/getQueryAndVariables.d.ts +0 -2
- package/guillotine/getQueryAndVariables.js +0 -32
- package/guillotine/getQueryAndVariables.js.map +0 -1
- package/guillotine/metadata/configQuery.d.ts +0 -2
- package/guillotine/metadata/configQuery.js +0 -36
- package/guillotine/metadata/configQuery.js.map +0 -1
- package/guillotine/metadata/richTextQuery.d.ts +0 -1
- package/guillotine/metadata/richTextQuery.js +0 -47
- package/guillotine/metadata/richTextQuery.js.map +0 -1
- package/guillotine/parseComponentPath.d.ts +0 -2
- package/guillotine/parseComponentPath.js +0 -22
- package/guillotine/parseComponentPath.js.map +0 -1
- package/guillotine/prefixFragmentCmpPath.d.ts +0 -1
- package/guillotine/prefixFragmentCmpPath.js +0 -13
- package/guillotine/prefixFragmentCmpPath.js.map +0 -1
- package/guillotine/processComponentConfig.d.ts +0 -2
- package/guillotine/processComponentConfig.js +0 -30
- package/guillotine/processComponentConfig.js.map +0 -1
- package/guillotine/restrictComponentsToPath.d.ts +0 -2
- package/guillotine/restrictComponentsToPath.js +0 -38
- package/guillotine/restrictComponentsToPath.js.map +0 -1
- package/guillotine/validateData.d.ts +0 -2
- package/guillotine/validateData.js +0 -7
- package/guillotine/validateData.js.map +0 -1
- package/guillotine/validateNotFound.d.ts +0 -2
- package/guillotine/validateNotFound.js +0 -16
- package/guillotine/validateNotFound.js.map +0 -1
- package/guillotine/validateShortcut.d.ts +0 -2
- package/guillotine/validateShortcut.js +0 -35
- package/guillotine/validateShortcut.js.map +0 -1
- package/i18n/LocaleContext.d.ts +0 -7
- package/i18n/LocaleContext.jsx +0 -50
- package/i18n/LocaleContext.jsx.map +0 -1
- package/i18n/i18n.d.ts +0 -12
- package/i18n/i18n.js +0 -59
- package/i18n/i18n.js.map +0 -1
- package/index.d.ts +0 -14
- package/index.js +0 -14
- package/index.js.map +0 -1
- package/query/Shortcut.d.ts +0 -1
- package/query/Shortcut.js +0 -19
- package/query/Shortcut.js.map +0 -1
- package/server/getServerRenderedHtml.d.ts +0 -1
- package/server/getServerRenderedHtml.js +0 -4
- package/server/getServerRenderedHtml.js.map +0 -1
- package/server.d.ts +0 -5
- package/server.js +0 -6
- package/server.js.map +0 -1
- package/types/component.d.ts +0 -92
- package/types/component.js +0 -2
- package/types/component.js.map +0 -1
- package/types/componentProps.d.ts +0 -106
- package/types/componentProps.js +0 -2
- package/types/componentProps.js.map +0 -1
- package/types/guillotine.d.ts +0 -344
- package/types/guillotine.js +0 -2
- package/types/guillotine.js.map +0 -1
- package/types/i18n.d.ts +0 -7
- package/types/i18n.js +0 -2
- package/types/i18n.js.map +0 -1
- package/types/index.d.ts +0 -47
- package/types/index.js +0 -3
- package/types/index.js.map +0 -1
- package/types/next.d.ts +0 -6
- package/types/next.js +0 -2
- package/types/next.js.map +0 -1
- package/types/util.d.ts +0 -3
- package/types/util.js +0 -3
- package/types/util.js.map +0 -1
- package/utils/addLineNumbers.d.ts +0 -1
- package/utils/addLineNumbers.js +0 -4
- package/utils/addLineNumbers.js.map +0 -1
- package/utils/buildGuillotineRequestHeaders.d.ts +0 -7
- package/utils/buildGuillotineRequestHeaders.js +0 -16
- package/utils/buildGuillotineRequestHeaders.js.map +0 -1
- package/utils/commonChars.d.ts +0 -1
- package/utils/commonChars.js +0 -17
- package/utils/commonChars.js.map +0 -1
- package/utils/enonicLog.d.ts +0 -5
- package/utils/enonicLog.js +0 -23
- package/utils/enonicLog.js.map +0 -1
- package/utils/fixDoubleSlashes.d.ts +0 -1
- package/utils/fixDoubleSlashes.js +0 -4
- package/utils/fixDoubleSlashes.js.map +0 -1
- package/utils/getAllLocales.d.ts +0 -1
- package/utils/getAllLocales.js +0 -5
- package/utils/getAllLocales.js.map +0 -1
- package/utils/getContentApiUrl.d.ts +0 -2
- package/utils/getContentApiUrl.js +0 -15
- package/utils/getContentApiUrl.js.map +0 -1
- package/utils/getLocaleMapping.d.ts +0 -2
- package/utils/getLocaleMapping.js +0 -19
- package/utils/getLocaleMapping.js.map +0 -1
- package/utils/getLocaleMappingByLocale.d.ts +0 -2
- package/utils/getLocaleMappingByLocale.js +0 -13
- package/utils/getLocaleMappingByLocale.js.map +0 -1
- package/utils/getLocaleMappingByProjectId.d.ts +0 -2
- package/utils/getLocaleMappingByProjectId.js +0 -16
- package/utils/getLocaleMappingByProjectId.js.map +0 -1
- package/utils/getLocaleMappings.d.ts +0 -2
- package/utils/getLocaleMappings.js +0 -30
- package/utils/getLocaleMappings.js.map +0 -1
- package/utils/getRenderMode.d.ts +0 -3
- package/utils/getRenderMode.js +0 -8
- package/utils/getRenderMode.js.map +0 -1
- package/utils/getRequestLocaleInfo.d.ts +0 -6
- package/utils/getRequestLocaleInfo.js +0 -29
- package/utils/getRequestLocaleInfo.js.map +0 -1
- package/utils/getXpBaseUrl.d.ts +0 -2
- package/utils/getXpBaseUrl.js +0 -8
- package/utils/getXpBaseUrl.js.map +0 -1
- package/utils/indent.d.ts +0 -1
- package/utils/indent.js +0 -5
- package/utils/indent.js.map +0 -1
- package/utils/sanitizeGraphqlName.d.ts +0 -1
- package/utils/sanitizeGraphqlName.js +0 -12
- package/utils/sanitizeGraphqlName.js.map +0 -1
- package/views/BaseComponent.d.ts +0 -20
- package/views/BaseComponent.jsx +0 -129
- package/views/BaseComponent.jsx.map +0 -1
- package/views/BaseContent.d.ts +0 -3
- package/views/BaseContent.jsx +0 -38
- package/views/BaseContent.jsx.map +0 -1
- package/views/BaseLayout.d.ts +0 -3
- package/views/BaseLayout.jsx +0 -24
- package/views/BaseLayout.jsx.map +0 -1
- package/views/BaseMacro.d.ts +0 -6
- package/views/BaseMacro.jsx +0 -100
- package/views/BaseMacro.jsx.map +0 -1
- package/views/BasePage.d.ts +0 -3
- package/views/BasePage.jsx +0 -34
- package/views/BasePage.jsx.map +0 -1
- package/views/BasePart.d.ts +0 -3
- package/views/BasePart.jsx +0 -24
- package/views/BasePart.jsx.map +0 -1
- package/views/Empty.d.ts +0 -2
- package/views/Empty.jsx +0 -4
- package/views/Empty.jsx.map +0 -1
- package/views/Fragment.d.ts +0 -3
- package/views/Fragment.jsx +0 -30
- package/views/Fragment.jsx.map +0 -1
- package/views/MainView.d.ts +0 -3
- package/views/MainView.jsx +0 -14
- package/views/MainView.jsx.map +0 -1
- package/views/PropsView.d.ts +0 -2
- package/views/PropsView.jsx +0 -21
- package/views/PropsView.jsx.map +0 -1
- package/views/Region.d.ts +0 -6
- package/views/Region.jsx +0 -52
- package/views/Region.jsx.map +0 -1
- package/views/RichTextView.d.ts +0 -3
- package/views/RichTextView.jsx +0 -39
- package/views/RichTextView.jsx.map +0 -1
- package/views/SingleComponent.d.ts +0 -4
- package/views/SingleComponent.jsx +0 -10
- package/views/SingleComponent.jsx.map +0 -1
- package/views/StaticContent.d.ts +0 -10
- package/views/StaticContent.jsx +0 -37
- package/views/StaticContent.jsx.map +0 -1
- package/views/Text.d.ts +0 -8
- package/views/Text.jsx +0 -4
- package/views/Text.jsx.map +0 -1
- package/views/macros/DefaultMacro.d.ts +0 -3
- package/views/macros/DefaultMacro.jsx +0 -4
- package/views/macros/DefaultMacro.jsx.map +0 -1
- package/views/macros/DisableMacro.d.ts +0 -3
- package/views/macros/DisableMacro.jsx +0 -3
- package/views/macros/DisableMacro.jsx.map +0 -1
|
@@ -3,32 +3,45 @@ import gqlmin from 'gqlmin';
|
|
|
3
3
|
|
|
4
4
|
import {fetchFromApi} from './fetchFromApi';
|
|
5
5
|
|
|
6
|
+
const XP_ERROR_PATTERN = '/_/error/';
|
|
6
7
|
|
|
7
8
|
/** Guillotine-specialized fetch, using the generic fetch above */
|
|
8
9
|
export async function fetchGuillotine<Data = Record<string, unknown>>(
|
|
9
10
|
contentApiUrl: string,
|
|
10
11
|
mapping: LocaleMapping,
|
|
11
|
-
options?: FetchOptions
|
|
12
|
+
options?: FetchOptions
|
|
12
13
|
): Promise<GuillotineResult> {
|
|
13
14
|
const body = options?.body;
|
|
15
|
+
const path = body?.variables?.path;
|
|
16
|
+
|
|
14
17
|
if (typeof body.query !== 'string' || !body.query.trim()) {
|
|
15
18
|
return {
|
|
16
19
|
error: {
|
|
17
20
|
code: '400',
|
|
18
|
-
message: `Invalid or missing query. JSON.stringify(query) = ${JSON.stringify(body.query)}
|
|
19
|
-
}
|
|
21
|
+
message: `Invalid or missing query. JSON.stringify(query) = ${JSON.stringify(body.query)}`
|
|
22
|
+
}
|
|
20
23
|
};
|
|
21
24
|
} else {
|
|
22
|
-
//
|
|
23
|
-
|
|
25
|
+
// special case for not sending XP generated error paths to guillotine
|
|
26
|
+
const pathArr = path?.split(XP_ERROR_PATTERN);
|
|
27
|
+
if (pathArr?.length === 2) {
|
|
28
|
+
return {
|
|
29
|
+
error: {
|
|
30
|
+
code: pathArr[1],
|
|
31
|
+
message: `XP error URL detected`
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
// Minify the query to avoid hitting 200k space limit
|
|
36
|
+
body.query = gqlmin(body.query);
|
|
37
|
+
}
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
const path = body?.variables?.path;
|
|
27
40
|
const pathMessage = path ? JSON.stringify(path) : '';
|
|
28
41
|
return await fetchFromApi<Data>(
|
|
29
42
|
contentApiUrl,
|
|
30
43
|
mapping,
|
|
31
|
-
options
|
|
44
|
+
options
|
|
32
45
|
)
|
|
33
46
|
.then(json => {
|
|
34
47
|
let errors: any[] = json.errors; // fetchFromApi ensures json is an object
|
|
@@ -45,8 +58,8 @@ export async function fetchGuillotine<Data = Record<string, unknown>>(
|
|
|
45
58
|
return {
|
|
46
59
|
error: {
|
|
47
60
|
code: '500',
|
|
48
|
-
message: `Server responded with ${errors.length} error(s), probably from guillotine - see log
|
|
49
|
-
}
|
|
61
|
+
message: `Server responded with ${errors.length} error(s), probably from guillotine - see log.`
|
|
62
|
+
}
|
|
50
63
|
};
|
|
51
64
|
}
|
|
52
65
|
|
|
@@ -9,23 +9,23 @@ export const fetchMetaData = async (
|
|
|
9
9
|
contentApiUrl: string,
|
|
10
10
|
xpContentPath: string,
|
|
11
11
|
mapping: LocaleMapping,
|
|
12
|
-
headers?: GuillotineRequestHeaders
|
|
12
|
+
headers?: GuillotineRequestHeaders
|
|
13
13
|
): Promise<MetaResult> => {
|
|
14
14
|
const body: ContentApiBaseBody = {
|
|
15
15
|
query: getMetaQuery(pageFragmentQuery()),
|
|
16
16
|
variables: {
|
|
17
|
-
path: xpContentPath
|
|
18
|
-
}
|
|
17
|
+
path: xpContentPath
|
|
18
|
+
}
|
|
19
19
|
};
|
|
20
20
|
const metaResult = await fetchGuillotine<MetaResult>(contentApiUrl, mapping, {
|
|
21
21
|
body,
|
|
22
|
-
headers
|
|
22
|
+
headers
|
|
23
23
|
});
|
|
24
24
|
if (metaResult.error) {
|
|
25
25
|
return metaResult;
|
|
26
26
|
} else {
|
|
27
27
|
return {
|
|
28
|
-
meta: metaResult?.guillotine?.get
|
|
28
|
+
meta: metaResult?.guillotine?.get
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -10,7 +10,7 @@ export const getCleanContentPathArrayOrThrow400 = (contentPath: string | string[
|
|
|
10
10
|
throw Error(JSON.stringify({
|
|
11
11
|
code: 400,
|
|
12
12
|
message: `Unexpected target content _path: contentPath must be a string or pure string array (contentPath=${JSON.stringify(
|
|
13
|
-
contentPath)})
|
|
13
|
+
contentPath)})`
|
|
14
14
|
}));
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,4 +19,4 @@ export const getCleanContentPathArrayOrThrow400 = (contentPath: string | string[
|
|
|
19
19
|
} else {
|
|
20
20
|
return (contentPath).join('/');
|
|
21
21
|
}
|
|
22
|
-
};
|
|
22
|
+
};
|
|
@@ -10,7 +10,7 @@ export function getParentRegion(
|
|
|
10
10
|
contentType: string,
|
|
11
11
|
cmpPath: PathFragment[],
|
|
12
12
|
components: PageComponent[] = [],
|
|
13
|
-
createMissing
|
|
13
|
+
createMissing ?: boolean
|
|
14
14
|
): PageRegion | undefined {
|
|
15
15
|
let currentTree: RegionTree = source;
|
|
16
16
|
let currentRegion: PageRegion | undefined;
|
|
@@ -26,7 +26,7 @@ export function getParentRegion(
|
|
|
26
26
|
if (createMissing) {
|
|
27
27
|
currentRegion = {
|
|
28
28
|
name: regionName,
|
|
29
|
-
components: []
|
|
29
|
+
components: []
|
|
30
30
|
};
|
|
31
31
|
currentTree[regionName] = currentRegion;
|
|
32
32
|
} else {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Context,
|
|
3
|
-
QueryAndVariables,
|
|
4
|
-
SelectedQueryMaybeVariablesFunc,
|
|
5
|
-
} from '../types';
|
|
1
|
+
import type {Context, QueryAndVariables, SelectedQueryMaybeVariablesFunc} from '../types';
|
|
6
2
|
|
|
7
3
|
|
|
8
4
|
export function getQueryAndVariables(
|
|
@@ -10,7 +6,7 @@ export function getQueryAndVariables(
|
|
|
10
6
|
path: string,
|
|
11
7
|
context: Context,
|
|
12
8
|
selectedQuery?: SelectedQueryMaybeVariablesFunc,
|
|
13
|
-
config?: any
|
|
9
|
+
config?: any
|
|
14
10
|
): QueryAndVariables | undefined {
|
|
15
11
|
|
|
16
12
|
let query, getVariables;
|
|
@@ -45,8 +41,8 @@ export function getQueryAndVariables(
|
|
|
45
41
|
return {
|
|
46
42
|
query,
|
|
47
43
|
variables: getVariables ? getVariables(path, context, config) : {
|
|
48
|
-
path
|
|
49
|
-
}
|
|
44
|
+
path
|
|
45
|
+
}
|
|
50
46
|
};
|
|
51
47
|
}
|
|
52
|
-
}
|
|
48
|
+
}
|
|
@@ -7,7 +7,7 @@ import {sanitizeGraphqlName} from '../../utils/sanitizeGraphqlName';
|
|
|
7
7
|
export const configQuery = (
|
|
8
8
|
list: [string, ComponentDefinition][],
|
|
9
9
|
includeAppName = true,
|
|
10
|
-
canUseConfigAsJson = true
|
|
10
|
+
canUseConfigAsJson = true
|
|
11
11
|
): string => {
|
|
12
12
|
const hasQueryList = list?.filter(([key, def]) => def.configQuery) || [];
|
|
13
13
|
if (hasQueryList.length === 0) {
|
|
@@ -43,4 +43,4 @@ export const configQuery = (
|
|
|
43
43
|
${Object.entries(configsByApp).map(entry => entry[0] + '{\n' + entry[1].join('\n') + '\n}')}
|
|
44
44
|
}`;
|
|
45
45
|
}
|
|
46
|
-
};
|
|
46
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type {PathFragment} from '../types';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
FRAGMENT_CONTENTTYPE_NAME,
|
|
6
|
-
FRAGMENT_DEFAULT_REGION_NAME,
|
|
7
|
-
} from '../common/constants';
|
|
4
|
+
import {FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME} from '../common/constants';
|
|
8
5
|
|
|
9
6
|
|
|
10
7
|
export function parseComponentPath(contentType: string, path: string): PathFragment[] {
|
|
@@ -14,7 +11,7 @@ export function parseComponentPath(contentType: string, path: string): PathFragm
|
|
|
14
11
|
while ((match = myRegexp.exec(path)) !== null) {
|
|
15
12
|
matches.push({
|
|
16
13
|
region: match[1],
|
|
17
|
-
index: +match[2]
|
|
14
|
+
index: +match[2]
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
17
|
if (contentType === FRAGMENT_CONTENTTYPE_NAME) {
|
|
@@ -22,8 +19,8 @@ export function parseComponentPath(contentType: string, path: string): PathFragm
|
|
|
22
19
|
// prepend FRAGMENT_DEFAULT_REGION_NAME to path to conform to page structure
|
|
23
20
|
matches.unshift({
|
|
24
21
|
region: FRAGMENT_DEFAULT_REGION_NAME,
|
|
25
|
-
index: 0
|
|
22
|
+
index: 0
|
|
26
23
|
});
|
|
27
24
|
}
|
|
28
25
|
return matches;
|
|
29
|
-
}
|
|
26
|
+
}
|
|
@@ -7,7 +7,7 @@ import {sanitizeGraphqlName} from '../utils/sanitizeGraphqlName';
|
|
|
7
7
|
export function processComponentConfig(
|
|
8
8
|
myAppName: string,
|
|
9
9
|
myAppNameDashed: string,
|
|
10
|
-
cmp: PageComponent
|
|
10
|
+
cmp: PageComponent
|
|
11
11
|
): void {
|
|
12
12
|
const cmpData = cmp[cmp.type];
|
|
13
13
|
if (cmpData && 'descriptor' in cmpData && cmpData.descriptor) {
|
|
@@ -9,7 +9,7 @@ import {prefixFragmentCmpPath} from './prefixFragmentCmpPath';
|
|
|
9
9
|
export function restrictComponentsToPath(
|
|
10
10
|
contentType: string,
|
|
11
11
|
components?: PageComponent[],
|
|
12
|
-
componentPath?: string
|
|
12
|
+
componentPath?: string
|
|
13
13
|
): PageComponent[] {
|
|
14
14
|
if (!componentPath || !components?.length) {
|
|
15
15
|
return components || [];
|
|
@@ -9,14 +9,14 @@ const LocaleContext = createContext<LocaleContextType>({
|
|
|
9
9
|
dictionary: {},
|
|
10
10
|
locale: '',
|
|
11
11
|
localize: (key: string, ...args: any[]) => key,
|
|
12
|
-
setLocale: (locale: string) => Promise.resolve({})
|
|
12
|
+
setLocale: (locale: string) => Promise.resolve({})
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
export const useLocaleContext = () => useContext(LocaleContext);
|
|
16
16
|
|
|
17
17
|
export const LocaleContextProvider = ({
|
|
18
18
|
children,
|
|
19
|
-
locale: localeProps = ''
|
|
19
|
+
locale: localeProps = ''
|
|
20
20
|
}: {
|
|
21
21
|
children: any
|
|
22
22
|
locale?: string
|
|
@@ -51,7 +51,7 @@ export const LocaleContextProvider = ({
|
|
|
51
51
|
setLocale,
|
|
52
52
|
locale: currentLocale,
|
|
53
53
|
dictionary,
|
|
54
|
-
localize
|
|
54
|
+
localize
|
|
55
55
|
}}>
|
|
56
56
|
{children}
|
|
57
57
|
</LocaleContext.Provider>
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ export {
|
|
|
2
2
|
APP_NAME,
|
|
3
3
|
APP_NAME_DASHED,
|
|
4
4
|
APP_NAME_UNDERSCORED,
|
|
5
|
-
IS_DEV_MODE
|
|
5
|
+
IS_DEV_MODE
|
|
6
6
|
} from './common/env';
|
|
7
7
|
|
|
8
8
|
export type * from './types';
|
|
@@ -19,7 +19,7 @@ export {
|
|
|
19
19
|
RENDER_MODE_HEADER,
|
|
20
20
|
XP_BASE_URL_HEADER,
|
|
21
21
|
XP_COMPONENT_TYPE,
|
|
22
|
-
XP_REQUEST_TYPE
|
|
22
|
+
XP_REQUEST_TYPE
|
|
23
23
|
} from './common/constants';
|
|
24
24
|
|
|
25
25
|
|
|
@@ -38,5 +38,5 @@ export {sanitizeGraphqlName} from './utils/sanitizeGraphqlName';
|
|
|
38
38
|
export {
|
|
39
39
|
UrlProcessor,
|
|
40
40
|
getAsset,
|
|
41
|
-
getUrl
|
|
41
|
+
getUrl
|
|
42
42
|
} from './common/UrlProcessor';
|
package/src/types/component.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
RichTextData as CompsRichTextData,
|
|
5
5
|
LinkData as CompsLinkData,
|
|
6
6
|
ImageData as CompsImageData,
|
|
7
|
-
MacroData as CompsMacroData
|
|
7
|
+
MacroData as CompsMacroData
|
|
8
8
|
} from '@enonic/react-components';
|
|
9
9
|
|
|
10
10
|
// Differs from ComponentDefinition to avoid storing catchAll on all components
|
|
@@ -9,8 +9,9 @@ import type {
|
|
|
9
9
|
PageData,
|
|
10
10
|
PartData,
|
|
11
11
|
RichTextData,
|
|
12
|
-
RegionTree
|
|
12
|
+
RegionTree
|
|
13
13
|
} from './component';
|
|
14
|
+
import type {ReactNode} from 'react';
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
export interface BaseComponentProps {
|
|
@@ -29,7 +30,7 @@ export interface BaseLayoutProps {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export interface BaseMacroProps {
|
|
32
|
-
children:
|
|
33
|
+
children: ReactNode;
|
|
33
34
|
data: Omit<MacroData, 'ref'>;
|
|
34
35
|
meta: MetaData;
|
|
35
36
|
renderInEditMode?: boolean;
|
|
@@ -86,7 +87,7 @@ export interface MetaData {
|
|
|
86
87
|
apiUrl: string,
|
|
87
88
|
baseUrl: string,
|
|
88
89
|
locale: string,
|
|
89
|
-
defaultLocale: string
|
|
90
|
+
defaultLocale: string
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
export interface PageProps {
|
package/src/types/guillotine.ts
CHANGED
|
@@ -65,7 +65,7 @@ export interface FetchContentResult extends Result {
|
|
|
65
65
|
// Seems like NodeJS.fetch lowercases all headers, so we need to lowercase the
|
|
66
66
|
// header names here.
|
|
67
67
|
export interface GuillotineRequestHeaders {
|
|
68
|
-
[key: string]: string;
|
|
68
|
+
[key: string]: string | undefined;
|
|
69
69
|
Cookie?: string
|
|
70
70
|
locale: string
|
|
71
71
|
locales: string
|
package/src/types/index.ts
CHANGED
|
@@ -16,12 +16,12 @@ export interface ContentApiBaseBody {
|
|
|
16
16
|
|
|
17
17
|
export interface ContentApiBaseBodyVariables {
|
|
18
18
|
path?: string, // Full content item _path
|
|
19
|
-
[key: string]: string | number | undefined
|
|
19
|
+
[key: string]: string | number | undefined
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface ContentPathItem {
|
|
23
23
|
contentPath: string[]
|
|
24
|
-
locale: string
|
|
24
|
+
locale: string
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface PathFragment {
|
|
@@ -51,7 +51,7 @@ export type FetchOptions = Omit<RequestInit, 'body'> & {
|
|
|
51
51
|
body?: ContentApiBaseBody,
|
|
52
52
|
next?: {
|
|
53
53
|
revalidate?: boolean | number,
|
|
54
|
-
tags?: string[]
|
|
54
|
+
tags?: string[]
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type {Context, GuillotineRequestHeaders} from '../types';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
GUILLOTINE_REQUEST_HEADERS,
|
|
6
|
-
JSESSIONID_HEADER,
|
|
7
|
-
} from '../common/constants';
|
|
4
|
+
import {GUILLOTINE_REQUEST_HEADERS, JSESSIONID_HEADER} from '../common/constants';
|
|
8
5
|
|
|
9
6
|
|
|
10
7
|
export function buildGuillotineRequestHeaders({
|
|
11
8
|
context,
|
|
12
9
|
defaultLocale,
|
|
13
10
|
locale,
|
|
14
|
-
locales
|
|
11
|
+
locales
|
|
15
12
|
}: {
|
|
16
13
|
context: Context
|
|
17
14
|
defaultLocale: string
|
|
@@ -21,7 +18,7 @@ export function buildGuillotineRequestHeaders({
|
|
|
21
18
|
const guillotineRequestHeaders: GuillotineRequestHeaders = {
|
|
22
19
|
[GUILLOTINE_REQUEST_HEADERS.DEFAULT_LOCALE]: defaultLocale,
|
|
23
20
|
[GUILLOTINE_REQUEST_HEADERS.LOCALE]: locale,
|
|
24
|
-
[GUILLOTINE_REQUEST_HEADERS.LOCALES]: JSON.stringify(locales)
|
|
21
|
+
[GUILLOTINE_REQUEST_HEADERS.LOCALES]: JSON.stringify(locales)
|
|
25
22
|
};
|
|
26
23
|
const jsessionid = context.headers?.get(JSESSIONID_HEADER);
|
|
27
24
|
if (jsessionid) {
|
|
@@ -29,4 +26,4 @@ export function buildGuillotineRequestHeaders({
|
|
|
29
26
|
`${JSESSIONID_HEADER}=${jsessionid}`;
|
|
30
27
|
}
|
|
31
28
|
return guillotineRequestHeaders;
|
|
32
|
-
}
|
|
29
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type {Context} from '../types';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
RENDER_MODE,
|
|
6
|
-
RENDER_MODE_HEADER,
|
|
7
|
-
} from '../common/constants';
|
|
4
|
+
import {RENDER_MODE, RENDER_MODE_HEADER} from '../common/constants';
|
|
8
5
|
|
|
9
6
|
|
|
10
7
|
export const getRenderMode = (context: Context): RENDER_MODE => {
|
|
11
8
|
const value = context.headers?.get(RENDER_MODE_HEADER);
|
|
12
9
|
const enumValue = RENDER_MODE[(value as keyof typeof RENDER_MODE)?.toUpperCase()];
|
|
13
10
|
return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
|
|
14
|
-
};
|
|
11
|
+
};
|
|
@@ -64,7 +64,7 @@ export const MissingComponent = ({descriptor, type}: { descriptor?: string, type
|
|
|
64
64
|
return (
|
|
65
65
|
<div style={{
|
|
66
66
|
border: '2px dashed lightgrey',
|
|
67
|
-
padding: '16px'
|
|
67
|
+
padding: '16px'
|
|
68
68
|
}}>
|
|
69
69
|
<h3 style={{margin: 0}}>Missing component</h3>
|
|
70
70
|
<p style={{marginBottom: 0, color: 'grey'}}>
|
|
@@ -96,7 +96,7 @@ export const ErrorComponent = ({type, descriptor, reason}: { type?: string, desc
|
|
|
96
96
|
return (
|
|
97
97
|
<div style={{
|
|
98
98
|
border: '2px solid red',
|
|
99
|
-
padding: '16px'
|
|
99
|
+
padding: '16px'
|
|
100
100
|
}}>
|
|
101
101
|
<h3 style={{margin: 0, textTransform: 'capitalize'}}>{reason ? reason : 'Unknown error'}</h3>
|
|
102
102
|
{descriptor && <p style={{color: 'grey'}}>{`${type}: ${descriptor}`}</p>}
|
|
@@ -110,7 +110,7 @@ export function shouldShowErrorView(meta: MetaData): boolean {
|
|
|
110
110
|
|
|
111
111
|
function createEditorAttrs(type: XP_COMPONENT_TYPE): Record<string,string> {
|
|
112
112
|
return {
|
|
113
|
-
[PORTAL_COMPONENT_ATTRIBUTE]: type
|
|
113
|
+
[PORTAL_COMPONENT_ATTRIBUTE]: type
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -120,7 +120,7 @@ function createComponentAttrs(component: PageComponent, meta: MetaData, common?:
|
|
|
120
120
|
component: component[type],
|
|
121
121
|
path: component.path,
|
|
122
122
|
meta,
|
|
123
|
-
common
|
|
123
|
+
common
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
if (data) {
|
|
@@ -142,7 +142,7 @@ export const PlaceholderComponent = ({type, descriptor}: { type?: string, descri
|
|
|
142
142
|
return (
|
|
143
143
|
<div style={{
|
|
144
144
|
border: '2px solid lightgrey',
|
|
145
|
-
padding: '16px'
|
|
145
|
+
padding: '16px'
|
|
146
146
|
}}>
|
|
147
147
|
<h3 style={{margin: 0, textTransform: 'capitalize'}}>Empty output</h3>
|
|
148
148
|
{descriptor && <p style={{color: 'grey'}}>{`${type} '${descriptor}' output is empty`}</p>}
|
package/src/views/BaseMacro.tsx
CHANGED
|
@@ -31,7 +31,7 @@ const BaseMacro = (props: BaseMacroProps) => {
|
|
|
31
31
|
// do not parse system macros (embed, disable) in edit mode
|
|
32
32
|
// but parse others because panel macros (for instance) wants its content to be html, not string
|
|
33
33
|
// TODO: should we make this behavior configurable ?
|
|
34
|
-
const bodyString = !data.descriptor.startsWith('system:') ? HTMLReactParser(config.body) : config.body;
|
|
34
|
+
const bodyString = !data.descriptor.startsWith('system:') ? HTMLReactParser(config.body as string) : config.body;
|
|
35
35
|
return <>
|
|
36
36
|
{`[${data.name}${attrs}]`}
|
|
37
37
|
{bodyString}
|
package/src/views/PropsView.tsx
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
import type {MetaData, RichTextViewProps, Replacer as OldReplacer, MacroConfig, RichTextData} from '../types';
|
|
1
|
+
import type {MetaData, RichTextViewProps, Replacer as NextReplacer, RichTextData, MacroData} from '../types';
|
|
3
2
|
|
|
4
3
|
import {getUrl, UrlProcessor} from '../common/UrlProcessor';
|
|
5
4
|
import BaseMacro from './BaseMacro';
|
|
6
5
|
import Link from 'next/link';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
6
|
+
import {useMemo} from 'react';
|
|
7
|
+
import type {
|
|
8
|
+
MacroComponentParams,
|
|
9
|
+
LinkComponentParams,
|
|
10
|
+
ImageComponentParams,
|
|
11
|
+
Replacer as ComponentsReplacer,
|
|
12
|
+
ExtendedRichTextData,
|
|
13
|
+
ComponentDataAndProps,
|
|
14
|
+
MacroComponentData
|
|
15
|
+
} from '@enonic/react-components';
|
|
16
|
+
import {RichText, RichTextMetaData} from '@enonic/react-components';
|
|
9
17
|
import type {DOMNode} from 'html-react-parser';
|
|
10
|
-
import {
|
|
18
|
+
import {LiteralUnion, TextComponent} from '@enonic-types/core';
|
|
11
19
|
|
|
12
20
|
interface ExtraRichTextProps {
|
|
13
|
-
|
|
21
|
+
nextMeta: MetaData;
|
|
14
22
|
renderInEditMode?: boolean;
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
const RichTextView = (props: RichTextViewProps) => {
|
|
26
|
+
const component: TextComponent = useMemo(() => ({
|
|
27
|
+
type: 'text',
|
|
28
|
+
path: props.meta.path,
|
|
29
|
+
text: props.data.processedHtml
|
|
30
|
+
}), [props.meta.path, props.data.processedHtml]);
|
|
31
|
+
|
|
18
32
|
return <RichText<ExtraRichTextProps>
|
|
19
|
-
data={props.data}
|
|
20
|
-
meta={props.meta}
|
|
33
|
+
data={wrapData(props.data)}
|
|
34
|
+
meta={toRichTextMetaData(props.meta)}
|
|
35
|
+
nextMeta={props.meta}
|
|
36
|
+
component={component}
|
|
21
37
|
className={props.className}
|
|
22
38
|
tag={props.tag}
|
|
23
39
|
replacer={wrapReplacer(props.customReplacer, props.meta, props.renderMacroInEditMode)}
|
|
@@ -28,36 +44,63 @@ const RichTextView = (props: RichTextViewProps) => {
|
|
|
28
44
|
/>;
|
|
29
45
|
};
|
|
30
46
|
|
|
31
|
-
function wrapReplacer(
|
|
32
|
-
|
|
47
|
+
function wrapReplacer(nextReplacer: NextReplacer | undefined, meta: MetaData,
|
|
48
|
+
renderMacroInEditMode: boolean): ComponentsReplacer<ExtraRichTextProps> {
|
|
49
|
+
if (!nextReplacer) {
|
|
33
50
|
return null;
|
|
34
51
|
}
|
|
35
|
-
return (
|
|
36
|
-
return
|
|
52
|
+
return ({el, data}: { el: DOMNode, data: RichTextData, mode?: LiteralUnion<RequestMode> }) => {
|
|
53
|
+
return nextReplacer(el, data, meta, renderMacroInEditMode);
|
|
37
54
|
};
|
|
38
55
|
}
|
|
39
56
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
function wrapData(data: RichTextData): ExtendedRichTextData {
|
|
58
|
+
if (!data.macros || !data.macros.length) {
|
|
59
|
+
return data as ExtendedRichTextData;
|
|
60
|
+
}
|
|
61
|
+
const macroComponents = data.macros.map(macroData => {
|
|
62
|
+
return {
|
|
63
|
+
component: {
|
|
64
|
+
type: 'macro',
|
|
65
|
+
ref: macroData.ref,
|
|
66
|
+
name: macroData.name,
|
|
67
|
+
descriptor: macroData.descriptor
|
|
68
|
+
},
|
|
69
|
+
data: {
|
|
70
|
+
name: macroData.name,
|
|
71
|
+
descriptor: macroData.descriptor,
|
|
72
|
+
config: macroData.config || {}
|
|
73
|
+
}
|
|
74
|
+
} as ComponentDataAndProps<MacroComponentData>;
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
...data,
|
|
78
|
+
macroComponents
|
|
49
79
|
};
|
|
80
|
+
}
|
|
50
81
|
|
|
51
|
-
|
|
82
|
+
function MacroAdapter(props: MacroComponentParams<ExtraRichTextProps>) {
|
|
83
|
+
const {children, component, data, common, meta, nextMeta, renderInEditMode} = props;
|
|
84
|
+
|
|
85
|
+
return <BaseMacro data={data as Omit<MacroData, 'ref'>} meta={nextMeta} renderInEditMode={renderInEditMode}>{children}</BaseMacro>;
|
|
52
86
|
}
|
|
53
87
|
|
|
54
88
|
function LinkAdapter(props: LinkComponentParams<ExtraRichTextProps>) {
|
|
55
|
-
return <Link href={getUrl(props.href, props.
|
|
89
|
+
return <Link href={getUrl(props.href, props.nextMeta)}>{props.children}</Link>;
|
|
56
90
|
}
|
|
57
91
|
|
|
58
92
|
function ImageAdapter(props: ImageComponentParams<ExtraRichTextProps>) {
|
|
59
|
-
const srcSet = props.srcSet?.length ? UrlProcessor.processSrcSet(props.srcSet, props.
|
|
60
|
-
return <img src={getUrl(props.src, props.
|
|
93
|
+
const srcSet = props.srcSet?.length ? UrlProcessor.processSrcSet(props.srcSet, props.nextMeta) : undefined;
|
|
94
|
+
return <img src={getUrl(props.src, props.nextMeta)} style={props.style} alt={props.alt} sizes={props.sizes} srcSet={srcSet}/>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toRichTextMetaData(meta: MetaData): RichTextMetaData {
|
|
98
|
+
return {
|
|
99
|
+
type: meta.type,
|
|
100
|
+
mode: meta.renderMode,
|
|
101
|
+
path: meta.path,
|
|
102
|
+
id: meta.id
|
|
103
|
+
}
|
|
61
104
|
}
|
|
62
105
|
|
|
63
106
|
export default RichTextView;
|
package/baseMappings.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|