@ninetailed/experience.js-react 7.6.0-beta.1 → 7.6.0-beta.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/index.cjs.d.ts +1 -0
- package/{index.cjs → index.cjs.js} +33 -12
- package/{index.js → index.esm.js} +119 -110
- package/package.json +26 -13
- package/src/lib/Experience/ComponentMarker.d.ts +5 -1
- package/src/lib/Experience/ESRLoadingComponent.d.ts +1 -1
- package/src/lib/Experience/Experience.d.ts +1 -1
- package/src/lib/MergeTag/MergeTag.d.ts +7 -0
- package/src/lib/MergeTag/helpers.d.ts +3 -0
- package/src/lib/MergeTag/index.d.ts +1 -0
- package/src/lib/NinetailedProvider.d.ts +4 -4
- package/src/lib/Personalize.d.ts +1 -1
- package/src/lib/useNinetailed.d.ts +1 -1
- package/src/lib/MergeTag.d.ts +0 -9
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -236,8 +236,10 @@ const selectValueFromProfile = (profile, id) => {
|
|
|
236
236
|
}
|
|
237
237
|
return radash.get(profile, matchingSelector);
|
|
238
238
|
};
|
|
239
|
+
|
|
239
240
|
const MergeTag = ({
|
|
240
|
-
id
|
|
241
|
+
id,
|
|
242
|
+
fallback
|
|
241
243
|
}) => {
|
|
242
244
|
const {
|
|
243
245
|
loading,
|
|
@@ -246,11 +248,10 @@ const MergeTag = ({
|
|
|
246
248
|
if (loading || !profile) {
|
|
247
249
|
return null;
|
|
248
250
|
}
|
|
249
|
-
const value = selectValueFromProfile(profile, id);
|
|
250
|
-
|
|
251
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
251
|
+
const value = selectValueFromProfile(profile, id) || fallback;
|
|
252
|
+
return value ? jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
252
253
|
children: value
|
|
253
|
-
});
|
|
254
|
+
}) : null;
|
|
254
255
|
};
|
|
255
256
|
|
|
256
257
|
const useExperience = ({
|
|
@@ -283,7 +284,9 @@ const useExperience = ({
|
|
|
283
284
|
return experience;
|
|
284
285
|
};
|
|
285
286
|
|
|
286
|
-
const ComponentMarker = /*#__PURE__*/React.forwardRef((
|
|
287
|
+
const ComponentMarker = /*#__PURE__*/React.forwardRef(({
|
|
288
|
+
hidden: _hidden = false
|
|
289
|
+
}, ref) => {
|
|
287
290
|
const {
|
|
288
291
|
logger
|
|
289
292
|
} = useNinetailed();
|
|
@@ -301,7 +304,7 @@ const ComponentMarker = /*#__PURE__*/React.forwardRef((_, ref) => {
|
|
|
301
304
|
}, [logger]);
|
|
302
305
|
React.useEffect(() => {
|
|
303
306
|
if (markerRef.current) {
|
|
304
|
-
const nextSibling = markerRef.current
|
|
307
|
+
const nextSibling = getNextSibling(markerRef.current, _hidden);
|
|
305
308
|
if (ref) {
|
|
306
309
|
if (typeof ref === 'function') {
|
|
307
310
|
ref(nextSibling);
|
|
@@ -310,7 +313,7 @@ const ComponentMarker = /*#__PURE__*/React.forwardRef((_, ref) => {
|
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
|
-
}, []);
|
|
316
|
+
}, [_hidden]);
|
|
314
317
|
return jsxRuntime.jsx("div", {
|
|
315
318
|
className: "nt-cmp-marker",
|
|
316
319
|
style: {
|
|
@@ -319,6 +322,21 @@ const ComponentMarker = /*#__PURE__*/React.forwardRef((_, ref) => {
|
|
|
319
322
|
ref: markerRef
|
|
320
323
|
});
|
|
321
324
|
});
|
|
325
|
+
const getNextSibling = (element, recursive = false) => {
|
|
326
|
+
if (!recursive) {
|
|
327
|
+
return element.nextSibling;
|
|
328
|
+
}
|
|
329
|
+
const {
|
|
330
|
+
parentElement
|
|
331
|
+
} = element;
|
|
332
|
+
if (!parentElement) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
if (parentElement.nextSibling) {
|
|
336
|
+
return parentElement.nextSibling;
|
|
337
|
+
}
|
|
338
|
+
return getNextSibling(parentElement, true);
|
|
339
|
+
};
|
|
322
340
|
|
|
323
341
|
const DefaultExperienceLoadingComponent = _a => {
|
|
324
342
|
var {
|
|
@@ -394,6 +412,7 @@ const Experience = _a => {
|
|
|
394
412
|
// @ts-ignore
|
|
395
413
|
const isComponentForwardRef = reactIs.isForwardRef(jsxRuntime.jsx(Component, {}));
|
|
396
414
|
const componentRef = React.useRef(null);
|
|
415
|
+
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
397
416
|
React.useEffect(() => {
|
|
398
417
|
const componentElement = componentRef.current;
|
|
399
418
|
if (componentElement && !(componentElement instanceof Element)) {
|
|
@@ -410,7 +429,9 @@ const Experience = _a => {
|
|
|
410
429
|
element: componentElement,
|
|
411
430
|
experience,
|
|
412
431
|
audience,
|
|
413
|
-
variant,
|
|
432
|
+
variant: isVariantHidden ? Object.assign(Object.assign({}, variant), {
|
|
433
|
+
id: `${baseline.id}-hidden`
|
|
434
|
+
}) : variant,
|
|
414
435
|
variantIndex
|
|
415
436
|
});
|
|
416
437
|
return () => {
|
|
@@ -422,7 +443,7 @@ const Experience = _a => {
|
|
|
422
443
|
return () => {
|
|
423
444
|
// noop
|
|
424
445
|
};
|
|
425
|
-
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience]);
|
|
446
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience, isVariantHidden]);
|
|
426
447
|
if (!hasVariants) {
|
|
427
448
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
428
449
|
children: [!isComponentForwardRef && jsxRuntime.jsx(ComponentMarker, {
|
|
@@ -442,10 +463,10 @@ const Experience = _a => {
|
|
|
442
463
|
component: Component
|
|
443
464
|
}));
|
|
444
465
|
}
|
|
445
|
-
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
446
466
|
if (isVariantHidden) {
|
|
447
467
|
return jsxRuntime.jsx(ComponentMarker, {
|
|
448
|
-
ref: componentRef
|
|
468
|
+
ref: componentRef,
|
|
469
|
+
hidden: true
|
|
449
470
|
}, `marker-hidden-${(experience === null || experience === void 0 ? void 0 : experience.id) || 'baseline'}-${variant.id}`);
|
|
450
471
|
}
|
|
451
472
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
1
|
import React, { createContext, useMemo, useContext, useState, useRef, useEffect, createElement, forwardRef } from 'react';
|
|
3
2
|
import { Ninetailed, selectVariant, selectHasExperienceVariants } from '@ninetailed/experience.js';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { logger, isBrowser } from '@ninetailed/experience.js-shared';
|
|
5
5
|
import { isEqual, get } from 'radash';
|
|
6
6
|
import { useInView } from 'react-intersection-observer';
|
|
@@ -50,11 +50,10 @@ const NinetailedProvider = props => {
|
|
|
50
50
|
const {
|
|
51
51
|
children
|
|
52
52
|
} = props;
|
|
53
|
-
return jsx(NinetailedContext.Provider,
|
|
54
|
-
value: ninetailed
|
|
55
|
-
}, {
|
|
53
|
+
return /*#__PURE__*/jsx(NinetailedContext.Provider, {
|
|
54
|
+
value: ninetailed,
|
|
56
55
|
children: children
|
|
57
|
-
})
|
|
56
|
+
});
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
const useNinetailed = () => {
|
|
@@ -65,42 +64,30 @@ const useNinetailed = () => {
|
|
|
65
64
|
return ninetailed;
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
80
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
81
|
-
***************************************************************************** */
|
|
82
|
-
|
|
83
|
-
function __rest(s, e) {
|
|
84
|
-
var t = {};
|
|
85
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
86
|
-
t[p] = s[p];
|
|
87
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
88
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
89
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
90
|
-
t[p[i]] = s[p[i]];
|
|
91
|
-
}
|
|
92
|
-
return t;
|
|
67
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
68
|
+
if (source == null) return {};
|
|
69
|
+
var target = {};
|
|
70
|
+
var sourceKeys = Object.keys(source);
|
|
71
|
+
var key, i;
|
|
72
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
73
|
+
key = sourceKeys[i];
|
|
74
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
75
|
+
target[key] = source[key];
|
|
76
|
+
}
|
|
77
|
+
return target;
|
|
93
78
|
}
|
|
94
79
|
|
|
80
|
+
const _excluded$3 = ["experiences"];
|
|
95
81
|
const useProfile = () => {
|
|
96
82
|
const ninetailed = useNinetailed();
|
|
97
83
|
const [profileState, setProfileState] = useState(ninetailed.profileState);
|
|
98
84
|
const profileStateRef = useRef({});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* This effect compares the old and new profile state before updating it.
|
|
88
|
+
* We use a ref to avoid an infinite loop which can happen when an empty profile state was updated with no changes.
|
|
89
|
+
* This behaviour occurred as the validation handling on the error property was not set properly in the "CreateProfile" and "UpdateProfile" endpoint types.
|
|
90
|
+
* Furthermore, it was also observed, that it "only" occurred when the preview plugin was used in parallel.
|
|
104
91
|
*/
|
|
105
92
|
useEffect(() => {
|
|
106
93
|
ninetailed.onProfileChange(profileState => {
|
|
@@ -114,8 +101,8 @@ const useProfile = () => {
|
|
|
114
101
|
}
|
|
115
102
|
});
|
|
116
103
|
}, []);
|
|
117
|
-
const profileStateWithoutExperiences =
|
|
118
|
-
return Object.assign(
|
|
104
|
+
const profileStateWithoutExperiences = _objectWithoutPropertiesLoose(profileState, _excluded$3);
|
|
105
|
+
return Object.assign({}, profileStateWithoutExperiences, {
|
|
119
106
|
loading: profileState.status === 'loading'
|
|
120
107
|
});
|
|
121
108
|
};
|
|
@@ -149,21 +136,22 @@ const TrackHasSeenComponent = ({
|
|
|
149
136
|
});
|
|
150
137
|
}
|
|
151
138
|
}, [inView]);
|
|
152
|
-
return jsxs(Fragment, {
|
|
153
|
-
children: [jsx("div", {
|
|
139
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
140
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
154
141
|
ref: ref
|
|
155
142
|
}), children]
|
|
156
143
|
});
|
|
157
144
|
};
|
|
158
145
|
|
|
159
|
-
const
|
|
160
|
-
|
|
146
|
+
const _excluded$2 = ["component", "loadingComponent", "variants", "holdout"];
|
|
147
|
+
const Personalize = _ref => {
|
|
148
|
+
let {
|
|
161
149
|
component: Component,
|
|
162
150
|
loadingComponent: LoadingComponent,
|
|
163
151
|
variants = [],
|
|
164
152
|
holdout = -1
|
|
165
|
-
} =
|
|
166
|
-
baseline =
|
|
153
|
+
} = _ref,
|
|
154
|
+
baseline = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
167
155
|
const {
|
|
168
156
|
loading,
|
|
169
157
|
variant,
|
|
@@ -174,7 +162,7 @@ const Personalize = _a => {
|
|
|
174
162
|
});
|
|
175
163
|
const hasVariants = variants.length > 0;
|
|
176
164
|
if (!hasVariants) {
|
|
177
|
-
return jsx(Component, Object.assign({}, baseline, {
|
|
165
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, baseline, {
|
|
178
166
|
ninetailed: {
|
|
179
167
|
isPersonalized,
|
|
180
168
|
audience
|
|
@@ -183,26 +171,24 @@ const Personalize = _a => {
|
|
|
183
171
|
}
|
|
184
172
|
if (loading) {
|
|
185
173
|
if (LoadingComponent) {
|
|
186
|
-
return jsx(LoadingComponent, {});
|
|
174
|
+
return /*#__PURE__*/jsx(LoadingComponent, {});
|
|
187
175
|
}
|
|
188
|
-
return jsx("div",
|
|
176
|
+
return /*#__PURE__*/jsx("div", {
|
|
189
177
|
style: {
|
|
190
178
|
opacity: 0
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
children: jsx(Component, Object.assign({}, variant, {
|
|
179
|
+
},
|
|
180
|
+
children: /*#__PURE__*/jsx(Component, Object.assign({}, variant, {
|
|
194
181
|
ninetailed: {
|
|
195
182
|
isPersonalized,
|
|
196
183
|
audience
|
|
197
184
|
}
|
|
198
185
|
}))
|
|
199
|
-
}
|
|
186
|
+
}, "hide");
|
|
200
187
|
}
|
|
201
|
-
return jsx(TrackHasSeenComponent,
|
|
188
|
+
return /*#__PURE__*/jsx(TrackHasSeenComponent, {
|
|
202
189
|
variant: variant,
|
|
203
190
|
audience: audience,
|
|
204
|
-
isPersonalized: isPersonalized
|
|
205
|
-
}, {
|
|
191
|
+
isPersonalized: isPersonalized,
|
|
206
192
|
children: /*#__PURE__*/createElement(Component, Object.assign({}, variant, {
|
|
207
193
|
key: `${audience.id}-${variant.id}`,
|
|
208
194
|
ninetailed: {
|
|
@@ -210,7 +196,7 @@ const Personalize = _a => {
|
|
|
210
196
|
audience
|
|
211
197
|
}
|
|
212
198
|
}))
|
|
213
|
-
})
|
|
199
|
+
});
|
|
214
200
|
};
|
|
215
201
|
|
|
216
202
|
const generateSelectors = id => {
|
|
@@ -228,8 +214,10 @@ const selectValueFromProfile = (profile, id) => {
|
|
|
228
214
|
}
|
|
229
215
|
return get(profile, matchingSelector);
|
|
230
216
|
};
|
|
217
|
+
|
|
231
218
|
const MergeTag = ({
|
|
232
|
-
id
|
|
219
|
+
id,
|
|
220
|
+
fallback
|
|
233
221
|
}) => {
|
|
234
222
|
const {
|
|
235
223
|
loading,
|
|
@@ -238,11 +226,10 @@ const MergeTag = ({
|
|
|
238
226
|
if (loading || !profile) {
|
|
239
227
|
return null;
|
|
240
228
|
}
|
|
241
|
-
const value = selectValueFromProfile(profile, id);
|
|
242
|
-
|
|
243
|
-
return jsx(Fragment, {
|
|
229
|
+
const value = selectValueFromProfile(profile, id) || fallback;
|
|
230
|
+
return value ? /*#__PURE__*/jsx(Fragment, {
|
|
244
231
|
children: value
|
|
245
|
-
});
|
|
232
|
+
}) : null;
|
|
246
233
|
};
|
|
247
234
|
|
|
248
235
|
const useExperience = ({
|
|
@@ -275,25 +262,27 @@ const useExperience = ({
|
|
|
275
262
|
return experience;
|
|
276
263
|
};
|
|
277
264
|
|
|
278
|
-
const ComponentMarker = /*#__PURE__*/forwardRef((
|
|
265
|
+
const ComponentMarker = /*#__PURE__*/forwardRef(({
|
|
266
|
+
hidden: _hidden = false
|
|
267
|
+
}, ref) => {
|
|
279
268
|
const {
|
|
280
269
|
logger
|
|
281
270
|
} = useNinetailed();
|
|
282
271
|
const markerRef = useRef(null);
|
|
283
272
|
useEffect(() => {
|
|
284
|
-
var
|
|
285
|
-
/*
|
|
286
|
-
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
287
|
-
See: https://github.com/facebook/react/issues/1881
|
|
273
|
+
var _markerRef$current;
|
|
274
|
+
/*
|
|
275
|
+
Due to React's limitation on setting !important styles during rendering, we set the display property on the DOM element directly.
|
|
276
|
+
See: https://github.com/facebook/react/issues/1881
|
|
288
277
|
*/
|
|
289
|
-
(
|
|
278
|
+
(_markerRef$current = markerRef.current) == null || _markerRef$current.style.setProperty('display', 'none', 'important');
|
|
290
279
|
}, []);
|
|
291
280
|
useEffect(() => {
|
|
292
281
|
logger.debug('Using fallback mechanism to detect when experiences are seen. This can lead to inaccurate results. Consider using a forwardRef instead. See: https://docs.ninetailed.io/for-developers/experience-sdk/rendering-experiences#tracking-impressions-of-experiences');
|
|
293
282
|
}, [logger]);
|
|
294
283
|
useEffect(() => {
|
|
295
284
|
if (markerRef.current) {
|
|
296
|
-
const nextSibling = markerRef.current
|
|
285
|
+
const nextSibling = getNextSibling(markerRef.current, _hidden);
|
|
297
286
|
if (ref) {
|
|
298
287
|
if (typeof ref === 'function') {
|
|
299
288
|
ref(nextSibling);
|
|
@@ -302,8 +291,8 @@ const ComponentMarker = /*#__PURE__*/forwardRef((_, ref) => {
|
|
|
302
291
|
}
|
|
303
292
|
}
|
|
304
293
|
}
|
|
305
|
-
}, []);
|
|
306
|
-
return jsx("div", {
|
|
294
|
+
}, [_hidden]);
|
|
295
|
+
return /*#__PURE__*/jsx("div", {
|
|
307
296
|
className: "nt-cmp-marker",
|
|
308
297
|
style: {
|
|
309
298
|
display: 'none'
|
|
@@ -311,14 +300,31 @@ const ComponentMarker = /*#__PURE__*/forwardRef((_, ref) => {
|
|
|
311
300
|
ref: markerRef
|
|
312
301
|
});
|
|
313
302
|
});
|
|
303
|
+
const getNextSibling = (element, recursive = false) => {
|
|
304
|
+
if (!recursive) {
|
|
305
|
+
return element.nextSibling;
|
|
306
|
+
}
|
|
307
|
+
const {
|
|
308
|
+
parentElement
|
|
309
|
+
} = element;
|
|
310
|
+
if (!parentElement) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
if (parentElement.nextSibling) {
|
|
314
|
+
return parentElement.nextSibling;
|
|
315
|
+
}
|
|
316
|
+
return getNextSibling(parentElement, true);
|
|
317
|
+
};
|
|
314
318
|
|
|
315
|
-
const
|
|
316
|
-
|
|
319
|
+
const _excluded$1 = ["component", "unhideAfterMs", "passthroughProps"],
|
|
320
|
+
_excluded2 = ["experiences", "component", "loadingComponent", "passthroughProps"];
|
|
321
|
+
const DefaultExperienceLoadingComponent = _ref => {
|
|
322
|
+
let {
|
|
317
323
|
component: Component,
|
|
318
324
|
unhideAfterMs = 5000,
|
|
319
325
|
passthroughProps
|
|
320
|
-
} =
|
|
321
|
-
baseline =
|
|
326
|
+
} = _ref,
|
|
327
|
+
baseline = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
322
328
|
const {
|
|
323
329
|
logger
|
|
324
330
|
} = useNinetailed();
|
|
@@ -333,12 +339,11 @@ const DefaultExperienceLoadingComponent = _a => {
|
|
|
333
339
|
};
|
|
334
340
|
}, []);
|
|
335
341
|
if (hidden) {
|
|
336
|
-
return jsx("div",
|
|
342
|
+
return /*#__PURE__*/jsx("div", {
|
|
337
343
|
style: {
|
|
338
344
|
opacity: 0
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
children: jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
345
|
+
},
|
|
346
|
+
children: /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
342
347
|
ninetailed: {
|
|
343
348
|
isPersonalized: false,
|
|
344
349
|
audience: {
|
|
@@ -346,9 +351,9 @@ const DefaultExperienceLoadingComponent = _a => {
|
|
|
346
351
|
}
|
|
347
352
|
}
|
|
348
353
|
}))
|
|
349
|
-
}
|
|
354
|
+
}, "hide");
|
|
350
355
|
}
|
|
351
|
-
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
356
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
352
357
|
ninetailed: {
|
|
353
358
|
isPersonalized: false,
|
|
354
359
|
audience: {
|
|
@@ -357,14 +362,14 @@ const DefaultExperienceLoadingComponent = _a => {
|
|
|
357
362
|
}
|
|
358
363
|
}));
|
|
359
364
|
};
|
|
360
|
-
const Experience =
|
|
361
|
-
|
|
365
|
+
const Experience = _ref2 => {
|
|
366
|
+
let {
|
|
362
367
|
experiences,
|
|
363
368
|
component: Component,
|
|
364
369
|
loadingComponent: LoadingComponent = DefaultExperienceLoadingComponent,
|
|
365
370
|
passthroughProps
|
|
366
|
-
} =
|
|
367
|
-
baseline =
|
|
371
|
+
} = _ref2,
|
|
372
|
+
baseline = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
368
373
|
const {
|
|
369
374
|
observeElement,
|
|
370
375
|
unobserveElement,
|
|
@@ -382,10 +387,12 @@ const Experience = _a => {
|
|
|
382
387
|
baseline,
|
|
383
388
|
experiences
|
|
384
389
|
});
|
|
390
|
+
|
|
385
391
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
386
392
|
// @ts-ignore
|
|
387
|
-
const isComponentForwardRef = isForwardRef(jsx(Component, {}));
|
|
393
|
+
const isComponentForwardRef = isForwardRef( /*#__PURE__*/jsx(Component, {}));
|
|
388
394
|
const componentRef = useRef(null);
|
|
395
|
+
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
389
396
|
useEffect(() => {
|
|
390
397
|
const componentElement = componentRef.current;
|
|
391
398
|
if (componentElement && !(componentElement instanceof Element)) {
|
|
@@ -402,7 +409,9 @@ const Experience = _a => {
|
|
|
402
409
|
element: componentElement,
|
|
403
410
|
experience,
|
|
404
411
|
audience,
|
|
405
|
-
variant,
|
|
412
|
+
variant: isVariantHidden ? Object.assign({}, variant, {
|
|
413
|
+
id: `${baseline.id}-hidden`
|
|
414
|
+
}) : variant,
|
|
406
415
|
variantIndex
|
|
407
416
|
});
|
|
408
417
|
return () => {
|
|
@@ -414,12 +423,12 @@ const Experience = _a => {
|
|
|
414
423
|
return () => {
|
|
415
424
|
// noop
|
|
416
425
|
};
|
|
417
|
-
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience]);
|
|
426
|
+
}, [observeElement, unobserveElement, experience, baseline, variant, variantIndex, audience, isVariantHidden]);
|
|
418
427
|
if (!hasVariants) {
|
|
419
|
-
return jsxs(Fragment, {
|
|
420
|
-
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
428
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
429
|
+
children: [!isComponentForwardRef && /*#__PURE__*/jsx(ComponentMarker, {
|
|
421
430
|
ref: componentRef
|
|
422
|
-
}, `marker-no-variants-${(experience
|
|
431
|
+
}, `marker-no-variants-${(experience == null ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, passthroughProps, baseline, {
|
|
423
432
|
key: baseline.id
|
|
424
433
|
}, isComponentForwardRef ? {
|
|
425
434
|
ref: componentRef
|
|
@@ -434,21 +443,21 @@ const Experience = _a => {
|
|
|
434
443
|
component: Component
|
|
435
444
|
}));
|
|
436
445
|
}
|
|
437
|
-
const isVariantHidden = 'hidden' in variant && variant.hidden;
|
|
438
446
|
if (isVariantHidden) {
|
|
439
|
-
return jsx(ComponentMarker, {
|
|
440
|
-
ref: componentRef
|
|
441
|
-
|
|
447
|
+
return /*#__PURE__*/jsx(ComponentMarker, {
|
|
448
|
+
ref: componentRef,
|
|
449
|
+
hidden: true
|
|
450
|
+
}, `marker-hidden-${(experience == null ? void 0 : experience.id) || 'baseline'}-${variant.id}`);
|
|
442
451
|
}
|
|
443
|
-
return jsxs(Fragment, {
|
|
444
|
-
children: [!isComponentForwardRef && jsx(ComponentMarker, {
|
|
452
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
453
|
+
children: [!isComponentForwardRef && /*#__PURE__*/jsx(ComponentMarker, {
|
|
445
454
|
ref: componentRef
|
|
446
|
-
}, `marker-${(experience
|
|
447
|
-
key: `${(experience
|
|
455
|
+
}, `marker-${(experience == null ? void 0 : experience.id) || 'baseline'}-${variant.id}`), /*#__PURE__*/createElement(Component, Object.assign({}, Object.assign({}, passthroughProps, variant), {
|
|
456
|
+
key: `${(experience == null ? void 0 : experience.id) || 'baseline'}-${variant.id}`,
|
|
448
457
|
ninetailed: {
|
|
449
458
|
isPersonalized,
|
|
450
459
|
audience: {
|
|
451
|
-
id: (audience
|
|
460
|
+
id: (audience == null ? void 0 : audience.id) || 'all visitors'
|
|
452
461
|
}
|
|
453
462
|
}
|
|
454
463
|
}, isComponentForwardRef ? {
|
|
@@ -457,18 +466,18 @@ const Experience = _a => {
|
|
|
457
466
|
});
|
|
458
467
|
};
|
|
459
468
|
|
|
469
|
+
const _excluded = ["experiences", "component", "passthroughProps"];
|
|
460
470
|
const ESRContext = /*#__PURE__*/React.createContext(undefined);
|
|
461
471
|
const ESRProvider = ({
|
|
462
472
|
experienceVariantsMap,
|
|
463
473
|
children
|
|
464
474
|
}) => {
|
|
465
|
-
return jsx(ESRContext.Provider,
|
|
475
|
+
return /*#__PURE__*/jsx(ESRContext.Provider, {
|
|
466
476
|
value: {
|
|
467
477
|
experienceVariantsMap
|
|
468
|
-
}
|
|
469
|
-
}, {
|
|
478
|
+
},
|
|
470
479
|
children: children
|
|
471
|
-
})
|
|
480
|
+
});
|
|
472
481
|
};
|
|
473
482
|
const useESR = () => {
|
|
474
483
|
const context = React.useContext(ESRContext);
|
|
@@ -479,19 +488,19 @@ const useESR = () => {
|
|
|
479
488
|
experienceVariantsMap: context.experienceVariantsMap
|
|
480
489
|
};
|
|
481
490
|
};
|
|
482
|
-
const ESRLoadingComponent =
|
|
483
|
-
|
|
491
|
+
const ESRLoadingComponent = _ref => {
|
|
492
|
+
let {
|
|
484
493
|
experiences,
|
|
485
494
|
component: Component,
|
|
486
495
|
passthroughProps
|
|
487
|
-
} =
|
|
488
|
-
baseline =
|
|
496
|
+
} = _ref,
|
|
497
|
+
baseline = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
489
498
|
const {
|
|
490
499
|
experienceVariantsMap
|
|
491
500
|
} = useESR();
|
|
492
501
|
const experience = experiences.find(experience => Object.prototype.hasOwnProperty.call(experienceVariantsMap, experience.id));
|
|
493
502
|
if (!experience) {
|
|
494
|
-
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
503
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
495
504
|
ninetailed: {
|
|
496
505
|
isPersonalized: false,
|
|
497
506
|
audience: {
|
|
@@ -502,7 +511,7 @@ const ESRLoadingComponent = _a => {
|
|
|
502
511
|
}
|
|
503
512
|
const component = experience.components.find(component => component.baseline.id === baseline.id);
|
|
504
513
|
if (!component) {
|
|
505
|
-
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
514
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
506
515
|
ninetailed: {
|
|
507
516
|
isPersonalized: false,
|
|
508
517
|
audience: {
|
|
@@ -512,7 +521,7 @@ const ESRLoadingComponent = _a => {
|
|
|
512
521
|
}));
|
|
513
522
|
}
|
|
514
523
|
if (experienceVariantsMap[experience.id] === 0) {
|
|
515
|
-
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
524
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
516
525
|
ninetailed: {
|
|
517
526
|
isPersonalized: false,
|
|
518
527
|
audience: {
|
|
@@ -523,7 +532,7 @@ const ESRLoadingComponent = _a => {
|
|
|
523
532
|
}
|
|
524
533
|
const variant = component.variants[experienceVariantsMap[experience.id] - 1];
|
|
525
534
|
if (!variant) {
|
|
526
|
-
return jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
535
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, baseline, {
|
|
527
536
|
ninetailed: {
|
|
528
537
|
isPersonalized: false,
|
|
529
538
|
audience: {
|
|
@@ -532,7 +541,7 @@ const ESRLoadingComponent = _a => {
|
|
|
532
541
|
}
|
|
533
542
|
}));
|
|
534
543
|
}
|
|
535
|
-
return jsx(Component, Object.assign({}, passthroughProps, variant, {
|
|
544
|
+
return /*#__PURE__*/jsx(Component, Object.assign({}, passthroughProps, variant, {
|
|
536
545
|
ninetailed: {
|
|
537
546
|
isPersonalized: false,
|
|
538
547
|
audience: {
|
package/package.json
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-react",
|
|
3
|
-
"version": "7.6.0-beta.
|
|
4
|
-
"
|
|
5
|
-
"react": ">=16.8.0"
|
|
6
|
-
},
|
|
7
|
-
"license": "BSL-1.1",
|
|
8
|
-
"module": "./index.js",
|
|
9
|
-
"main": "./index.cjs",
|
|
10
|
-
"type": "module",
|
|
11
|
-
"types": "./src/index.d.ts",
|
|
3
|
+
"version": "7.6.0-beta.2",
|
|
4
|
+
"description": "Ninetailed SDK for React",
|
|
12
5
|
"dependencies": {
|
|
13
|
-
"@ninetailed/experience.js": "
|
|
14
|
-
"@ninetailed/experience.js-shared": "
|
|
6
|
+
"@ninetailed/experience.js": "*",
|
|
7
|
+
"@ninetailed/experience.js-shared": "*",
|
|
8
|
+
"@ninetailed/experience.js-plugin-analytics": "*",
|
|
15
9
|
"radash": "10.9.0",
|
|
16
10
|
"react-intersection-observer": "8.34.0",
|
|
17
|
-
"react-is": "18.2.0"
|
|
18
|
-
|
|
11
|
+
"react-is": "18.2.0",
|
|
12
|
+
"@testing-library/react-hooks": "7.0.2",
|
|
13
|
+
"@testing-library/react": "13.4.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": ">=16.8.0"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/ninetailed-inc/experience.js.git",
|
|
22
|
+
"directory": "packages/sdks/react"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"react",
|
|
26
|
+
"ninetailed",
|
|
27
|
+
"personalization",
|
|
28
|
+
"a/b testing"
|
|
29
|
+
],
|
|
30
|
+
"module": "./index.esm.js",
|
|
31
|
+
"main": "./index.cjs.js"
|
|
19
32
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
type ComponentMarkerProps = {
|
|
3
|
+
hidden?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const ComponentMarker: React.ForwardRefExoticComponent<ComponentMarkerProps & React.RefAttributes<unknown>>;
|
|
6
|
+
export {};
|
|
@@ -12,5 +12,5 @@ export declare const ESRProvider: React.FC<PropsWithChildren<ESRProviderProps>>;
|
|
|
12
12
|
export declare const useESR: () => {
|
|
13
13
|
experienceVariantsMap: Record<string, number>;
|
|
14
14
|
};
|
|
15
|
-
export declare const ESRLoadingComponent: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, passthroughProps, ...baseline }: ExperienceBaseProps<P, PassThroughProps, Variant>) => JSX.Element;
|
|
15
|
+
export declare const ESRLoadingComponent: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, passthroughProps, ...baseline }: ExperienceBaseProps<P, PassThroughProps, Variant>) => import("react/jsx-runtime").JSX.Element;
|
|
16
16
|
export {};
|
|
@@ -23,5 +23,5 @@ type DefaultExperienceLoadingComponentProps = ExperienceBaseProps<Record<string,
|
|
|
23
23
|
unhideAfterMs?: number;
|
|
24
24
|
};
|
|
25
25
|
export declare const DefaultExperienceLoadingComponent: React.FC<DefaultExperienceLoadingComponentProps>;
|
|
26
|
-
export declare const Experience: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, loadingComponent: LoadingComponent, passthroughProps, ...baseline }: ExperienceProps<P, PassThroughProps, Variant>) => JSX.Element;
|
|
26
|
+
export declare const Experience: <P, PassThroughProps extends Partial<P> = Partial<P>, Variant extends Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference = Pick<P, Exclude<keyof P, keyof PassThroughProps>> & Reference>({ experiences, component: Component, loadingComponent: LoadingComponent, passthroughProps, ...baseline }: ExperienceProps<P, PassThroughProps, Variant>) => import("react/jsx-runtime").JSX.Element;
|
|
27
27
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MergeTag';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Ninetailed,
|
|
3
|
-
import {
|
|
2
|
+
import { Ninetailed, OnInitProfileId, Storage } from '@ninetailed/experience.js';
|
|
3
|
+
import { Locale, OnErrorHandler, OnLogHandler, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
|
|
4
|
+
import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
5
|
export type NinetailedProviderInstantiationProps = {
|
|
5
6
|
clientId: string;
|
|
6
7
|
environment?: string;
|
|
7
8
|
preview?: boolean;
|
|
8
9
|
url?: string;
|
|
9
10
|
plugins?: (NinetailedPlugin | NinetailedPlugin[])[];
|
|
10
|
-
profile?: Profile;
|
|
11
11
|
locale?: Locale;
|
|
12
12
|
requestTimeout?: number;
|
|
13
13
|
onLog?: OnLogHandler;
|
|
@@ -21,4 +21,4 @@ export type NinetailedProviderInstantiationProps = {
|
|
|
21
21
|
export type NinetailedProviderProps = NinetailedProviderInstantiationProps | {
|
|
22
22
|
ninetailed: Ninetailed;
|
|
23
23
|
};
|
|
24
|
-
export declare const NinetailedProvider: (props: React.PropsWithChildren<NinetailedProviderProps>) => JSX.Element;
|
|
24
|
+
export declare const NinetailedProvider: (props: React.PropsWithChildren<NinetailedProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
package/src/lib/Personalize.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ type PersonalizeProps<P> = Baseline<P> & {
|
|
|
19
19
|
loadingComponent?: React.ComponentType;
|
|
20
20
|
holdout?: number;
|
|
21
21
|
};
|
|
22
|
-
export declare const Personalize: <P extends object>({ component: Component, loadingComponent: LoadingComponent, variants, holdout, ...baseline }: PersonalizeProps<P>) => JSX.Element;
|
|
22
|
+
export declare const Personalize: <P extends object>({ component: Component, loadingComponent: LoadingComponent, variants, holdout, ...baseline }: PersonalizeProps<P>) => import("react/jsx-runtime").JSX.Element;
|
|
23
23
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Reference } from '@ninetailed/experience.js-shared';
|
|
2
1
|
import { NinetailedInstance } from '@ninetailed/experience.js';
|
|
2
|
+
import { Reference } from '@ninetailed/experience.js-shared';
|
|
3
3
|
export declare const useNinetailed: <TBaseline extends Reference = Reference, TVariant extends Reference = Reference>() => NinetailedInstance<TBaseline, TVariant>;
|
package/src/lib/MergeTag.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { Profile } from '@ninetailed/experience.js';
|
|
3
|
-
type MergeTagProps = {
|
|
4
|
-
id: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const generateSelectors: (id: string) => string[];
|
|
7
|
-
export declare const selectValueFromProfile: (profile: Profile, id: string) => unknown;
|
|
8
|
-
export declare const MergeTag: React.FC<React.PropsWithChildren<MergeTagProps>>;
|
|
9
|
-
export {};
|