@uniformdev/canvas-next-rsc 19.99.0 → 19.100.0
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/dist/UniformComposition-38e22896.d.ts +61 -0
- package/dist/UniformComposition-d178d865.d.ts +64 -0
- package/dist/actions/updateContext.d.ts +2 -0
- package/dist/actions/updateContext.js +17 -0
- package/dist/client/canvasClient.d.ts +5 -0
- package/dist/client/canvasClient.js +52 -0
- package/dist/client/manifestClient.d.ts +161 -0
- package/dist/client/manifestClient.js +32 -0
- package/dist/client/projectMapClient.d.ts +5 -0
- package/dist/client/projectMapClient.js +17 -0
- package/dist/client/routeClient.d.ts +5 -0
- package/dist/client/routeClient.js +56 -0
- package/dist/components/DefaultNotImplementedComponent.d.ts +2 -0
- package/dist/components/DefaultNotImplementedComponent.js +45 -0
- package/dist/components/GoogleTagManagerAnalytics.d.ts +3 -0
- package/dist/components/GoogleTagManagerAnalytics.js +44 -0
- package/dist/components/UniformComponent.d.ts +22 -0
- package/dist/components/UniformComponent.js +14 -0
- package/dist/components/UniformComposition.d.ts +35 -0
- package/dist/components/UniformComposition.js +60 -0
- package/dist/components/UniformContext.d.ts +11 -0
- package/dist/components/UniformContext.js +19 -0
- package/dist/components/UniformRichText.d.ts +38 -0
- package/dist/components/UniformRichText.js +15 -0
- package/dist/components/UniformRichTextNode.d.ts +10 -0
- package/dist/components/UniformRichTextNode.js +49 -0
- package/dist/components/UniformScript.d.ts +3 -0
- package/dist/components/UniformScript.js +73 -0
- package/dist/components/UniformSlot.d.ts +27 -0
- package/dist/components/UniformSlot.js +33 -0
- package/dist/components/UniformText.d.ts +14 -0
- package/dist/components/UniformText.js +9 -0
- package/dist/components/__tests__/evaluateComposition.spec.d.ts +1 -0
- package/dist/components/__tests__/evaluateComposition.spec.js +80 -0
- package/dist/components/convertComponentToProps.d.ts +14 -0
- package/dist/components/convertComponentToProps.js +22 -0
- package/dist/components/evaluateComposition.d.ts +15 -0
- package/dist/components/evaluateComposition.js +167 -0
- package/dist/components/getEnrichmentTags.d.ts +3 -0
- package/dist/components/getEnrichmentTags.js +13 -0
- package/dist/components/getUniformContext.d.ts +6 -0
- package/dist/components/getUniformContext.js +17 -0
- package/dist/components/nodes/HeadingRichTextNode.d.ts +2 -0
- package/dist/components/nodes/HeadingRichTextNode.js +6 -0
- package/dist/components/nodes/LinebreakRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinebreakRichTextNode.js +4 -0
- package/dist/components/nodes/LinkRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinkRichTextNode.js +6 -0
- package/dist/components/nodes/ListItemRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListItemRichTextNode.js +5 -0
- package/dist/components/nodes/ListRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListRichTextNode.js +6 -0
- package/dist/components/nodes/ParagraphRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ParagraphRichTextNode.js +6 -0
- package/dist/components/nodes/TabRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TabRichTextNode.js +4 -0
- package/dist/components/nodes/TextRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TextRichTextNode.js +9 -0
- package/dist/components/renderComponent.d.ts +15 -0
- package/dist/components/renderComponent.js +50 -0
- package/dist/components/resolvePath.d.ts +5 -0
- package/dist/components/resolvePath.js +34 -0
- package/dist/components/resolveRoute.d.ts +26 -0
- package/dist/components/resolveRoute.js +59 -0
- package/dist/components/retrieveRoute.d.ts +10 -0
- package/dist/components/retrieveRoute.js +70 -0
- package/dist/components/types.d.ts +11 -0
- package/dist/components/types.js +1 -0
- package/dist/config/helpers.d.ts +15 -0
- package/dist/config/helpers.js +20 -0
- package/dist/config/models.d.ts +43 -0
- package/dist/config/models.js +1 -0
- package/dist/config/uniform.server.config.d.ts +3 -0
- package/dist/config/uniform.server.config.js +3 -0
- package/dist/cookie/index.d.ts +12 -0
- package/dist/cookie/index.js +21 -0
- package/dist/handler/createPreviewGETRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewGETRouteHandler.js +43 -0
- package/dist/handler/createPreviewPOSTRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewPOSTRouteHandler.js +88 -0
- package/dist/handler/createUniformRouteHandler.d.ts +4 -0
- package/dist/handler/createUniformRouteHandler.js +10 -0
- package/dist/handler/helpers.d.ts +19 -0
- package/dist/handler/helpers.js +147 -0
- package/dist/handler/messages/handleCompositionChanged.d.ts +2 -0
- package/dist/handler/messages/handleCompositionChanged.js +9 -0
- package/dist/handler/messages/handleCompositionDeleted.d.ts +2 -0
- package/dist/handler/messages/handleCompositionDeleted.js +9 -0
- package/dist/handler/messages/handleCompositionPublished.d.ts +2 -0
- package/dist/handler/messages/handleCompositionPublished.js +9 -0
- package/dist/handler/messages/handleManifestPublished.d.ts +2 -0
- package/dist/handler/messages/handleManifestPublished.js +10 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.js +20 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.js +20 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +21 -0
- package/dist/handler/messages/handleRedirectDelete.d.ts +2 -0
- package/dist/handler/messages/handleRedirectDelete.js +14 -0
- package/dist/handler/messages/handleRedirectInsert.d.ts +2 -0
- package/dist/handler/messages/handleRedirectInsert.js +14 -0
- package/dist/handler/messages/handleRedirectUpdate.d.ts +2 -0
- package/dist/handler/messages/handleRedirectUpdate.js +14 -0
- package/dist/hooks/useForgetMe.d.ts +4 -0
- package/dist/hooks/useForgetMe.js +10 -0
- package/dist/hooks/useToggleConsent.d.ts +7 -0
- package/dist/hooks/useToggleConsent.js +22 -0
- package/dist/hooks/useUniformContext.d.ts +1 -0
- package/dist/hooks/useUniformContext.js +3 -0
- package/dist/models/index.d.ts +30 -0
- package/dist/models/index.js +1 -0
- package/dist/register/componentStore.d.ts +1 -0
- package/dist/register/componentStore.js +2 -0
- package/dist/register/componentStoreResolver.d.ts +2 -0
- package/dist/register/componentStoreResolver.js +5 -0
- package/dist/register/createComponentStore.d.ts +12 -0
- package/dist/register/createComponentStore.js +13 -0
- package/dist/register/createComponentStoreResolver.d.ts +9 -0
- package/dist/register/createComponentStoreResolver.js +9 -0
- package/dist/register/getTypeWithVariant.d.ts +1 -0
- package/dist/register/getTypeWithVariant.js +1 -0
- package/dist/register/registerUniformComponent.d.ts +6 -0
- package/dist/register/registerUniformComponent.js +8 -0
- package/dist/resolve/resolveChildren.d.ts +10 -0
- package/dist/resolve/resolveChildren.js +20 -0
- package/dist/score/index.d.ts +3 -0
- package/dist/score/index.js +114 -0
- package/dist/utils/__tests__/apply.spec.d.ts +1 -0
- package/dist/utils/__tests__/apply.spec.js +358 -0
- package/dist/utils/__tests__/diff.spec.d.ts +1 -0
- package/dist/utils/__tests__/diff.spec.js +394 -0
- package/dist/utils/apply.d.ts +6 -0
- package/dist/utils/apply.js +124 -0
- package/dist/utils/comp.d.ts +16 -0
- package/dist/utils/comp.js +47 -0
- package/dist/utils/diff.d.ts +44 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/draft.d.ts +11 -0
- package/dist/utils/draft.js +23 -0
- package/dist/utils/tag.d.ts +2 -0
- package/dist/utils/tag.js +7 -0
- package/dist/utils/url.d.ts +1 -0
- package/dist/utils/url.js +10 -0
- package/package.json +11 -11
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
import { CompositionResolvedGetResponse, ComponentInstance } from '@uniformdev/canvas';
|
|
4
|
+
import { PageParameters, ComponentProps, CompositionContext, AppDirectoryServerContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
5
|
+
|
|
6
|
+
type UniformStaticCompositionProps = {
|
|
7
|
+
/**
|
|
8
|
+
* How to render the composition.
|
|
9
|
+
*/
|
|
10
|
+
mode: 'static';
|
|
11
|
+
};
|
|
12
|
+
type UniformServerCompositionProps = {
|
|
13
|
+
/**
|
|
14
|
+
* How to render the composition.
|
|
15
|
+
*/
|
|
16
|
+
mode: 'server';
|
|
17
|
+
/**
|
|
18
|
+
* The Context instance to use for server-side rendering.
|
|
19
|
+
*/
|
|
20
|
+
serverContext?: AppDirectoryServerContext;
|
|
21
|
+
};
|
|
22
|
+
type UniformCompositionProps = PageParameters & {
|
|
23
|
+
composition?: CompositionResolvedGetResponse;
|
|
24
|
+
/**
|
|
25
|
+
* Function to map composition components to React components.
|
|
26
|
+
*/
|
|
27
|
+
resolveComponent: ResolveComponentFunction;
|
|
28
|
+
} & (UniformStaticCompositionProps | UniformServerCompositionProps);
|
|
29
|
+
declare const UniformComposition: React.FC<UniformCompositionProps>;
|
|
30
|
+
type ResolveComponentFunction = (options: {
|
|
31
|
+
component: ComponentInstance;
|
|
32
|
+
}) => ResolveComponentResult;
|
|
33
|
+
type ResolveComponentResult = {
|
|
34
|
+
component: ComponentType<ComponentProps<any, any>> | null;
|
|
35
|
+
includeContext?: boolean;
|
|
36
|
+
};
|
|
37
|
+
declare const resolveComposition: (props: Omit<ResolveComponentsOptions, 'slotName' | 'slotIndex' | 'target'> & {
|
|
38
|
+
composition: ComponentInstance;
|
|
39
|
+
compositionContext: CompositionContext;
|
|
40
|
+
}) => React$1.FunctionComponentElement<{
|
|
41
|
+
children?: ReactNode;
|
|
42
|
+
}> | null;
|
|
43
|
+
type ResolveComponentsOptions = {
|
|
44
|
+
serverContext?: AppDirectoryServerContext;
|
|
45
|
+
target: {
|
|
46
|
+
type: 'root';
|
|
47
|
+
composition: ComponentInstance;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'slot';
|
|
50
|
+
components: ComponentInstance[];
|
|
51
|
+
parent: ComponentInstance;
|
|
52
|
+
root: ComponentInstance;
|
|
53
|
+
};
|
|
54
|
+
slotName: string | undefined;
|
|
55
|
+
slotIndex: number | undefined;
|
|
56
|
+
resolveComponent: ResolveComponentFunction;
|
|
57
|
+
compositionContext: CompositionContext;
|
|
58
|
+
mode: UniformCompositionProps['mode'];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { ResolveComponentFunction as R, UniformCompositionProps as U, UniformComposition as a, ResolveComponentResult as b, resolveComposition as r };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
import { ResolvedRouteGetResponse, ComponentInstance } from '@uniformdev/canvas';
|
|
4
|
+
import { PageParameters, ComponentProps, CompositionContext, AppDirectoryServerContext } from '@uniformdev/canvas-next-rsc-shared';
|
|
5
|
+
|
|
6
|
+
type UniformStaticCompositionProps = {
|
|
7
|
+
/**
|
|
8
|
+
* How to render the composition.
|
|
9
|
+
*/
|
|
10
|
+
mode: 'static';
|
|
11
|
+
};
|
|
12
|
+
type UniformServerCompositionProps = {
|
|
13
|
+
/**
|
|
14
|
+
* How to render the composition.
|
|
15
|
+
*/
|
|
16
|
+
mode: 'server';
|
|
17
|
+
/**
|
|
18
|
+
* The Context instance to use for server-side rendering.
|
|
19
|
+
*/
|
|
20
|
+
serverContext?: AppDirectoryServerContext;
|
|
21
|
+
};
|
|
22
|
+
type UniformCompositionProps = PageParameters & {
|
|
23
|
+
/**
|
|
24
|
+
* The route data to render.
|
|
25
|
+
*/
|
|
26
|
+
route: ResolvedRouteGetResponse | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Function to map composition components to React components.
|
|
29
|
+
*/
|
|
30
|
+
resolveComponent: ResolveComponentFunction;
|
|
31
|
+
} & (UniformStaticCompositionProps | UniformServerCompositionProps);
|
|
32
|
+
declare const UniformComposition: React.FC<UniformCompositionProps>;
|
|
33
|
+
type ResolveComponentFunction = (options: {
|
|
34
|
+
component: ComponentInstance;
|
|
35
|
+
}) => ResolveComponentResult;
|
|
36
|
+
type ResolveComponentResult = {
|
|
37
|
+
component: ComponentType<ComponentProps<any, any>> | null;
|
|
38
|
+
includeContext?: boolean;
|
|
39
|
+
};
|
|
40
|
+
declare const resolveComposition: (props: Omit<ResolveComponentsOptions, 'slotName' | 'slotIndex' | 'target'> & {
|
|
41
|
+
composition: ComponentInstance;
|
|
42
|
+
compositionContext: CompositionContext;
|
|
43
|
+
}) => React$1.FunctionComponentElement<{
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
}> | null;
|
|
46
|
+
type ResolveComponentsOptions = {
|
|
47
|
+
serverContext?: AppDirectoryServerContext;
|
|
48
|
+
target: {
|
|
49
|
+
type: 'root';
|
|
50
|
+
composition: ComponentInstance;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'slot';
|
|
53
|
+
components: ComponentInstance[];
|
|
54
|
+
parent: ComponentInstance;
|
|
55
|
+
root: ComponentInstance;
|
|
56
|
+
};
|
|
57
|
+
slotName: string | undefined;
|
|
58
|
+
slotIndex: number | undefined;
|
|
59
|
+
resolveComponent: ResolveComponentFunction;
|
|
60
|
+
compositionContext: CompositionContext;
|
|
61
|
+
mode: UniformCompositionProps['mode'];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { ResolveComponentFunction as R, UniformCompositionProps as U, UniformComposition as a, ResolveComponentResult as b, resolveComposition as r };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
|
|
3
|
+
import { cookies } from 'next/headers';
|
|
4
|
+
import { getUniformContext } from '../components/getUniformContext';
|
|
5
|
+
import { serializeCookie } from '../score';
|
|
6
|
+
export const updateContextAction = async (options) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const context = await getUniformContext({
|
|
9
|
+
cookieValue: (_a = cookies().get(UNIFORM_DEFAULT_COOKIE_NAME)) === null || _a === void 0 ? void 0 : _a.value,
|
|
10
|
+
});
|
|
11
|
+
if (!context.storage.data.consent) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
await context.update(options);
|
|
15
|
+
const scoreCookie = serializeCookie(context.storage.data);
|
|
16
|
+
cookies().set(UNIFORM_DEFAULT_COOKIE_NAME, scoreCookie);
|
|
17
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CanvasClient } from '@uniformdev/canvas';
|
|
2
|
+
import { buildCompositionTag } from '../utils/tag';
|
|
3
|
+
export const getCanvasClient = (options) => {
|
|
4
|
+
return new CanvasClient({
|
|
5
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
6
|
+
apiHost: process.env.UNIFORM_API_HOST,
|
|
7
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
8
|
+
edgeApiHost: process.env.UNIFORM_EDGE_API_HOST,
|
|
9
|
+
fetch: (req, init) => {
|
|
10
|
+
let requestedUrl;
|
|
11
|
+
if (typeof req === 'string') {
|
|
12
|
+
requestedUrl = new URL(req);
|
|
13
|
+
}
|
|
14
|
+
else if (req instanceof URL) {
|
|
15
|
+
requestedUrl = req;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
requestedUrl = new URL(req.url);
|
|
19
|
+
}
|
|
20
|
+
const tags = [];
|
|
21
|
+
if (requestedUrl) {
|
|
22
|
+
// this is here so this code breaks if parameters change here
|
|
23
|
+
const compositionIdKey = 'compositionId';
|
|
24
|
+
const compositionIdsKey = 'compositionIDs';
|
|
25
|
+
const compositionId = requestedUrl.searchParams.get(compositionIdKey);
|
|
26
|
+
const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
|
|
27
|
+
if (compositionId) {
|
|
28
|
+
tags.push(buildCompositionTag(compositionId));
|
|
29
|
+
}
|
|
30
|
+
if (compositionIds) {
|
|
31
|
+
const ids = compositionIds.split(',');
|
|
32
|
+
for (let i = 0; i < ids.length; i++) {
|
|
33
|
+
tags.push(buildCompositionTag(ids[i]));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let revalidate = options === null || options === void 0 ? void 0 : options.revalidate;
|
|
38
|
+
let noCache = false;
|
|
39
|
+
if (revalidate === -1) {
|
|
40
|
+
noCache = true;
|
|
41
|
+
revalidate = undefined;
|
|
42
|
+
}
|
|
43
|
+
return fetch(req, {
|
|
44
|
+
...init,
|
|
45
|
+
cache: noCache ? 'no-cache' : 'force-cache',
|
|
46
|
+
next: {
|
|
47
|
+
revalidate,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { ManifestClient } from '@uniformdev/context/api';
|
|
2
|
+
export type GetManifestClientOptions = {
|
|
3
|
+
revalidate?: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const getManifestClient: (options?: GetManifestClientOptions) => ManifestClient;
|
|
6
|
+
export declare const getManifestFromApi: (options: {
|
|
7
|
+
searchParams: {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
project: {
|
|
12
|
+
id?: string | undefined;
|
|
13
|
+
name?: string | undefined;
|
|
14
|
+
ui_version?: number | undefined;
|
|
15
|
+
pz?: {
|
|
16
|
+
sig?: {
|
|
17
|
+
[key: string]: {
|
|
18
|
+
str: number;
|
|
19
|
+
cap: number;
|
|
20
|
+
dur: "p" | "s" | "t";
|
|
21
|
+
crit: {
|
|
22
|
+
type: "G";
|
|
23
|
+
op?: "&" | "|" | undefined;
|
|
24
|
+
clauses: ({
|
|
25
|
+
type: "G";
|
|
26
|
+
op?: "&" | "|" | undefined;
|
|
27
|
+
clauses: (any | {
|
|
28
|
+
type: "CK";
|
|
29
|
+
cookieName: string;
|
|
30
|
+
match: {
|
|
31
|
+
rhs: string;
|
|
32
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
33
|
+
cs?: boolean | undefined;
|
|
34
|
+
} | {
|
|
35
|
+
op: "*" | "!*";
|
|
36
|
+
};
|
|
37
|
+
} | {
|
|
38
|
+
type: "QS";
|
|
39
|
+
queryName: string;
|
|
40
|
+
match: {
|
|
41
|
+
rhs: string;
|
|
42
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
43
|
+
cs?: boolean | undefined;
|
|
44
|
+
} | {
|
|
45
|
+
op: "*" | "!*";
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
type: "QK";
|
|
49
|
+
key: string;
|
|
50
|
+
match: {
|
|
51
|
+
rhs: string;
|
|
52
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
53
|
+
cs?: boolean | undefined;
|
|
54
|
+
} | {
|
|
55
|
+
op: "*" | "!*";
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
type: "EVT";
|
|
59
|
+
event: {
|
|
60
|
+
rhs: string;
|
|
61
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
62
|
+
cs?: boolean | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
op: "*" | "!*";
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
type: "PV";
|
|
68
|
+
path: {
|
|
69
|
+
rhs: string;
|
|
70
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
71
|
+
cs?: boolean | undefined;
|
|
72
|
+
} | {
|
|
73
|
+
op: "*" | "!*";
|
|
74
|
+
};
|
|
75
|
+
} | {
|
|
76
|
+
type: "PVC";
|
|
77
|
+
match: {
|
|
78
|
+
rhs: number;
|
|
79
|
+
op: "=" | "!=" | "<" | ">";
|
|
80
|
+
};
|
|
81
|
+
})[];
|
|
82
|
+
} | {
|
|
83
|
+
type: "CK";
|
|
84
|
+
cookieName: string;
|
|
85
|
+
match: {
|
|
86
|
+
rhs: string;
|
|
87
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
88
|
+
cs?: boolean | undefined;
|
|
89
|
+
} | {
|
|
90
|
+
op: "*" | "!*";
|
|
91
|
+
};
|
|
92
|
+
} | {
|
|
93
|
+
type: "QS";
|
|
94
|
+
queryName: string;
|
|
95
|
+
match: {
|
|
96
|
+
rhs: string;
|
|
97
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
98
|
+
cs?: boolean | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
op: "*" | "!*";
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
type: "QK";
|
|
104
|
+
key: string;
|
|
105
|
+
match: {
|
|
106
|
+
rhs: string;
|
|
107
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
108
|
+
cs?: boolean | undefined;
|
|
109
|
+
} | {
|
|
110
|
+
op: "*" | "!*";
|
|
111
|
+
};
|
|
112
|
+
} | {
|
|
113
|
+
type: "EVT";
|
|
114
|
+
event: {
|
|
115
|
+
rhs: string;
|
|
116
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
117
|
+
cs?: boolean | undefined;
|
|
118
|
+
} | {
|
|
119
|
+
op: "*" | "!*";
|
|
120
|
+
};
|
|
121
|
+
} | {
|
|
122
|
+
type: "PV";
|
|
123
|
+
path: {
|
|
124
|
+
rhs: string;
|
|
125
|
+
op: "~" | "=" | "//" | "!=" | "!~" | "!//";
|
|
126
|
+
cs?: boolean | undefined;
|
|
127
|
+
} | {
|
|
128
|
+
op: "*" | "!*";
|
|
129
|
+
};
|
|
130
|
+
} | {
|
|
131
|
+
type: "PVC";
|
|
132
|
+
match: {
|
|
133
|
+
rhs: number;
|
|
134
|
+
op: "=" | "!=" | "<" | ">";
|
|
135
|
+
};
|
|
136
|
+
})[];
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
} | undefined;
|
|
140
|
+
enr?: {
|
|
141
|
+
[key: string]: {
|
|
142
|
+
cap: number;
|
|
143
|
+
};
|
|
144
|
+
} | undefined;
|
|
145
|
+
agg?: {
|
|
146
|
+
[key: string]: {
|
|
147
|
+
inputs: {
|
|
148
|
+
dim: string;
|
|
149
|
+
sign?: "-" | "+" | "c" | undefined;
|
|
150
|
+
}[];
|
|
151
|
+
};
|
|
152
|
+
} | undefined;
|
|
153
|
+
control?: number | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
test?: {
|
|
156
|
+
[key: string]: {
|
|
157
|
+
wv?: string | undefined;
|
|
158
|
+
};
|
|
159
|
+
} | undefined;
|
|
160
|
+
};
|
|
161
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ManifestClient } from '@uniformdev/context/api';
|
|
2
|
+
import { getManifestRevalidateInterval } from '../config/helpers';
|
|
3
|
+
export const getManifestClient = (options) => {
|
|
4
|
+
const manifestClient = new ManifestClient({
|
|
5
|
+
apiHost: process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL,
|
|
6
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
7
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
8
|
+
fetch: (req, init) => {
|
|
9
|
+
let revalidate = options === null || options === void 0 ? void 0 : options.revalidate;
|
|
10
|
+
let noCache = false;
|
|
11
|
+
if (revalidate === -1) {
|
|
12
|
+
noCache = true;
|
|
13
|
+
revalidate = undefined;
|
|
14
|
+
}
|
|
15
|
+
return fetch(req, {
|
|
16
|
+
...init,
|
|
17
|
+
cache: noCache ? 'no-cache' : 'force-cache',
|
|
18
|
+
next: {
|
|
19
|
+
revalidate,
|
|
20
|
+
tags: ['manifest'],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return manifestClient;
|
|
26
|
+
};
|
|
27
|
+
export const getManifestFromApi = (options) => {
|
|
28
|
+
const manifestClient = getManifestClient({
|
|
29
|
+
revalidate: getManifestRevalidateInterval(options),
|
|
30
|
+
});
|
|
31
|
+
return manifestClient.get();
|
|
32
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProjectMapClient } from '@uniformdev/project-map';
|
|
2
|
+
export const getProjectMapClient = (options) => {
|
|
3
|
+
const manifestClient = new ProjectMapClient({
|
|
4
|
+
apiHost: process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL,
|
|
5
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
6
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
7
|
+
fetch: (req, init) => {
|
|
8
|
+
return fetch(req, {
|
|
9
|
+
...init,
|
|
10
|
+
next: {
|
|
11
|
+
revalidate: options === null || options === void 0 ? void 0 : options.revalidate,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
return manifestClient;
|
|
17
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RouteClient } from '@uniformdev/canvas';
|
|
2
|
+
import { buildPathTag } from '../utils/tag';
|
|
3
|
+
export const getRouteClient = (options) => {
|
|
4
|
+
const client = new RouteClient({
|
|
5
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
6
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
7
|
+
edgeApiHost: process.env.UNIFORM_EDGE_API_HOST,
|
|
8
|
+
fetch: (req, init) => {
|
|
9
|
+
let requestedUrl;
|
|
10
|
+
if (typeof req === 'string') {
|
|
11
|
+
requestedUrl = new URL(req);
|
|
12
|
+
}
|
|
13
|
+
else if (req instanceof URL) {
|
|
14
|
+
requestedUrl = req;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
requestedUrl = new URL(req.url);
|
|
18
|
+
}
|
|
19
|
+
const tags = [];
|
|
20
|
+
if (requestedUrl) {
|
|
21
|
+
// this is here so this code breaks if parameters change here
|
|
22
|
+
const pathKey = 'path';
|
|
23
|
+
const path = requestedUrl.searchParams.get(pathKey);
|
|
24
|
+
if (path) {
|
|
25
|
+
// at this point, we do not know if this path is dynamic or not
|
|
26
|
+
// so apply each segment as a tag so we can clear any segment, ie:
|
|
27
|
+
// /authors/alex would add /authors and /authors/alex as tags
|
|
28
|
+
const pieces = path.split('/');
|
|
29
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
30
|
+
const segmentPieces = pieces.slice(0, i + 1);
|
|
31
|
+
const segment = segmentPieces.join('/');
|
|
32
|
+
tags.push(buildPathTag(segment));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let revalidate;
|
|
37
|
+
let noCache = false;
|
|
38
|
+
if (options === null || options === void 0 ? void 0 : options.revalidate) {
|
|
39
|
+
revalidate = options.revalidate;
|
|
40
|
+
}
|
|
41
|
+
if (revalidate === -1) {
|
|
42
|
+
noCache = true;
|
|
43
|
+
revalidate = undefined;
|
|
44
|
+
}
|
|
45
|
+
return fetch(req, {
|
|
46
|
+
...init,
|
|
47
|
+
cache: noCache ? 'no-cache' : 'force-cache',
|
|
48
|
+
next: {
|
|
49
|
+
revalidate,
|
|
50
|
+
tags: tags.length ? tags : undefined,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return client;
|
|
56
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CANVAS_LOCALIZATION_TYPE } from '@uniformdev/canvas';
|
|
3
|
+
const wrapperStyles = {
|
|
4
|
+
display: 'flex',
|
|
5
|
+
flexDirection: 'column',
|
|
6
|
+
gap: '0.5rem',
|
|
7
|
+
borderLeft: '4px solid #e42535',
|
|
8
|
+
padding: '16px',
|
|
9
|
+
fontSize: '16px',
|
|
10
|
+
borderRadius: '0 8px 8px 0',
|
|
11
|
+
margin: '8px',
|
|
12
|
+
backgroundColor: 'rgba(255, 255, 255, 0.45)',
|
|
13
|
+
color: '#1d3557',
|
|
14
|
+
};
|
|
15
|
+
export function DefaultNotImplementedComponent(props) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const componentType = (_a = props.component) === null || _a === void 0 ? void 0 : _a.type;
|
|
18
|
+
if (!componentType) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (componentType === CANVAS_LOCALIZATION_TYPE) {
|
|
22
|
+
return (_jsx("div", { style: wrapperStyles, children: _jsxs("p", { children: ["Seems like localization is not enabled in your application. Please read our documentation on how to", ' ', _jsx("a", { href: "https://docs.uniform.app/guides/composition/localization#activate-front-end", target: "_blank", style: { fontWeight: 'bolder', textDecoration: 'underline' }, rel: "noreferrer", children: "enable localization in your front-end application." })] }) }));
|
|
23
|
+
}
|
|
24
|
+
const proposedFileName = `${componentType[0].toUpperCase()}${componentType.substring(1)}`;
|
|
25
|
+
const probableProps = Object.keys((_b = props.component.parameters) !== null && _b !== void 0 ? _b : {});
|
|
26
|
+
const probableSlots = Object.keys((_c = props.component.slots) !== null && _c !== void 0 ? _c : {});
|
|
27
|
+
return (_jsxs("div", { style: wrapperStyles, children: [_jsx("h2", { style: { fontSize: '1.2rem' }, children: "Unknown Component" }), _jsxs("p", { children: ["Received request from Uniform to render a component with the public ID: ", _jsx("code", { children: componentType }), "."] }), _jsxs("p", { children: [_jsx("code", { children: "<UniformComposition />" }), " does not have ", _jsx("code", { children: componentType }), " mapped to a React component yet."] }), _jsx("p", { children: "To teach your app how to render this component:" }), ' ', _jsxs("ul", { style: {
|
|
28
|
+
listStyleType: 'disc',
|
|
29
|
+
marginLeft: '1rem',
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'column',
|
|
32
|
+
gap: '0.5rem',
|
|
33
|
+
}, children: [_jsxs("li", { children: ["Create a React component and register it with Uniform, for example", _jsx("pre", { children: `function ${proposedFileName}(${probableProps.length > 0 ? `{ ${probableProps.join(', ')} }` : ''}) {
|
|
34
|
+
return (
|
|
35
|
+
<div>
|
|
36
|
+
${proposedFileName}!
|
|
37
|
+
${probableSlots.length > 0
|
|
38
|
+
? probableSlots.map((slot) => `<UniformSlot name="${slot}" />`).join('\n ')
|
|
39
|
+
: ''}
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
registerUniformComponent({ type: "${componentType}", component: ${proposedFileName} })` }), _jsxs("details", { children: [_jsx("summary", { style: { cursor: 'pointer' }, children: "Props that your React component will receive" }), _jsx("pre", { children: JSON.stringify(props, null, 2) })] })] }), _jsxs("li", { children: ["Import the component into the file where ", _jsx("code", { children: "<UniformComposition />" }), " is defined, for example ", _jsx("pre", { children: `import "../components/${proposedFileName}.tsx"` })] })] }), ' ', _jsxs("p", { children: ["Need more help?", ' ', _jsx("a", { href: "https://docs.uniform.app/docs/guides/composition/rendering", target: "_blank", rel: "noreferrer", style: { textDecoration: 'underline' }, children: "Check out the documentation." })] })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import Script from 'next/script';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { useUniformContext } from '../hooks/useUniformContext';
|
|
6
|
+
const isGtagConfigured = () => {
|
|
7
|
+
return typeof window !== 'undefined' && typeof window.gtag === 'function';
|
|
8
|
+
};
|
|
9
|
+
export const GoogleTagManagerAnalytics = (props) => {
|
|
10
|
+
const { seenComponents } = useUniformContext();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!(seenComponents === null || seenComponents === void 0 ? void 0 : seenComponents.length)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!isGtagConfigured()) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.warn('Google Tag Manager is not configured. Please add the gtag script to your site.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
seenComponents.forEach((component) => {
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
22
|
+
if (component.type === 'personalization') {
|
|
23
|
+
(_b = (_a = window).gtag) === null || _b === void 0 ? void 0 : _b.call(_a, 'event', component.id, {
|
|
24
|
+
event_category: 'Uniform Personalization',
|
|
25
|
+
event_label: component.variants.join(', '),
|
|
26
|
+
is_control_group: component.control ? 1 : 0,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (component.type === 'test') {
|
|
30
|
+
(_d = (_c = window).gtag) === null || _d === void 0 ? void 0 : _d.call(_c, 'event', component.id, {
|
|
31
|
+
event_category: 'Uniform AB Testing',
|
|
32
|
+
event_label: (_e = component.variant) !== null && _e !== void 0 ? _e : 'No Variant',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}, [seenComponents]);
|
|
37
|
+
return (_jsx(_Fragment, { children: Boolean(props === null || props === void 0 ? void 0 : props.measurementId) && (_jsxs(_Fragment, { children: [_jsx(Script, { src: `https://www.googletagmanager.com/gtag/js?id=${props.measurementId}`, strategy: "afterInteractive" }), _jsx(Script, { id: "google-analytics", strategy: "afterInteractive", children: `
|
|
38
|
+
window.dataLayer = window.dataLayer || [];
|
|
39
|
+
function gtag(){window.dataLayer.push(arguments);}
|
|
40
|
+
gtag('js', new Date());
|
|
41
|
+
|
|
42
|
+
gtag('config', '${props.measurementId}');
|
|
43
|
+
` })] })) }));
|
|
44
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ComponentInstance, type RootComponentInstance } from '@uniformdev/canvas';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export type CompositionContext = {
|
|
4
|
+
composition: RootComponentInstance;
|
|
5
|
+
path: string;
|
|
6
|
+
state?: number;
|
|
7
|
+
searchParams: {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type ComponentProps<TProps = unknown> = TProps & {
|
|
12
|
+
component: ComponentInstance;
|
|
13
|
+
context: CompositionContext;
|
|
14
|
+
};
|
|
15
|
+
export type UniformComponentProps<TRenderProps = unknown> = {
|
|
16
|
+
data: ComponentInstance;
|
|
17
|
+
context: CompositionContext;
|
|
18
|
+
children?: ReactNode | ((props: ComponentProps<TRenderProps>) => JSX.Element);
|
|
19
|
+
};
|
|
20
|
+
export declare function UniformComponent({ data, children, context }: UniformComponentProps): import("react").FunctionComponentElement<{
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createElement, Fragment } from 'react';
|
|
2
|
+
import { componentStoreResolver } from '../register/componentStoreResolver';
|
|
3
|
+
import { resolveChildren } from '../resolve/resolveChildren';
|
|
4
|
+
export function UniformComponent({ data, children, context }) {
|
|
5
|
+
const resolvedChildren = resolveChildren({
|
|
6
|
+
children,
|
|
7
|
+
data,
|
|
8
|
+
context,
|
|
9
|
+
hasParentLayout: false,
|
|
10
|
+
resolveRenderer: componentStoreResolver,
|
|
11
|
+
});
|
|
12
|
+
const childrenToRender = [resolvedChildren];
|
|
13
|
+
return createElement(Fragment, {}, childrenToRender);
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type SuspenseOptions = {
|
|
3
|
+
mode: 'off';
|
|
4
|
+
} | {
|
|
5
|
+
mode: 'fallback';
|
|
6
|
+
fallback: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type UniformCompositionProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The params object from Next.js router. Used to resolve a composition.
|
|
11
|
+
*/
|
|
12
|
+
params: {
|
|
13
|
+
slug: string | string[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The searchParams object from Next.js router. Used for signal evaluation.
|
|
17
|
+
*/
|
|
18
|
+
searchParams?: {
|
|
19
|
+
[key: string]: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Behavior of root Suspense component.
|
|
23
|
+
*/
|
|
24
|
+
suspense?: {
|
|
25
|
+
mode: 'off';
|
|
26
|
+
} | {
|
|
27
|
+
mode: 'fallback';
|
|
28
|
+
fallback: React.ReactNode;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The children of the UniformComposition component.
|
|
32
|
+
*/
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
};
|
|
35
|
+
export declare const UniformComposition: ({ suspense, ...props }: UniformCompositionProps) => JSX.Element;
|