@uniformdev/canvas-next-rsc-shared 19.55.2-alpha.14
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/LICENSE.txt +2 -0
- package/README.md +5 -0
- package/dist/index.d.mts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.esm.js +92 -0
- package/dist/index.js +120 -0
- package/dist/index.mjs +92 -0
- package/package.json +50 -0
package/LICENSE.txt
ADDED
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
2
|
+
import { ComponentInstance, RouteGetResponseComposition, RootComponentInstance } from '@uniformdev/canvas';
|
|
3
|
+
import { ContextInstance, ContextState } from '@uniformdev/context';
|
|
4
|
+
import { PropsWithChildren } from 'react';
|
|
5
|
+
|
|
6
|
+
type PageParameters = {
|
|
7
|
+
/**
|
|
8
|
+
* The params object from Next.js router. Used to resolve a composition.
|
|
9
|
+
*/
|
|
10
|
+
params: {
|
|
11
|
+
slug?: string | string[];
|
|
12
|
+
path?: string | string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The searchParams object from Next.js router. Used for signal evaluation.
|
|
16
|
+
*/
|
|
17
|
+
searchParams?: {
|
|
18
|
+
[key: string]: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type SlotDefinition = {
|
|
22
|
+
name: string;
|
|
23
|
+
items: PropsWithChildren['children'][];
|
|
24
|
+
};
|
|
25
|
+
type ComponentProps<TProps = unknown, TSlotNames extends string = string> = TProps & {
|
|
26
|
+
component: ComponentInstance;
|
|
27
|
+
context: CompositionContext;
|
|
28
|
+
slots: Record<TSlotNames, SlotDefinition>;
|
|
29
|
+
};
|
|
30
|
+
type CompositionContext = Omit<RouteGetResponseComposition, 'compositionApiResponse'> & {
|
|
31
|
+
composition: RootComponentInstance;
|
|
32
|
+
path: string;
|
|
33
|
+
state?: number;
|
|
34
|
+
searchParams: {
|
|
35
|
+
[key: string]: string | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
isDraftMode: boolean;
|
|
38
|
+
isContextualEditing: boolean;
|
|
39
|
+
};
|
|
40
|
+
type AppDirectoryContext = Omit<ContextInstance, 'update'> & {
|
|
41
|
+
update: (update: Partial<AppDirectoryContextState>) => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
type AppDirectoryContextState = Omit<ContextState, 'url'> & PageParameters;
|
|
44
|
+
type AppDirectoryServerContext = Omit<AppDirectoryContext, 'update'> & {
|
|
45
|
+
/**
|
|
46
|
+
* Internal use only. Please use `ContextUpdateTransfer` to handle any Context updates.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated
|
|
49
|
+
*/
|
|
50
|
+
__INTERNAL__: {
|
|
51
|
+
update: AppDirectoryContext['update'];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type PersonalizeProps = {
|
|
56
|
+
trackingEventName: string;
|
|
57
|
+
count: number | undefined;
|
|
58
|
+
};
|
|
59
|
+
type PersonalizeWithContextComponentProps = ComponentProps<PersonalizeProps> & {
|
|
60
|
+
contextInstance: AppDirectoryServerContext;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
declare const runPersonalization: ({ component, trackingEventName, count, contextInstance, }: PersonalizeProps & {
|
|
64
|
+
component: _uniformdev_canvas.ComponentInstance;
|
|
65
|
+
context: CompositionContext;
|
|
66
|
+
slots: Record<string, SlotDefinition>;
|
|
67
|
+
} & {
|
|
68
|
+
contextInstance: Pick<ContextInstance, 'personalize'> | undefined;
|
|
69
|
+
}) => {
|
|
70
|
+
indexes: number[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type TestProps = {
|
|
74
|
+
test: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
declare const runTest: ({ test, component, contextInstance, }: TestProps & {
|
|
78
|
+
component: _uniformdev_canvas.ComponentInstance;
|
|
79
|
+
context: CompositionContext;
|
|
80
|
+
slots: Record<string, SlotDefinition>;
|
|
81
|
+
} & {
|
|
82
|
+
contextInstance: Pick<ContextInstance, 'test'> | undefined;
|
|
83
|
+
}) => {
|
|
84
|
+
index: number | null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { AppDirectoryContext, AppDirectoryContextState, AppDirectoryServerContext, ComponentProps, CompositionContext, PageParameters, PersonalizeProps, PersonalizeWithContextComponentProps, SlotDefinition, TestProps, runPersonalization, runTest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as _uniformdev_canvas from '@uniformdev/canvas';
|
|
2
|
+
import { ComponentInstance, RouteGetResponseComposition, RootComponentInstance } from '@uniformdev/canvas';
|
|
3
|
+
import { ContextInstance, ContextState } from '@uniformdev/context';
|
|
4
|
+
import { PropsWithChildren } from 'react';
|
|
5
|
+
|
|
6
|
+
type PageParameters = {
|
|
7
|
+
/**
|
|
8
|
+
* The params object from Next.js router. Used to resolve a composition.
|
|
9
|
+
*/
|
|
10
|
+
params: {
|
|
11
|
+
slug?: string | string[];
|
|
12
|
+
path?: string | string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The searchParams object from Next.js router. Used for signal evaluation.
|
|
16
|
+
*/
|
|
17
|
+
searchParams?: {
|
|
18
|
+
[key: string]: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type SlotDefinition = {
|
|
22
|
+
name: string;
|
|
23
|
+
items: PropsWithChildren['children'][];
|
|
24
|
+
};
|
|
25
|
+
type ComponentProps<TProps = unknown, TSlotNames extends string = string> = TProps & {
|
|
26
|
+
component: ComponentInstance;
|
|
27
|
+
context: CompositionContext;
|
|
28
|
+
slots: Record<TSlotNames, SlotDefinition>;
|
|
29
|
+
};
|
|
30
|
+
type CompositionContext = Omit<RouteGetResponseComposition, 'compositionApiResponse'> & {
|
|
31
|
+
composition: RootComponentInstance;
|
|
32
|
+
path: string;
|
|
33
|
+
state?: number;
|
|
34
|
+
searchParams: {
|
|
35
|
+
[key: string]: string | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
isDraftMode: boolean;
|
|
38
|
+
isContextualEditing: boolean;
|
|
39
|
+
};
|
|
40
|
+
type AppDirectoryContext = Omit<ContextInstance, 'update'> & {
|
|
41
|
+
update: (update: Partial<AppDirectoryContextState>) => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
type AppDirectoryContextState = Omit<ContextState, 'url'> & PageParameters;
|
|
44
|
+
type AppDirectoryServerContext = Omit<AppDirectoryContext, 'update'> & {
|
|
45
|
+
/**
|
|
46
|
+
* Internal use only. Please use `ContextUpdateTransfer` to handle any Context updates.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated
|
|
49
|
+
*/
|
|
50
|
+
__INTERNAL__: {
|
|
51
|
+
update: AppDirectoryContext['update'];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type PersonalizeProps = {
|
|
56
|
+
trackingEventName: string;
|
|
57
|
+
count: number | undefined;
|
|
58
|
+
};
|
|
59
|
+
type PersonalizeWithContextComponentProps = ComponentProps<PersonalizeProps> & {
|
|
60
|
+
contextInstance: AppDirectoryServerContext;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
declare const runPersonalization: ({ component, trackingEventName, count, contextInstance, }: PersonalizeProps & {
|
|
64
|
+
component: _uniformdev_canvas.ComponentInstance;
|
|
65
|
+
context: CompositionContext;
|
|
66
|
+
slots: Record<string, SlotDefinition>;
|
|
67
|
+
} & {
|
|
68
|
+
contextInstance: Pick<ContextInstance, 'personalize'> | undefined;
|
|
69
|
+
}) => {
|
|
70
|
+
indexes: number[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type TestProps = {
|
|
74
|
+
test: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
declare const runTest: ({ test, component, contextInstance, }: TestProps & {
|
|
78
|
+
component: _uniformdev_canvas.ComponentInstance;
|
|
79
|
+
context: CompositionContext;
|
|
80
|
+
slots: Record<string, SlotDefinition>;
|
|
81
|
+
} & {
|
|
82
|
+
contextInstance: Pick<ContextInstance, 'test'> | undefined;
|
|
83
|
+
}) => {
|
|
84
|
+
index: number | null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { AppDirectoryContext, AppDirectoryContextState, AppDirectoryServerContext, ComponentProps, CompositionContext, PageParameters, PersonalizeProps, PersonalizeWithContextComponentProps, SlotDefinition, TestProps, runPersonalization, runTest };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/runPersonalization.ts
|
|
2
|
+
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
3
|
+
var runPersonalization = ({
|
|
4
|
+
component,
|
|
5
|
+
trackingEventName,
|
|
6
|
+
count,
|
|
7
|
+
contextInstance
|
|
8
|
+
}) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
11
|
+
const componentVariations = slot.map((v, i) => {
|
|
12
|
+
var _a2, _b2;
|
|
13
|
+
const contextTag = (_b2 = (_a2 = v.parameters) == null ? void 0 : _a2[CANVAS_PERSONALIZATION_PARAM]) == null ? void 0 : _b2.value;
|
|
14
|
+
const id = (contextTag == null ? void 0 : contextTag.name) || `pz-${i}-${v.type}`;
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
pz: contextTag,
|
|
18
|
+
index: i
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const indexes = [];
|
|
22
|
+
if (contextInstance) {
|
|
23
|
+
const { variations } = contextInstance.personalize({
|
|
24
|
+
name: trackingEventName,
|
|
25
|
+
take: count || 1,
|
|
26
|
+
variations: componentVariations
|
|
27
|
+
});
|
|
28
|
+
if (variations) {
|
|
29
|
+
for (let i = 0; i < variations.length; i++) {
|
|
30
|
+
indexes.push(variations[i].index);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
const defaults = [];
|
|
35
|
+
for (let i = 0; i < componentVariations.length; i++) {
|
|
36
|
+
const v = componentVariations[i];
|
|
37
|
+
if (!((_b = v.pz) == null ? void 0 : _b.crit)) {
|
|
38
|
+
defaults.push(v.index);
|
|
39
|
+
if (defaults.length >= (count || 1)) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
indexes.push(...defaults);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
indexes
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/runTest.ts
|
|
52
|
+
import { CANVAS_TEST_SLOT, CANVAS_TEST_VARIANT_PARAM } from "@uniformdev/canvas";
|
|
53
|
+
var runTest = ({
|
|
54
|
+
test,
|
|
55
|
+
component,
|
|
56
|
+
contextInstance
|
|
57
|
+
}) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
|
|
60
|
+
const componentVariations = slot.map((v, i) => {
|
|
61
|
+
var _a2, _b, _c;
|
|
62
|
+
const contextTag = (_b = (_a2 = v.parameters) == null ? void 0 : _a2[CANVAS_TEST_VARIANT_PARAM]) == null ? void 0 : _b.value;
|
|
63
|
+
const id = (_c = contextTag == null ? void 0 : contextTag.id) != null ? _c : "testId" in v ? v.testId : `ab-${i}-${v.type}`;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
testDistribution: contextTag == null ? void 0 : contextTag.testDistribution,
|
|
67
|
+
index: i
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
let index = null;
|
|
71
|
+
if (contextInstance) {
|
|
72
|
+
const { result } = contextInstance.test({
|
|
73
|
+
name: test,
|
|
74
|
+
variations: componentVariations
|
|
75
|
+
});
|
|
76
|
+
if (result) {
|
|
77
|
+
index = result.index;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const [first] = componentVariations;
|
|
81
|
+
if (first) {
|
|
82
|
+
index = first.index;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
index
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
runPersonalization,
|
|
91
|
+
runTest
|
|
92
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
runPersonalization: () => runPersonalization,
|
|
24
|
+
runTest: () => runTest
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/runPersonalization.ts
|
|
29
|
+
var import_canvas = require("@uniformdev/canvas");
|
|
30
|
+
var runPersonalization = ({
|
|
31
|
+
component,
|
|
32
|
+
trackingEventName,
|
|
33
|
+
count,
|
|
34
|
+
contextInstance
|
|
35
|
+
}) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[import_canvas.CANVAS_PERSONALIZE_SLOT]) || [];
|
|
38
|
+
const componentVariations = slot.map((v, i) => {
|
|
39
|
+
var _a2, _b2;
|
|
40
|
+
const contextTag = (_b2 = (_a2 = v.parameters) == null ? void 0 : _a2[import_canvas.CANVAS_PERSONALIZATION_PARAM]) == null ? void 0 : _b2.value;
|
|
41
|
+
const id = (contextTag == null ? void 0 : contextTag.name) || `pz-${i}-${v.type}`;
|
|
42
|
+
return {
|
|
43
|
+
id,
|
|
44
|
+
pz: contextTag,
|
|
45
|
+
index: i
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
const indexes = [];
|
|
49
|
+
if (contextInstance) {
|
|
50
|
+
const { variations } = contextInstance.personalize({
|
|
51
|
+
name: trackingEventName,
|
|
52
|
+
take: count || 1,
|
|
53
|
+
variations: componentVariations
|
|
54
|
+
});
|
|
55
|
+
if (variations) {
|
|
56
|
+
for (let i = 0; i < variations.length; i++) {
|
|
57
|
+
indexes.push(variations[i].index);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
const defaults = [];
|
|
62
|
+
for (let i = 0; i < componentVariations.length; i++) {
|
|
63
|
+
const v = componentVariations[i];
|
|
64
|
+
if (!((_b = v.pz) == null ? void 0 : _b.crit)) {
|
|
65
|
+
defaults.push(v.index);
|
|
66
|
+
if (defaults.length >= (count || 1)) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
indexes.push(...defaults);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
indexes
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/runTest.ts
|
|
79
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
80
|
+
var runTest = ({
|
|
81
|
+
test,
|
|
82
|
+
component,
|
|
83
|
+
contextInstance
|
|
84
|
+
}) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[import_canvas2.CANVAS_TEST_SLOT]) || [];
|
|
87
|
+
const componentVariations = slot.map((v, i) => {
|
|
88
|
+
var _a2, _b, _c;
|
|
89
|
+
const contextTag = (_b = (_a2 = v.parameters) == null ? void 0 : _a2[import_canvas2.CANVAS_TEST_VARIANT_PARAM]) == null ? void 0 : _b.value;
|
|
90
|
+
const id = (_c = contextTag == null ? void 0 : contextTag.id) != null ? _c : "testId" in v ? v.testId : `ab-${i}-${v.type}`;
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
testDistribution: contextTag == null ? void 0 : contextTag.testDistribution,
|
|
94
|
+
index: i
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
let index = null;
|
|
98
|
+
if (contextInstance) {
|
|
99
|
+
const { result } = contextInstance.test({
|
|
100
|
+
name: test,
|
|
101
|
+
variations: componentVariations
|
|
102
|
+
});
|
|
103
|
+
if (result) {
|
|
104
|
+
index = result.index;
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
const [first] = componentVariations;
|
|
108
|
+
if (first) {
|
|
109
|
+
index = first.index;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
index
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
runPersonalization,
|
|
119
|
+
runTest
|
|
120
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/runPersonalization.ts
|
|
2
|
+
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
|
|
3
|
+
var runPersonalization = ({
|
|
4
|
+
component,
|
|
5
|
+
trackingEventName,
|
|
6
|
+
count,
|
|
7
|
+
contextInstance
|
|
8
|
+
}) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
11
|
+
const componentVariations = slot.map((v, i) => {
|
|
12
|
+
var _a2, _b2;
|
|
13
|
+
const contextTag = (_b2 = (_a2 = v.parameters) == null ? void 0 : _a2[CANVAS_PERSONALIZATION_PARAM]) == null ? void 0 : _b2.value;
|
|
14
|
+
const id = (contextTag == null ? void 0 : contextTag.name) || `pz-${i}-${v.type}`;
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
pz: contextTag,
|
|
18
|
+
index: i
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const indexes = [];
|
|
22
|
+
if (contextInstance) {
|
|
23
|
+
const { variations } = contextInstance.personalize({
|
|
24
|
+
name: trackingEventName,
|
|
25
|
+
take: count || 1,
|
|
26
|
+
variations: componentVariations
|
|
27
|
+
});
|
|
28
|
+
if (variations) {
|
|
29
|
+
for (let i = 0; i < variations.length; i++) {
|
|
30
|
+
indexes.push(variations[i].index);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
const defaults = [];
|
|
35
|
+
for (let i = 0; i < componentVariations.length; i++) {
|
|
36
|
+
const v = componentVariations[i];
|
|
37
|
+
if (!((_b = v.pz) == null ? void 0 : _b.crit)) {
|
|
38
|
+
defaults.push(v.index);
|
|
39
|
+
if (defaults.length >= (count || 1)) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
indexes.push(...defaults);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
indexes
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/runTest.ts
|
|
52
|
+
import { CANVAS_TEST_SLOT, CANVAS_TEST_VARIANT_PARAM } from "@uniformdev/canvas";
|
|
53
|
+
var runTest = ({
|
|
54
|
+
test,
|
|
55
|
+
component,
|
|
56
|
+
contextInstance
|
|
57
|
+
}) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
|
|
60
|
+
const componentVariations = slot.map((v, i) => {
|
|
61
|
+
var _a2, _b, _c;
|
|
62
|
+
const contextTag = (_b = (_a2 = v.parameters) == null ? void 0 : _a2[CANVAS_TEST_VARIANT_PARAM]) == null ? void 0 : _b.value;
|
|
63
|
+
const id = (_c = contextTag == null ? void 0 : contextTag.id) != null ? _c : "testId" in v ? v.testId : `ab-${i}-${v.type}`;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
testDistribution: contextTag == null ? void 0 : contextTag.testDistribution,
|
|
67
|
+
index: i
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
let index = null;
|
|
71
|
+
if (contextInstance) {
|
|
72
|
+
const { result } = contextInstance.test({
|
|
73
|
+
name: test,
|
|
74
|
+
variations: componentVariations
|
|
75
|
+
});
|
|
76
|
+
if (result) {
|
|
77
|
+
index = result.index;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const [first] = componentVariations;
|
|
81
|
+
if (first) {
|
|
82
|
+
index = first.index;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
index
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
runPersonalization,
|
|
91
|
+
runTest
|
|
92
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniformdev/canvas-next-rsc-shared",
|
|
3
|
+
"version": "19.55.2-alpha.14+9b75d5322",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsup",
|
|
7
|
+
"dev": "tsup --watch",
|
|
8
|
+
"lint": "eslint \"**/*.{ts,tsx}\" --fix",
|
|
9
|
+
"test": "jest --maxWorkers=1 --passWithNoTests"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.esm.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"node": "./dist/index.mjs",
|
|
18
|
+
"default": "./dist/index.esm.js"
|
|
19
|
+
},
|
|
20
|
+
"require": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"/dist"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^18.0.0",
|
|
28
|
+
"@types/react": "^18.2.20",
|
|
29
|
+
"eslint": "^8.11.0",
|
|
30
|
+
"next": "^13.4.12",
|
|
31
|
+
"react": "18.2.0",
|
|
32
|
+
"react-dom": "18.2.0"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@uniformdev/canvas": "19.55.2-alpha.14+9b75d5322",
|
|
36
|
+
"@uniformdev/context": "19.55.2-alpha.14+9b75d5322"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=16.14.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"next": ">=13.4.7",
|
|
43
|
+
"react": ">=18.2",
|
|
44
|
+
"react-dom": ">=18.2"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "9b75d5322988b2a8c59e7e1b641fb0c8cb7ad301"
|
|
50
|
+
}
|