@plitzi/sdk-elements 0.39.10 → 0.39.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/Element/hooks/useElementState.d.ts +1 -1
  3. package/dist/builder/index.d.ts +2 -0
  4. package/dist/builder/index.mjs +4 -1
  5. package/dist/builder/ruleFields.d.ts +16 -0
  6. package/dist/builder/ruleFields.mjs +86 -0
  7. package/dist/builder/ruleSummary.d.ts +6 -0
  8. package/dist/builder/ruleSummary.mjs +33 -0
  9. package/dist/dataSource/GlobalSources.mjs +120 -99
  10. package/dist/dataSource/index.d.ts +1 -0
  11. package/dist/dataSource/index.mjs +6 -5
  12. package/dist/dataSource/useAudienceScope.d.ts +8 -0
  13. package/dist/dataSource/useAudienceScope.mjs +40 -0
  14. package/dist/dataSource/useExperiments.d.ts +12 -0
  15. package/dist/dataSource/useExperiments.mjs +58 -0
  16. package/dist/elements/basic/Link/declaration.mjs +1 -1
  17. package/dist/elements/declarations/index.d.ts +112 -2
  18. package/dist/elements/declarations/index.mjs +55 -49
  19. package/dist/elements/index.d.ts +5 -1
  20. package/dist/elements/index.mjs +6 -2
  21. package/dist/elements/media/Embed/declaration.d.ts +1 -1
  22. package/dist/elements/media/Embed/index.d.ts +1 -1
  23. package/dist/elements/provider/Channel/declaration.mjs +1 -1
  24. package/dist/elements/settings.mjs +8 -2
  25. package/dist/elements/structure/TimeWindow/Settings.d.ts +8 -0
  26. package/dist/elements/structure/TimeWindow/Settings.mjs +40 -0
  27. package/dist/elements/structure/TimeWindow/TimeWindow.d.ts +14 -0
  28. package/dist/elements/structure/TimeWindow/TimeWindow.mjs +32 -0
  29. package/dist/elements/structure/TimeWindow/declaration.d.ts +34 -0
  30. package/dist/elements/structure/TimeWindow/declaration.mjs +26 -0
  31. package/dist/elements/structure/TimeWindow/index.d.ts +32 -0
  32. package/dist/elements/structure/TimeWindow/index.mjs +5 -0
  33. package/dist/elements/testing/Variants/Settings.d.ts +14 -0
  34. package/dist/elements/testing/Variants/Settings.mjs +280 -0
  35. package/dist/elements/testing/Variants/VariantItem/Settings.d.ts +13 -0
  36. package/dist/elements/testing/Variants/VariantItem/Settings.mjs +140 -0
  37. package/dist/elements/testing/Variants/VariantItem/VariantItem.d.ts +18 -0
  38. package/dist/elements/testing/Variants/VariantItem/VariantItem.mjs +11 -0
  39. package/dist/elements/testing/Variants/VariantItem/declaration.d.ts +38 -0
  40. package/dist/elements/testing/Variants/VariantItem/declaration.mjs +29 -0
  41. package/dist/elements/testing/Variants/VariantItem/index.d.ts +36 -0
  42. package/dist/elements/testing/Variants/VariantItem/index.mjs +5 -0
  43. package/dist/elements/testing/Variants/Variants.d.ts +28 -0
  44. package/dist/elements/testing/Variants/Variants.mjs +31 -0
  45. package/dist/elements/testing/Variants/declaration.d.ts +44 -0
  46. package/dist/elements/testing/Variants/declaration.mjs +30 -0
  47. package/dist/elements/testing/Variants/index.d.ts +77 -0
  48. package/dist/elements/testing/Variants/index.mjs +9 -0
  49. package/dist/elements/testing/childOfItem.d.ts +7 -0
  50. package/dist/elements/testing/childOfItem.mjs +9 -0
  51. package/dist/index.d.ts +108 -1
  52. package/dist/index.mjs +13 -9
  53. package/package.json +8 -8
