@enonic/nextjs-adapter 3.0.0 → 3.0.2
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/guillotine/validateShortcut.js +10 -4
- package/guillotine/validateShortcut.js.map +1 -1
- package/package.json +11 -11
- package/query/Shortcut.d.ts +1 -1
- package/query/Shortcut.js +4 -0
- package/query/Shortcut.js.map +1 -1
- package/src/guillotine/validateShortcut.ts +10 -4
- package/src/query/Shortcut.ts +4 -0
- package/src/types/componentProps.ts +3 -6
- package/src/utils/getRequestLocaleInfo.ts +5 -4
- package/src/views/RichTextView.tsx +5 -5
- package/types/componentProps.d.ts +1 -1
- package/utils/getRequestLocaleInfo.js +8 -5
- package/utils/getRequestLocaleInfo.js.map +1 -1
- package/views/RichTextView.jsx +5 -5
- package/views/RichTextView.jsx.map +1 -1
|
@@ -3,16 +3,22 @@ import { RENDER_MODE } from '../common/constants';
|
|
|
3
3
|
import { IS_DEV_MODE } from '../common/env';
|
|
4
4
|
import { UrlProcessor } from '../common/UrlProcessor';
|
|
5
5
|
export function validateShortcut(props) {
|
|
6
|
-
var _a, _b
|
|
6
|
+
var _a, _b;
|
|
7
7
|
const { data, meta, error } = props;
|
|
8
|
-
const
|
|
8
|
+
const dataObj = (_a = data === null || data === void 0 ? void 0 : data.get) === null || _a === void 0 ? void 0 : _a.data;
|
|
9
|
+
const pageUrl = (_b = dataObj === null || dataObj === void 0 ? void 0 : dataObj.target) === null || _b === void 0 ? void 0 : _b.pageUrl;
|
|
10
|
+
const parameters = dataObj === null || dataObj === void 0 ? void 0 : dataObj.parameters;
|
|
9
11
|
if (meta.type === 'base:shortcut' && pageUrl) {
|
|
10
12
|
if (meta.renderMode !== RENDER_MODE.NEXT) {
|
|
11
13
|
// do not show shortcut targets in preview/edit mode
|
|
12
|
-
console.warn(404, `Shortcuts are not available in ${
|
|
14
|
+
console.warn(404, `Shortcuts are not available in ${meta.renderMode} render mode`);
|
|
13
15
|
notFound();
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
let destination = UrlProcessor.process(pageUrl, meta, true);
|
|
18
|
+
if (parameters) {
|
|
19
|
+
const searchParams = parameters.map(({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join('&');
|
|
20
|
+
destination += '?' + searchParams;
|
|
21
|
+
}
|
|
16
22
|
console.debug(`Redirecting shortcut content [${meta.path}] to`, destination);
|
|
17
23
|
redirect(destination, RedirectType.replace);
|
|
18
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateShortcut.js","sourceRoot":"","sources":["../src/guillotine/validateShortcut.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAGpD,MAAM,UAAU,gBAAgB,CAAC,KAAyB;;IACtD,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAC,GAAG,KAAK,CAAC;IAClC,MAAM,OAAO,GAAG,MAAA,
|
|
1
|
+
{"version":3,"file":"validateShortcut.js","sourceRoot":"","sources":["../src/guillotine/validateShortcut.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAGpD,MAAM,UAAU,gBAAgB,CAAC,KAAyB;;IACtD,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAC,GAAG,KAAK,CAAC;IAClC,MAAM,OAA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G,IAAI,CAAC,UAAU,KAAK,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC;IAErG,MAAM,UAAU,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,YAAY,IAAI,sBAAsB,CAAC;IAE7F,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,8BAA8B,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAC9D,QAAQ,EAAE,CAAC;IACf,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enonic/nextjs-adapter",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Pavel Milkevich <pmi@enonic.com>",
|
|
@@ -53,23 +53,23 @@
|
|
|
53
53
|
"@formatjs/intl-localematcher": "^0.5.4",
|
|
54
54
|
"html-react-parser": "^5.1.10",
|
|
55
55
|
"negotiator": "^0.6.3",
|
|
56
|
-
"next": "^14.2.
|
|
57
|
-
"react": "18.
|
|
58
|
-
"react-dom": "18.
|
|
56
|
+
"next": "^14.2.3",
|
|
57
|
+
"react": "18.3.1",
|
|
58
|
+
"react-dom": "18.3.1",
|
|
59
59
|
"unescape": "^1.0.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@edge-runtime/jest-environment": "^2.3.10",
|
|
63
63
|
"@enonic-types/core": "^7.14.1",
|
|
64
64
|
"@enonic/eslint-config": "^1.2.1",
|
|
65
|
-
"@testing-library/jest-dom": "^6.4.
|
|
66
|
-
"@testing-library/react": "^15.0.
|
|
65
|
+
"@testing-library/jest-dom": "^6.4.5",
|
|
66
|
+
"@testing-library/react": "^15.0.7",
|
|
67
67
|
"@types/negotiator": "^0.6.3",
|
|
68
|
-
"@types/node": "^20.12.
|
|
69
|
-
"@types/react": "^18.2
|
|
70
|
-
"@types/react-dom": "^18.
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
72
|
-
"@typescript-eslint/parser": "^7.
|
|
68
|
+
"@types/node": "^20.12.11",
|
|
69
|
+
"@types/react": "^18.3.2",
|
|
70
|
+
"@types/react-dom": "^18.3.0",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
72
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
73
73
|
"concurrently": "^8.2.2",
|
|
74
74
|
"cpy-cli": "^5.0.0",
|
|
75
75
|
"del-cli": "^5.1.0",
|
package/query/Shortcut.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getShortcutQuery = "\n query($path:ID!){\n guillotine {\n get(key:$path) {\n ... on base_Shortcut {\n data {\n target {\n pageUrl(type: absolute)\n }\n }\n }\n }\n }\n }";
|
|
1
|
+
export declare const getShortcutQuery = "\n query($path:ID!){\n guillotine {\n get(key:$path) {\n ... on base_Shortcut {\n data {\n target {\n pageUrl(type: absolute)\n }\n parameters {\n name\n value\n }\n }\n }\n }\n }\n }";
|
package/query/Shortcut.js
CHANGED
package/query/Shortcut.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shortcut.js","sourceRoot":"","sources":["../src/query/Shortcut.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG
|
|
1
|
+
{"version":3,"file":"Shortcut.js","sourceRoot":"","sources":["../src/query/Shortcut.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;IAiB5B,CAAC"}
|
|
@@ -9,15 +9,21 @@ import {UrlProcessor} from '../common/UrlProcessor';
|
|
|
9
9
|
|
|
10
10
|
export function validateShortcut(props: FetchContentResult): void {
|
|
11
11
|
const {data, meta, error} = props;
|
|
12
|
-
const
|
|
12
|
+
const dataObj = data?.get?.data;
|
|
13
|
+
const pageUrl = dataObj?.target?.pageUrl;
|
|
14
|
+
const parameters = dataObj?.parameters;
|
|
13
15
|
if (meta.type === 'base:shortcut' && pageUrl) {
|
|
14
16
|
if (meta.renderMode !== RENDER_MODE.NEXT) {
|
|
15
17
|
// do not show shortcut targets in preview/edit mode
|
|
16
|
-
console.warn(404, `Shortcuts are not available in ${
|
|
18
|
+
console.warn(404, `Shortcuts are not available in ${meta.renderMode} render mode`);
|
|
17
19
|
notFound();
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
let destination = UrlProcessor.process(pageUrl, meta, true);
|
|
23
|
+
if (parameters) {
|
|
24
|
+
const searchParams = parameters.map(({name, value}) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join('&');
|
|
25
|
+
destination += '?' + searchParams;
|
|
26
|
+
}
|
|
21
27
|
console.debug(`Redirecting shortcut content [${meta.path}] to`, destination);
|
|
22
28
|
redirect(destination, RedirectType.replace);
|
|
23
29
|
}
|
|
@@ -34,4 +40,4 @@ export function validateShortcut(props: FetchContentResult): void {
|
|
|
34
40
|
console.warn(404, `Can not render content at [${meta.path}]`);
|
|
35
41
|
notFound();
|
|
36
42
|
}
|
|
37
|
-
}
|
|
43
|
+
}
|
package/src/query/Shortcut.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import {DOMNode} from 'html-react-parser';
|
|
2
|
-
import type {
|
|
3
|
-
RENDER_MODE,
|
|
4
|
-
XP_REQUEST_TYPE,
|
|
5
|
-
} from '../common/constants';
|
|
2
|
+
import type {RENDER_MODE, XP_REQUEST_TYPE} from '../common/constants';
|
|
6
3
|
import type {
|
|
7
4
|
FragmentData,
|
|
8
5
|
LayoutData,
|
|
@@ -130,7 +127,7 @@ export type Replacer = (
|
|
|
130
127
|
renderMacroInEditMode: boolean
|
|
131
128
|
) => ReplacerResult;
|
|
132
129
|
|
|
133
|
-
export type ReplacerResult = JSX.Element |
|
|
130
|
+
export type ReplacerResult = JSX.Element | DOMNode;
|
|
134
131
|
|
|
135
132
|
export interface RichTextViewProps {
|
|
136
133
|
data: RichTextData
|
|
@@ -139,4 +136,4 @@ export interface RichTextViewProps {
|
|
|
139
136
|
tag?: string
|
|
140
137
|
renderMacroInEditMode?: boolean
|
|
141
138
|
customReplacer?: Replacer
|
|
142
|
-
}
|
|
139
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import type {Context} from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import Negotiator from 'negotiator';
|
|
5
|
-
import {match as localeMatcher} from '@formatjs/intl-localematcher';
|
|
6
2
|
import {PROJECT_ID_HEADER} from '../common/constants';
|
|
7
3
|
import {getLocaleMappings} from './getLocaleMappings';
|
|
8
4
|
import {getLocaleMappingByProjectId} from './getLocaleMappingByProjectId';
|
|
@@ -19,10 +15,15 @@ export function getRequestLocaleInfo(context: Context) {
|
|
|
19
15
|
|
|
20
16
|
} else {
|
|
21
17
|
locale = context.locale;
|
|
18
|
+
/* Disabled to prevent situation when www.site.com redirects to www.site.com/no when accept-header is set to 'no'
|
|
19
|
+
|
|
22
20
|
if (!locale) {
|
|
23
21
|
const acceptLang = context.headers?.get('accept-language') || '';
|
|
24
22
|
const langs = new Negotiator({headers: {'accept-language': acceptLang}}).languages();
|
|
25
23
|
locale = localeMatcher(langs, locales, defaultLocale);
|
|
24
|
+
}*/
|
|
25
|
+
if (!locale) {
|
|
26
|
+
locale = defaultLocale;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
return {locale, locales, defaultLocale};
|
|
@@ -3,16 +3,15 @@ import type {MetaData, Replacer, ReplacerResult, RichTextData, RichTextViewProps
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
import {getUrl, UrlProcessor} from '../common/UrlProcessor';
|
|
6
|
-
import HTMLReactParser, {DOMNode} from 'html-react-parser';
|
|
6
|
+
import HTMLReactParser, {DOMNode, domToReact} from 'html-react-parser';
|
|
7
7
|
import {ElementType} from 'domelementtype';
|
|
8
8
|
import BaseMacro from './BaseMacro';
|
|
9
9
|
import Link from 'next/link';
|
|
10
|
-
import {Text} from 'domhandler';
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
export function createReplacer(allData: RichTextData, meta: MetaData, renderMacroInEditMode = true, customReplacer?: Replacer): (domNode: DOMNode) => ReplacerResult {
|
|
14
13
|
// eslint-disable-next-line react/display-name
|
|
15
|
-
|
|
14
|
+
const replacerFn = (domNode: DOMNode): ReplacerResult => {
|
|
16
15
|
if (domNode.type !== ElementType.Tag) {
|
|
17
16
|
return domNode;
|
|
18
17
|
}
|
|
@@ -41,8 +40,8 @@ export function createReplacer(allData: RichTextData, meta: MetaData, renderMacr
|
|
|
41
40
|
const href = el.attribs['href'];
|
|
42
41
|
|
|
43
42
|
if (ref && href) {
|
|
44
|
-
const
|
|
45
|
-
return <Link href={getUrl(href, meta)}>{
|
|
43
|
+
const domNodes = el.children as DOMNode[];
|
|
44
|
+
return <Link href={getUrl(href, meta)}>{domToReact(domNodes, {replace: replacerFn})}</Link>;
|
|
46
45
|
}
|
|
47
46
|
break;
|
|
48
47
|
case UrlProcessor.MACRO_TAG:
|
|
@@ -63,6 +62,7 @@ export function createReplacer(allData: RichTextData, meta: MetaData, renderMacr
|
|
|
63
62
|
}
|
|
64
63
|
return el;
|
|
65
64
|
};
|
|
65
|
+
return replacerFn;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const RichTextView = ({className, tag, data, meta, renderMacroInEditMode, customReplacer}: RichTextViewProps) => {
|
|
@@ -93,7 +93,7 @@ export interface RegionsProps {
|
|
|
93
93
|
meta: MetaData;
|
|
94
94
|
}
|
|
95
95
|
export type Replacer = (domNode: DOMNode, data: RichTextData, meta: MetaData, renderMacroInEditMode: boolean) => ReplacerResult;
|
|
96
|
-
export type ReplacerResult = JSX.Element |
|
|
96
|
+
export type ReplacerResult = JSX.Element | DOMNode;
|
|
97
97
|
export interface RichTextViewProps {
|
|
98
98
|
data: RichTextData;
|
|
99
99
|
meta: MetaData;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import Negotiator from 'negotiator';
|
|
2
|
-
import { match as localeMatcher } from '@formatjs/intl-localematcher';
|
|
3
1
|
import { PROJECT_ID_HEADER } from '../common/constants';
|
|
4
2
|
import { getLocaleMappings } from './getLocaleMappings';
|
|
5
3
|
import { getLocaleMappingByProjectId } from './getLocaleMappingByProjectId';
|
|
6
4
|
export function getRequestLocaleInfo(context) {
|
|
7
|
-
var _a, _b
|
|
5
|
+
var _a, _b;
|
|
8
6
|
let locale;
|
|
9
7
|
const configs = getLocaleMappings();
|
|
10
8
|
const locales = Object.keys(configs);
|
|
@@ -15,10 +13,15 @@ export function getRequestLocaleInfo(context) {
|
|
|
15
13
|
}
|
|
16
14
|
else {
|
|
17
15
|
locale = context.locale;
|
|
16
|
+
/* Disabled to prevent situation when www.site.com redirects to www.site.com/no when accept-header is set to 'no'
|
|
17
|
+
|
|
18
18
|
if (!locale) {
|
|
19
|
-
const acceptLang =
|
|
20
|
-
const langs = new Negotiator({
|
|
19
|
+
const acceptLang = context.headers?.get('accept-language') || '';
|
|
20
|
+
const langs = new Negotiator({headers: {'accept-language': acceptLang}}).languages();
|
|
21
21
|
locale = localeMatcher(langs, locales, defaultLocale);
|
|
22
|
+
}*/
|
|
23
|
+
if (!locale) {
|
|
24
|
+
locale = defaultLocale;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
return { locale, locales, defaultLocale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRequestLocaleInfo.js","sourceRoot":"","sources":["../src/utils/getRequestLocaleInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRequestLocaleInfo.js","sourceRoot":"","sources":["../src/utils/getRequestLocaleInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,2BAA2B,EAAC,MAAM,+BAA+B,CAAC;AAG1E,MAAM,UAAU,oBAAoB,CAAC,OAAgB;;IACjD,IAAI,MAAc,CAAC;IACnB,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,OAAO,0CAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC1D,IAAI,SAAS,EAAE,CAAC;QACZ,MAAM,GAAG,MAAA,2BAA2B,CAAC,SAAS,EAAE,KAAK,CAAC,0CAAE,MAAM,CAAC;IAEnE,CAAC;SAAM,CAAC;QACJ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACxB;;;;;;WAMG;QACH,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,GAAG,aAAa,CAAC;QAC3B,CAAC;IACL,CAAC;IACD,OAAO,EAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAC,CAAC;AAC5C,CAAC"}
|
package/views/RichTextView.jsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { getUrl, UrlProcessor } from '../common/UrlProcessor';
|
|
2
|
-
import HTMLReactParser from 'html-react-parser';
|
|
2
|
+
import HTMLReactParser, { domToReact } from 'html-react-parser';
|
|
3
3
|
import { ElementType } from 'domelementtype';
|
|
4
4
|
import BaseMacro from './BaseMacro';
|
|
5
5
|
import Link from 'next/link';
|
|
6
6
|
export function createReplacer(allData, meta, renderMacroInEditMode = true, customReplacer) {
|
|
7
7
|
// eslint-disable-next-line react/display-name
|
|
8
|
-
|
|
9
|
-
var _a;
|
|
8
|
+
const replacerFn = (domNode) => {
|
|
10
9
|
if (domNode.type !== ElementType.Tag) {
|
|
11
10
|
return domNode;
|
|
12
11
|
}
|
|
@@ -32,8 +31,8 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
32
31
|
ref = el.attribs[UrlProcessor.LINK_ATTR];
|
|
33
32
|
const href = el.attribs['href'];
|
|
34
33
|
if (ref && href) {
|
|
35
|
-
const
|
|
36
|
-
return <Link href={getUrl(href, meta)}>{
|
|
34
|
+
const domNodes = el.children;
|
|
35
|
+
return <Link href={getUrl(href, meta)}>{domToReact(domNodes, { replace: replacerFn })}</Link>;
|
|
37
36
|
}
|
|
38
37
|
break;
|
|
39
38
|
case UrlProcessor.MACRO_TAG:
|
|
@@ -54,6 +53,7 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
54
53
|
}
|
|
55
54
|
return el;
|
|
56
55
|
};
|
|
56
|
+
return replacerFn;
|
|
57
57
|
}
|
|
58
58
|
const RichTextView = ({ className, tag, data, meta, renderMacroInEditMode, customReplacer }) => {
|
|
59
59
|
const CustomTag = tag || 'section';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextView.jsx","sourceRoot":"","sources":["../src/views/RichTextView.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"RichTextView.jsx","sourceRoot":"","sources":["../src/views/RichTextView.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,eAAe,EAAE,EAAU,UAAU,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,UA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