@@ -0,0 +1,32 @@
1
+ declare const TimeWindow: import('react').FC<import('../../..').WithElementProps<import('./TimeWindow').TimeWindowProps>> & {
2
+ readonly type: "timeWindow";
3
+ readonly content: {
4
+ readonly attributes: {
5
+ readonly startsAt: "";
6
+ readonly endsAt: "";
7
+ };
8
+ readonly definition: {
9
+ readonly label: "Time Window";
10
+ readonly description: string;
11
+ readonly items: [];
12
+ };
13
+ readonly market: {
14
+ readonly category: "structure";
15
+ readonly icon: "fa-regular fa-calendar";
16
+ };
17
+ readonly defaultStyle: {
18
+ readonly style: {
19
+ readonly base: {
20
+ readonly default: {};
21
+ };
22
+ };
23
+ readonly subTypes: {};
24
+ };
25
+ };
26
+ } & {
27
+ content: import('@plitzi/sdk-shared/authoring').ElementContentDefaults;
28
+ } & import('@plitzi/sdk-shared/authoring').ElementAttributesBrand<Partial<{
29
+ startsAt?: string | undefined;
30
+ endsAt?: string | undefined;
31
+ }>>;
32
+ export default TimeWindow;
@@ -0,0 +1,5 @@
1
+ import e from "./declaration.mjs";
2
+ import t from "./TimeWindow.mjs";
3
+ // src/elements/structure/TimeWindow/index.ts
4
+ var n = Object.assign(t, e);
5
+ export { n as default };
@@ -0,0 +1,14 @@
1
+ import { ChooseBy } from '@plitzi/sdk-shared/variants';
2
+ type SettingsProps = {
3
+ id?: string;
4
+ chooseBy?: ChooseBy;
5
+ experiment?: string;
6
+ builderVariant?: number;
7
+ onUpdate?: (key: string, value: string | boolean | number) => void;
8
+ };
9
+ /**
10
+ * A Variants element's settings: how it chooses, and its variants in a list — each with its share or its rule, the one
11
+ * the canvas shows, and the way to add, select and remove one — so it is set from one place.
12
+ */
13
+ declare const Settings: ({ id, chooseBy, experiment, builderVariant, onUpdate }: SettingsProps) => import('react').JSX.Element;
14
+ export default Settings;
@@ -0,0 +1,280 @@
1
+ import { audienceRuleFields as e } from "../../../builder/ruleFields.mjs";
2
+ import { ruleSummary as t } from "../../../builder/ruleSummary.mjs";
3
+ import n from "../../useSettingsUpdate.mjs";
4
+ import { use as r, useCallback as i, useMemo as a } from "react";
5
+ import { useBuilderStore as o, useCommonStore as s } from "@plitzi/sdk-shared/store";
6
+ import { pick as c } from "@plitzi/plitzi-ui/helpers";
7
+ import { ComponentContext as l } from "@plitzi/sdk-shared/elements";
8
+ import { hasConditions as u } from "@plitzi/sdk-shared/flags";
9
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
10
+ import { VARIANT_ITEM_TYPE as m } from "@plitzi/sdk-shared/variants";
11
+ import { DEFAULT_VARIANT_WEIGHT as h, EXPERIMENT_VARIANTS as g, experimentNameOf as _, isExperimentWeight as v, sharesToHundred as y, variantAt as b } from "@plitzi/sdk-shared/experiments";
12
+ import x from "clsx";
13
+ import { BuilderContext as S } from "@plitzi/sdk-shared/builder/contexts";
14
+ import C from "@plitzi/plitzi-ui/Button";
15
+ import w from "@plitzi/plitzi-ui/Input";
16
+ // src/elements/testing/Variants/Settings.tsx
17
+ var T = [{
18
+ mode: "chance",
19
+ label: "By chance",
20
+ detail: "A/B test, by share",
21
+ icon: "fa-solid fa-shuffle"
22
+ }, {
23
+ mode: "rules",
24
+ label: "By rules",
25
+ detail: "Who is visiting",
26
+ icon: "fa-solid fa-filter"
27
+ }], E = {
28
+ chance: "Each visitor is given a variant at random, by its share, and keeps it when they come back.",
29
+ rules: "Each visitor sees the first variant whose rule they match. The last, with no rule, is for everyone else."
30
+ }, D = (e) => v(e?.weight) ? e.weight : h, O = (e, t) => t > 0 ? Math.round(e / t * 100) : 0, k = ({ chooseBy: e, onChange: t }) => /* @__PURE__ */ f("div", {
31
+ role: "radiogroup",
32
+ "aria-label": "Choose the variant",
33
+ className: "bg-ui-raised grid grid-cols-2 gap-1 rounded-lg p-1",
34
+ children: T.map(({ mode: n, label: r, detail: i, icon: a }) => /* @__PURE__ */ p("button", {
35
+ type: "button",
36
+ role: "radio",
37
+ "aria-checked": e === n,
38
+ className: x("flex flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left transition-colors", {
39
+ "bg-ui-panel text-ui-fg shadow-sm": e === n,
40
+ "text-ui-fg-muted hover:text-ui-fg": e !== n
41
+ }),
42
+ onClick: () => t(n),
43
+ children: [/* @__PURE__ */ p("span", {
44
+ className: "flex items-center gap-1.5 text-xs font-semibold",
45
+ children: [/* @__PURE__ */ f("i", { className: x(a, "text-[10px]") }), r]
46
+ }), /* @__PURE__ */ f("span", {
47
+ className: "text-ui-fg-subtle text-[10px]",
48
+ children: i
49
+ })]
50
+ }, n))
51
+ }), A = ({ id: e, mark: t, shown: n, chooseBy: r, weight: i, percent: a, exact: o, rule: s, beyond: c, removable: l, onShow: u, onSelect: m, onWeight: h, onRemove: g }) => /* @__PURE__ */ p("li", {
52
+ className: "hover:bg-ui-hover flex items-center gap-2 rounded-md px-1.5 py-1",
53
+ children: [
54
+ /* @__PURE__ */ f("button", {
55
+ type: "button",
56
+ "aria-pressed": n,
57
+ title: n ? "Shown in the canvas while editing" : "Show this one in the canvas while editing",
58
+ className: x("flex size-6 shrink-0 items-center justify-center rounded transition-colors", {
59
+ "bg-primary-50 text-primary-600 dark:bg-primary-400/15 dark:text-primary-300": n,
60
+ "text-ui-fg-subtle hover:text-ui-fg": !n
61
+ }),
62
+ onClick: u,
63
+ children: /* @__PURE__ */ f("i", { className: x(n ? "fa-solid fa-eye" : "fa-regular fa-eye", "text-[11px]") })
64
+ }),
65
+ /* @__PURE__ */ f("span", {
66
+ className: "bg-ui-raised text-ui-fg-muted inline-flex size-5 shrink-0 items-center justify-center rounded text-[10px] font-bold",
67
+ children: t
68
+ }),
69
+ /* @__PURE__ */ p("button", {
70
+ type: "button",
71
+ className: "min-w-0 grow text-left",
72
+ title: r === "rules" ? `Edit the rule of ${e}` : `Select ${e}`,
73
+ onClick: m,
74
+ children: [
75
+ /* @__PURE__ */ f("span", {
76
+ className: "text-ui-fg block truncate text-xs",
77
+ children: e
78
+ }),
79
+ r === "rules" && /* @__PURE__ */ f("span", {
80
+ className: "text-ui-fg-subtle block truncate text-[10px]",
81
+ children: s || "Everyone else"
82
+ }),
83
+ c && /* @__PURE__ */ f("span", {
84
+ className: "block text-[10px] text-amber-600 dark:text-amber-400",
85
+ children: "Never shown: five at most"
86
+ }),
87
+ r === "chance" && !c && !o && /* @__PURE__ */ p("span", {
88
+ title: "What it is drawn as while the shares do not add up to 100",
89
+ className: "block text-[10px] text-amber-600 tabular-nums dark:text-amber-400",
90
+ children: [
91
+ "read as ≈",
92
+ a,
93
+ "%"
94
+ ]
95
+ })
96
+ ]
97
+ }),
98
+ r === "chance" && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f(w, {
99
+ className: "w-14 shrink-0",
100
+ type: "number",
101
+ size: "xs",
102
+ min: 0,
103
+ max: 100,
104
+ "aria-label": `Share of ${e}`,
105
+ value: String(i),
106
+ onChange: h
107
+ }), /* @__PURE__ */ f("span", {
108
+ className: "text-ui-fg-muted shrink-0 text-[11px]",
109
+ children: "%"
110
+ })] }),
111
+ r === "rules" && /* @__PURE__ */ f("button", {
112
+ type: "button",
113
+ title: `Edit the rule of ${e}`,
114
+ className: "text-ui-fg-subtle hover:text-ui-fg flex size-6 shrink-0 items-center justify-center rounded",
115
+ onClick: m,
116
+ children: /* @__PURE__ */ f("i", { className: "fa-solid fa-pen text-[10px]" })
117
+ }),
118
+ /* @__PURE__ */ f("button", {
119
+ type: "button",
120
+ title: l ? `Remove ${e}` : "It needs the variants it has",
121
+ disabled: !l,
122
+ className: "text-ui-fg-subtle flex size-6 shrink-0 items-center justify-center rounded enabled:hover:text-red-600 disabled:opacity-40 dark:enabled:hover:text-red-400",
123
+ onClick: g,
124
+ children: /* @__PURE__ */ f("i", { className: "fa-solid fa-trash text-[10px]" })
125
+ })
126
+ ]
127
+ }), j = ({ id: d = "", chooseBy: h = "chance", experiment: v = "", builderVariant: T = 0, onUpdate: j }) => {
128
+ let M = n(j), [[N = [], P = ""]] = s([`schema.flat.${d}.definition.items`, `schema.flat.${d}.definition.rootId`]), [F] = s(N.map((e) => `schema.flat.${e}`)), [[I = {}, L = {}, R]] = s([
129
+ "navigation.routeParams",
130
+ "navigation.queryParams",
131
+ "schema.settings.visitorRoles"
132
+ ]), [, z] = o("elementSelected"), { builderHandler: B, builderDropElement: V } = r(S), { componentDefinitions: H } = r(l), U = a(() => e({
133
+ routeParams: I,
134
+ queryParams: L,
135
+ visitorRoles: Object.keys(R ?? {})
136
+ }), [
137
+ I,
138
+ L,
139
+ R
140
+ ]), W = N.map((e, t) => D(F[t]?.attributes)), G = W.slice(0, g.length), K = G.reduce((e, t) => e + t, 0), q = N.map((e, t) => F[t]?.attributes.when), J = q.findIndex((e) => !u(e)), Y = h === "chance" ? 2 : 1, X = _({
141
+ id: d,
142
+ attributes: { experiment: v }
143
+ }), Z = h === "chance" && N.length >= g.length, Q = i((e) => j?.("chooseBy", e), [j]), $ = i((e, t) => {
144
+ let n = F.at(e);
145
+ n && B("schemaUpdateElement", {
146
+ ...n,
147
+ attributes: {
148
+ ...n.attributes,
149
+ weight: t
150
+ }
151
+ });
152
+ }, [B, F]), ee = i(() => y(G.map(() => 1)).forEach((e, t) => $(t, e)), [G, $]), te = i(() => y(G).forEach((e, t) => $(t, e)), [G, $]), ne = i(() => {
153
+ let e = H.current[m], t = N.at(-1);
154
+ if (!e || t === void 0) return;
155
+ let n = h === "rules" && J !== -1 ? N[J] : void 0, r = {
156
+ id: "",
157
+ ...c(e, ["attributes", "definition"])
158
+ };
159
+ V("add##variant", { element: r }, n ? "top" : "bottom", n ?? t, P);
160
+ }, [
161
+ V,
162
+ h,
163
+ H,
164
+ J,
165
+ N,
166
+ P
167
+ ]), re = i((e) => {
168
+ B("schemaRemoveElement", N[e]), e < T ? j?.("builderVariant", T - 1) : e === T && j?.("builderVariant", 0);
169
+ }, [
170
+ B,
171
+ T,
172
+ N,
173
+ j
174
+ ]), ie = i((e, t) => {
175
+ let n = Number(t);
176
+ t.trim() !== "" && Number.isFinite(n) && $(e, Math.min(100, Math.max(0, Math.round(n))));
177
+ }, [$]);
178
+ return /* @__PURE__ */ p("div", {
179
+ className: "flex flex-col gap-4 py-2",
180
+ children: [
181
+ /* @__PURE__ */ p("div", {
182
+ className: "flex flex-col gap-1.5",
183
+ children: [
184
+ /* @__PURE__ */ f("span", {
185
+ className: "text-ui-fg text-xs font-medium",
186
+ children: "Choose the variant"
187
+ }),
188
+ /* @__PURE__ */ f(k, {
189
+ chooseBy: h,
190
+ onChange: Q
191
+ }),
192
+ /* @__PURE__ */ f("span", {
193
+ className: "text-ui-fg-subtle text-xs",
194
+ children: E[h]
195
+ })
196
+ ]
197
+ }),
198
+ h === "chance" && /* @__PURE__ */ p("div", {
199
+ className: "flex flex-col gap-1",
200
+ children: [/* @__PURE__ */ f(w, {
201
+ label: "Test name",
202
+ size: "xs",
203
+ placeholder: _({
204
+ id: d,
205
+ attributes: {}
206
+ }) ?? "heroTest",
207
+ value: v,
208
+ onChange: M.text("experiment")
209
+ }), /* @__PURE__ */ f("span", {
210
+ className: x("text-xs", X ? "text-ui-fg-subtle" : "text-red-600 dark:text-red-400"),
211
+ children: X === void 0 ? "Not running: a name is letters, digits and _, not starting with a digit — heroTest, pricing_v2." : `${v === "" ? "Named after this element until you name it. " : ""}Its results are in Analytics → Experiments as “${X}”.`
212
+ })]
213
+ }),
214
+ /* @__PURE__ */ p("div", {
215
+ className: "flex flex-col gap-1",
216
+ children: [
217
+ /* @__PURE__ */ p("div", {
218
+ className: "flex items-center justify-between",
219
+ children: [/* @__PURE__ */ f("span", {
220
+ className: "text-ui-fg-subtle text-[11px] font-semibold tracking-wide uppercase",
221
+ children: "Each variant"
222
+ }), h === "chance" && N.length > 1 && /* @__PURE__ */ f("button", {
223
+ type: "button",
224
+ className: "text-primary-600 dark:text-primary-300 text-[11px]",
225
+ onClick: ee,
226
+ children: "Even shares"
227
+ })]
228
+ }),
229
+ /* @__PURE__ */ f("ul", {
230
+ className: "flex flex-col",
231
+ children: N.map((e, n) => /* @__PURE__ */ f(A, {
232
+ id: e,
233
+ mark: h === "chance" ? b(n)?.toUpperCase() ?? "–" : String(n + 1),
234
+ shown: n === T,
235
+ chooseBy: h,
236
+ weight: W[n],
237
+ percent: n < g.length ? O(W[n], K) : 0,
238
+ exact: K === 100,
239
+ rule: t(q[n], U),
240
+ beyond: h === "chance" && n >= g.length,
241
+ removable: N.length > Y,
242
+ onShow: () => j?.("builderVariant", n),
243
+ onSelect: () => z(e),
244
+ onWeight: (e) => ie(n, e),
245
+ onRemove: () => re(n)
246
+ }, e))
247
+ }),
248
+ h === "chance" && /* @__PURE__ */ p("div", {
249
+ className: "flex items-center justify-between gap-2 px-1.5 py-1 text-[11px]",
250
+ children: [/* @__PURE__ */ f("span", {
251
+ className: x({
252
+ "text-ui-fg-subtle": K === 100,
253
+ "text-amber-600 dark:text-amber-400": K !== 100
254
+ }),
255
+ children: K === 100 ? "Total: 100% of the visitors" : `Total: ${String(K)}% — the shares add up to 100%`
256
+ }), K !== 100 && K > 0 && /* @__PURE__ */ f("button", {
257
+ type: "button",
258
+ className: "text-primary-600 dark:text-primary-300 shrink-0",
259
+ onClick: te,
260
+ children: "Make it 100%"
261
+ })]
262
+ }),
263
+ /* @__PURE__ */ p(C, {
264
+ size: "xs",
265
+ intent: "secondary",
266
+ className: "self-start",
267
+ disabled: Z,
268
+ onClick: ne,
269
+ children: [/* @__PURE__ */ f(C.Icon, { icon: "fa-solid fa-plus" }), "Add a variant"]
270
+ })
271
+ ]
272
+ }),
273
+ /* @__PURE__ */ f("span", {
274
+ className: "text-ui-fg-subtle text-xs",
275
+ children: h === "chance" ? "Each share is a percent of the visitors, and together they add up to 100% — 50, 25, 20 and 5 split them so. 0 shows a variant to nobody. The eye picks the one the canvas shows while editing; its preview shows the visitor chosen in State Manager → Visitor." : "Select a variant to write its rule: what the visitor’s device, language, first visit or address say. The eye picks the one the canvas shows while editing; its preview shows the visitor chosen in State Manager → Visitor."
276
+ })
277
+ ]
278
+ });
279
+ };
280
+ export { j as default };
@@ -0,0 +1,13 @@
1
+ import { RuleGroup } from '@plitzi/plitzi-ui/QueryBuilder';
2
+ type SettingsProps = {
3
+ id?: string;
4
+ weight?: number;
5
+ when?: RuleGroup;
6
+ onUpdate?: (key: string, value: RuleGroup | number) => void;
7
+ };
8
+ /**
9
+ * A variant's settings: what it is to the Variants element it is in — its letter or its place — and, as that element
10
+ * chooses, its share of the visitors or the rule of the ones it is for. The way back to the element is one press.
11
+ */
12
+ declare const Settings: ({ id, weight, when, onUpdate }: SettingsProps) => import('react').JSX.Element;
13
+ export default Settings;
@@ -0,0 +1,140 @@
1
+ import { audienceRuleFields as e } from "../../../../builder/ruleFields.mjs";
2
+ import { use as t, useCallback as n, useMemo as r } from "react";
3
+ import { isRecord as i } from "@plitzi/sdk-shared/helpers";
4
+ import { useBuilderStore as a, useCommonStore as o } from "@plitzi/sdk-shared/store";
5
+ import { hasConditions as s } from "@plitzi/sdk-shared/flags";
6
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
7
+ import { isChooseBy as u } from "@plitzi/sdk-shared/variants";
8
+ import { DEFAULT_VARIANT_WEIGHT as d, EXPERIMENT_VARIANTS as f, isExperimentWeight as p, variantAt as m } from "@plitzi/sdk-shared/experiments";
9
+ import { BuilderContext as h } from "@plitzi/sdk-shared/builder/contexts";
10
+ import g from "@plitzi/plitzi-ui/Button";
11
+ import _ from "@plitzi/plitzi-ui/Input";
12
+ import v from "@plitzi/plitzi-ui/QueryBuilder";
13
+ // src/elements/testing/Variants/VariantItem/Settings.tsx
14
+ var y = {
15
+ combinator: "and",
16
+ rules: []
17
+ }, b = ({ id: b = "", weight: x = d, when: S = y, onUpdate: C }) => {
18
+ let [[w = ""]] = o([`schema.flat.${b}.definition.parentId`]), [[T, E, D = [], O]] = o([
19
+ `schema.flat.${w}.attributes.chooseBy`,
20
+ `schema.flat.${w}.attributes.builderVariant`,
21
+ `schema.flat.${w}.definition.items`,
22
+ `schema.flat.${w}`
23
+ ]), [k] = o(D.map((e) => `schema.flat.${e}.attributes.weight`)), [[A = {}, j = {}, M]] = o([
24
+ "navigation.routeParams",
25
+ "navigation.queryParams",
26
+ "schema.settings.visitorRoles"
27
+ ]), [, N] = a("elementSelected"), { builderHandler: P } = t(h), F = u(T) ? T : "chance", I = D.indexOf(b), L = r(() => e({
28
+ routeParams: A,
29
+ queryParams: j,
30
+ visitorRoles: Object.keys(M ?? {})
31
+ }), [
32
+ A,
33
+ j,
34
+ M
35
+ ]), R = k.slice(0, f.length).reduce((e, t) => e + (p(t) ? t : d), 0), z = R > 0 ? Math.round(x / R * 100) : 0, B = E === I, V = n((e) => {
36
+ let t = Number(e);
37
+ e.trim() !== "" && Number.isFinite(t) && C?.("weight", Math.min(100, Math.max(0, Math.round(t))));
38
+ }, [C]), H = n((e) => C?.("when", e), [C]), U = n(() => N(w), [w, N]), W = n(() => {
39
+ i(O) && P("schemaUpdateElement", {
40
+ ...O,
41
+ attributes: {
42
+ ...O.attributes,
43
+ builderVariant: I
44
+ }
45
+ });
46
+ }, [
47
+ P,
48
+ I,
49
+ O
50
+ ]), G = F === "chance" ? `Variant ${m(I)?.toUpperCase() ?? String(I + 1)}` : `Variant ${String(I + 1)}`;
51
+ return /* @__PURE__ */ l("div", {
52
+ className: "flex flex-col gap-4 py-2",
53
+ children: [
54
+ /* @__PURE__ */ l("div", {
55
+ className: "bg-ui-raised flex items-center justify-between gap-2 rounded-lg px-2.5 py-2",
56
+ children: [/* @__PURE__ */ l("div", {
57
+ className: "flex min-w-0 flex-col",
58
+ children: [/* @__PURE__ */ c("span", {
59
+ className: "text-ui-fg text-xs font-semibold",
60
+ children: G
61
+ }), /* @__PURE__ */ l("span", {
62
+ className: "text-ui-fg-subtle truncate text-[11px]",
63
+ children: [
64
+ "of ",
65
+ w,
66
+ ", chosen ",
67
+ F === "chance" ? "by chance" : "by rules"
68
+ ]
69
+ })]
70
+ }), /* @__PURE__ */ l(g, {
71
+ size: "xs",
72
+ intent: "secondary",
73
+ onClick: U,
74
+ children: [/* @__PURE__ */ c(g.Icon, { icon: "fa-solid fa-arrow-up" }), "All variants"]
75
+ })]
76
+ }),
77
+ F === "chance" && /* @__PURE__ */ l("div", {
78
+ className: "flex flex-col gap-1",
79
+ children: [/* @__PURE__ */ l("div", {
80
+ className: "flex items-end gap-2",
81
+ children: [/* @__PURE__ */ c(_, {
82
+ className: "w-24",
83
+ type: "number",
84
+ label: "Share (%)",
85
+ size: "xs",
86
+ min: 0,
87
+ max: 100,
88
+ value: String(x),
89
+ onChange: V
90
+ }), /* @__PURE__ */ c("span", {
91
+ className: "text-ui-fg-muted pb-1.5 text-xs",
92
+ children: "of the visitors"
93
+ })]
94
+ }), R === 100 ? /* @__PURE__ */ c("span", {
95
+ className: "text-ui-fg-subtle text-xs",
96
+ children: "A percent of the visitors: all the variants’ shares add up to 100%. 0 shows it to nobody."
97
+ }) : /* @__PURE__ */ l("span", {
98
+ className: "text-xs text-amber-600 dark:text-amber-400",
99
+ children: [
100
+ "The variants’ shares add up to ",
101
+ R,
102
+ "%, not 100%: this one is read as ",
103
+ z,
104
+ "% until they do. Fix them in All variants."
105
+ ]
106
+ })]
107
+ }),
108
+ F === "rules" && /* @__PURE__ */ l("div", {
109
+ className: "flex flex-col gap-1",
110
+ children: [
111
+ /* @__PURE__ */ c("span", {
112
+ className: "text-ui-fg text-xs font-medium",
113
+ children: "Shown to visitors who match"
114
+ }),
115
+ /* @__PURE__ */ c(v, {
116
+ direction: "vertical",
117
+ intent: "gray",
118
+ className: "w-full",
119
+ query: S,
120
+ fields: L,
121
+ onChange: H,
122
+ showBranches: !0
123
+ }),
124
+ /* @__PURE__ */ c("span", {
125
+ className: "text-ui-fg-subtle text-xs",
126
+ children: s(S) ? "The first variant whose rule a visitor matches is the one they see." : "No rule: it is for everyone the variants before it did not take — keep it last."
127
+ })
128
+ ]
129
+ }),
130
+ !B && /* @__PURE__ */ l(g, {
131
+ size: "xs",
132
+ intent: "secondary",
133
+ className: "self-start",
134
+ onClick: W,
135
+ children: [/* @__PURE__ */ c(g.Icon, { icon: "fa-regular fa-eye" }), "Show this one in the canvas"]
136
+ })
137
+ ]
138
+ });
139
+ };
140
+ export { b as default };
@@ -0,0 +1,18 @@
1
+ import { RuleGroup } from '@plitzi/sdk-shared/conditions';
2
+ import { ReactNode, RefObject } from 'react';
3
+ export type VariantItemProps = {
4
+ ref?: RefObject<HTMLElement>;
5
+ className?: string;
6
+ children?: ReactNode;
7
+ /**
8
+ * Chosen by chance, its share of the visitors against the other variants' weights: 0–100. 0 shows it to nobody, and
9
+ * the visitors who were shown it are drawn again.
10
+ */
11
+ weight?: number;
12
+ /** Chosen by rules, the visitors it is for: a rule group. With no conditions, everybody the variants before it left. */
13
+ when?: RuleGroup;
14
+ };
15
+ declare const VariantItem: ({ ref, className, children }: VariantItemProps) => import('react').JSX.Element;
16
+ declare const _default: import('react').FC<import('../../../..').WithElementProps<VariantItemProps>>;
17
+ export default _default;
18
+ export { VariantItem };
@@ -0,0 +1,11 @@
1
+ import e from "../../../../Element/hocs/withElement.mjs";
2
+ import { RootElement as t } from "../../../../Element/RootElement.mjs";
3
+ import { jsx as n } from "react/jsx-runtime";
4
+ import r from "clsx";
5
+ // src/elements/testing/Variants/VariantItem/VariantItem.tsx
6
+ var i = ({ ref: e, className: i = "", children: a }) => /* @__PURE__ */ n(t, {
7
+ ref: e,
8
+ className: r("plitzi-component__variant-item", i),
9
+ children: a
10
+ }), a = e(i);
11
+ export { i as VariantItem, a as default };
@@ -0,0 +1,38 @@
1
+ import { VariantItemProps } from './VariantItem';
2
+ import { AuthorableAttributes } from '@plitzi/sdk-shared/authoring';
3
+ /** What this element can be authored with — its component's own props, minus what the runtime supplies. */
4
+ export type VariantItemAttributes = AuthorableAttributes<VariantItemProps>;
5
+ declare const declaration: import('@plitzi/sdk-shared/authoring').DeclaredElement<{
6
+ readonly type: "variantItem";
7
+ readonly ancestorType: "variants";
8
+ readonly content: {
9
+ readonly attributes: {
10
+ readonly weight: 50;
11
+ };
12
+ readonly definition: {
13
+ readonly label: "Variant";
14
+ readonly description: string;
15
+ readonly items: [];
16
+ };
17
+ readonly builder: {
18
+ readonly canSnippet: false;
19
+ readonly itemsNotAllowed: ["variantItem"];
20
+ };
21
+ readonly market: {
22
+ readonly category: "testing";
23
+ readonly icon: "fa-solid fa-code-branch";
24
+ };
25
+ readonly defaultStyle: {
26
+ readonly style: {
27
+ readonly base: {
28
+ readonly default: {};
29
+ };
30
+ };
31
+ readonly subTypes: {};
32
+ };
33
+ };
34
+ }, Partial<{
35
+ when?: import('@plitzi/sdk-shared').RuleGroup | undefined;
36
+ weight?: number | undefined;
37
+ }>>;
38
+ export default declaration;
@@ -0,0 +1,29 @@
1
+ import { elementDeclaration as e } from "@plitzi/sdk-shared/authoring";
2
+ import { VARIANTS_TYPE as t, VARIANT_ITEM_TYPE as n } from "@plitzi/sdk-shared/variants";
3
+ import { DEFAULT_VARIANT_WEIGHT as r } from "@plitzi/sdk-shared/experiments";
4
+ // src/elements/testing/Variants/VariantItem/declaration.ts
5
+ var i = e()({
6
+ type: n,
7
+ ancestorType: t,
8
+ content: {
9
+ attributes: { weight: r },
10
+ definition: {
11
+ label: "Variant",
12
+ description: "One of the versions a Variants element chooses between — by chance, shown to its share of the visitors; by rules, to the visitors its rule matches. Its share is `weight`, a percent of the visitors (the variants’ add up to 100), and its rule `when` (a rule group; none is everybody else). Only the variant a visitor is shown is drawn.",
13
+ items: []
14
+ },
15
+ builder: {
16
+ canSnippet: !1,
17
+ itemsNotAllowed: [n]
18
+ },
19
+ market: {
20
+ category: "testing",
21
+ icon: "fa-solid fa-code-branch"
22
+ },
23
+ defaultStyle: {
24
+ style: { base: { default: {} } },
25
+ subTypes: {}
26
+ }
27
+ }
28
+ });
29
+ export { i as default };
@@ -0,0 +1,36 @@
1
+ declare const VariantItem: import('react').FC<import('../../../..').WithElementProps<import('./VariantItem').VariantItemProps>> & {
2
+ readonly type: "variantItem";
3
+ readonly ancestorType: "variants";
4
+ readonly content: {
5
+ readonly attributes: {
6
+ readonly weight: 50;
7
+ };
8
+ readonly definition: {
9
+ readonly label: "Variant";
10
+ readonly description: string;
11
+ readonly items: [];
12
+ };
13
+ readonly builder: {
14
+ readonly canSnippet: false;
15
+ readonly itemsNotAllowed: ["variantItem"];
16
+ };
17
+ readonly market: {
18
+ readonly category: "testing";
19
+ readonly icon: "fa-solid fa-code-branch";
20
+ };
21
+ readonly defaultStyle: {
22
+ readonly style: {
23
+ readonly base: {
24
+ readonly default: {};
25
+ };
26
+ };
27
+ readonly subTypes: {};
28
+ };
29
+ };
30
+ } & {
31
+ content: import('@plitzi/sdk-shared/authoring').ElementContentDefaults;
32
+ } & import('@plitzi/sdk-shared/authoring').ElementAttributesBrand<Partial<{
33
+ when?: import('@plitzi/sdk-shared').RuleGroup | undefined;
34
+ weight?: number | undefined;
35
+ }>>;
36
+ export default VariantItem;
@@ -0,0 +1,5 @@
1
+ import e from "./declaration.mjs";
2
+ import t from "./VariantItem.mjs";
3
+ // src/elements/testing/Variants/VariantItem/index.ts
4
+ var n = Object.assign(t, e);
5
+ export { n as default };
@@ -0,0 +1,28 @@
1
+ import { ChooseBy } from '@plitzi/sdk-shared/variants';
2
+ import { ReactNode, RefObject } from 'react';
3
+ export type VariantsProps = {
4
+ ref?: RefObject<HTMLElement>;
5
+ className?: string;
6
+ children?: ReactNode;
7
+ /**
8
+ * How it chooses the variant a visitor sees: `chance` — an A/B test, each variant shown to its `weight`'s share of
9
+ * the visitors, and a visitor kept on theirs when they come back — or `rules`, the first variant whose `when` the
10
+ * visitor matches (one with no conditions is for everybody else).
11
+ */
12
+ chooseBy?: ChooseBy;
13
+ /**
14
+ * By chance, the experiment's name — `heroTest`: what keeps a visitor on their variant, what `{{ experiments.heroTest
15
+ * }}` reads and what the results are shown under. Every element with the same name shows a visitor the same variant.
16
+ * Left empty, it is named after the element (`pricing-test` runs `pricing_test`).
17
+ */
18
+ experiment?: string;
19
+ /**
20
+ * The variant (from 0) the builder's canvas shows while editing, so each can be edited. Its preview shows the
21
+ * simulated visitor's. Visitors never see it decided this way.
22
+ */
23
+ builderVariant?: number;
24
+ };
25
+ declare const Variants: ({ ref, className, children, chooseBy, experiment, builderVariant }: VariantsProps) => import('react').JSX.Element;
26
+ declare const _default: import('react').FC<import('../../..').WithElementProps<VariantsProps>>;
27
+ export default _default;
28
+ export { Variants };