@uniformdev/context-vue 16.2.1-nuxt.249 → 16.2.1-nuxt.325
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/index.d.ts +2 -4
- package/dist/index.esm.js +612 -1
- package/dist/index.js +653 -1
- package/dist/index.mjs +612 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1 +1,612 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/Test/Test.ts
|
|
2
|
+
import { defineComponent as defineComponent3 } from "vue-demi";
|
|
3
|
+
|
|
4
|
+
// ../canvas-vue/src/utils/vue-demi-h.ts
|
|
5
|
+
import { isVue3, h as vueH } from "vue-demi";
|
|
6
|
+
var RESERVED_PROP_NAMES = ["key", "ref", "slot", "class", "style"];
|
|
7
|
+
var DOM_PROP_NAMES = ["innerHTML"];
|
|
8
|
+
var h = (...args) => {
|
|
9
|
+
if (isVue3) {
|
|
10
|
+
return vueH(...args);
|
|
11
|
+
}
|
|
12
|
+
const [type, propsOrChildren, children] = args;
|
|
13
|
+
const isChildrenOnly = Array.isArray(propsOrChildren) || typeof propsOrChildren !== "object";
|
|
14
|
+
if (isChildrenOnly) {
|
|
15
|
+
return vueH(...args);
|
|
16
|
+
}
|
|
17
|
+
const propsAndFriends = propsOrChildren;
|
|
18
|
+
const groupedProps = groupPropsAndFriends(type, propsAndFriends);
|
|
19
|
+
console.log("groupedProps", groupedProps);
|
|
20
|
+
const scopedSlots = getScopedSlots(children);
|
|
21
|
+
return vueH(type, { ...groupedProps, scopedSlots }, children);
|
|
22
|
+
};
|
|
23
|
+
function groupPropsAndFriends(type, propsAndFriends) {
|
|
24
|
+
const groupedProps = Object.entries(propsAndFriends).reduce((object, [key, value]) => {
|
|
25
|
+
if (isReserved(key)) {
|
|
26
|
+
object[key] = value;
|
|
27
|
+
} else if (isProp(type, key)) {
|
|
28
|
+
object.props[key] = value;
|
|
29
|
+
} else if (isDomProp(key)) {
|
|
30
|
+
object.domProps[key] = value;
|
|
31
|
+
} else if (isEvent(key)) {
|
|
32
|
+
object.on[getEventName(key)] = value;
|
|
33
|
+
} else {
|
|
34
|
+
object.attrs[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return object;
|
|
37
|
+
}, {
|
|
38
|
+
props: {},
|
|
39
|
+
attrs: {},
|
|
40
|
+
on: {},
|
|
41
|
+
domProps: {},
|
|
42
|
+
key: void 0,
|
|
43
|
+
class: void 0,
|
|
44
|
+
style: void 0,
|
|
45
|
+
ref: void 0,
|
|
46
|
+
slot: void 0
|
|
47
|
+
});
|
|
48
|
+
return groupedProps;
|
|
49
|
+
}
|
|
50
|
+
function isProp(type, propName) {
|
|
51
|
+
const isNativeElement = typeof type === "string";
|
|
52
|
+
if (isNativeElement) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return Boolean(type.props[propName]);
|
|
56
|
+
}
|
|
57
|
+
function isDomProp(propName) {
|
|
58
|
+
return DOM_PROP_NAMES.includes(propName);
|
|
59
|
+
}
|
|
60
|
+
function isEvent(propName) {
|
|
61
|
+
return /^on[A-Z]/.test(propName);
|
|
62
|
+
}
|
|
63
|
+
function getEventName(propName) {
|
|
64
|
+
return propName.replace(/^on/, "").toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
function isReserved(propName) {
|
|
67
|
+
return RESERVED_PROP_NAMES.includes(propName);
|
|
68
|
+
}
|
|
69
|
+
function getScopedSlots(children) {
|
|
70
|
+
if (typeof children === "function") {
|
|
71
|
+
return { default: children };
|
|
72
|
+
}
|
|
73
|
+
if (typeof children === "object" && !Array.isArray(children)) {
|
|
74
|
+
return children;
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/utils/constants.ts
|
|
80
|
+
var isServer = typeof window === "undefined";
|
|
81
|
+
|
|
82
|
+
// src/components/Test/TestStandard.ts
|
|
83
|
+
import { defineComponent, toRaw } from "vue-demi";
|
|
84
|
+
|
|
85
|
+
// src/providers/useUniformContext.ts
|
|
86
|
+
import { inject, provide } from "vue-demi";
|
|
87
|
+
import { parse as parseCookie } from "cookie-es";
|
|
88
|
+
var uniformContextInjectionKey = "uniformContextInjectionKey";
|
|
89
|
+
var provideUniformContext = ({
|
|
90
|
+
context,
|
|
91
|
+
outputType = "standard",
|
|
92
|
+
trackRouteOnRender = true,
|
|
93
|
+
vueAppInstance
|
|
94
|
+
}) => {
|
|
95
|
+
const payload = {
|
|
96
|
+
context,
|
|
97
|
+
outputType
|
|
98
|
+
};
|
|
99
|
+
if (vueAppInstance) {
|
|
100
|
+
vueAppInstance.provide(uniformContextInjectionKey, payload);
|
|
101
|
+
} else {
|
|
102
|
+
provide(uniformContextInjectionKey, payload);
|
|
103
|
+
}
|
|
104
|
+
if (trackRouteOnRender) {
|
|
105
|
+
onRouteChange(context);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function onRouteChange(context) {
|
|
109
|
+
if (isServer) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
context == null ? void 0 : context.update({
|
|
113
|
+
url: new URL(window.location.href),
|
|
114
|
+
cookies: parseCookie(document.cookie)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var useUniformContext = () => {
|
|
118
|
+
const contextData = inject(uniformContextInjectionKey);
|
|
119
|
+
if (!contextData) {
|
|
120
|
+
throw Error(`Could not inject Uniform's Context, make sure you're using <UniformContextProvider /> or the Uniform Nuxt module with a valid manifest.`);
|
|
121
|
+
}
|
|
122
|
+
return contextData;
|
|
123
|
+
};
|
|
124
|
+
function isUsingUniformContext() {
|
|
125
|
+
try {
|
|
126
|
+
return Boolean(inject(uniformContextInjectionKey, null));
|
|
127
|
+
} catch (e) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/components/Test/TestStandard.ts
|
|
133
|
+
var TestStandard = defineComponent({
|
|
134
|
+
name: "TestStandard",
|
|
135
|
+
inheritAttrs: false,
|
|
136
|
+
props: {
|
|
137
|
+
name: {
|
|
138
|
+
type: String,
|
|
139
|
+
required: true
|
|
140
|
+
},
|
|
141
|
+
variations: {
|
|
142
|
+
type: Array,
|
|
143
|
+
required: true
|
|
144
|
+
},
|
|
145
|
+
component: {
|
|
146
|
+
type: [Object, Function],
|
|
147
|
+
required: true
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
setup(props) {
|
|
151
|
+
const { context: uniformContext } = useUniformContext();
|
|
152
|
+
const { result } = uniformContext.test({
|
|
153
|
+
name: toRaw(props.name),
|
|
154
|
+
variations: toRaw(props.variations)
|
|
155
|
+
});
|
|
156
|
+
if (!result) {
|
|
157
|
+
return () => null;
|
|
158
|
+
}
|
|
159
|
+
return () => h(props.component, { ...result });
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
var TestStandard_default = TestStandard;
|
|
163
|
+
|
|
164
|
+
// src/components/Test/TestEdge.ts
|
|
165
|
+
import { defineComponent as defineComponent2 } from "vue-demi";
|
|
166
|
+
import { ScriptType, EdgeNodeTagName } from "@uniformdev/context";
|
|
167
|
+
var TestEdge = defineComponent2({
|
|
168
|
+
name: "TestEdge",
|
|
169
|
+
inheritAttrs: false,
|
|
170
|
+
props: {
|
|
171
|
+
name: {
|
|
172
|
+
type: String,
|
|
173
|
+
required: true
|
|
174
|
+
},
|
|
175
|
+
variations: {
|
|
176
|
+
type: Array,
|
|
177
|
+
required: true
|
|
178
|
+
},
|
|
179
|
+
component: {
|
|
180
|
+
type: [Object, Function],
|
|
181
|
+
required: true
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
setup(props) {
|
|
185
|
+
const options = {
|
|
186
|
+
name: props.name
|
|
187
|
+
};
|
|
188
|
+
return () => [
|
|
189
|
+
h(EdgeNodeTagName, { "data-type": ScriptType.TestStart, innerHTML: JSON.stringify(options) }),
|
|
190
|
+
props.variations.map((variation) => {
|
|
191
|
+
return [
|
|
192
|
+
h(EdgeNodeTagName, {
|
|
193
|
+
"data-type": ScriptType.ListItemSettings,
|
|
194
|
+
key: `LIS-${variation.id}`,
|
|
195
|
+
innerHTML: JSON.stringify({ id: variation.id })
|
|
196
|
+
}),
|
|
197
|
+
h(EdgeNodeTagName, { "data-type": ScriptType.ListItem, key: `LI-${variation.id}` }, h(props.component, { ...variation }))
|
|
198
|
+
];
|
|
199
|
+
}),
|
|
200
|
+
h(EdgeNodeTagName, { "data-type": ScriptType.TestEnd })
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
var TestEdge_default = TestEdge;
|
|
205
|
+
|
|
206
|
+
// src/components/Test/Test.ts
|
|
207
|
+
var Test = defineComponent3({
|
|
208
|
+
name: "Test",
|
|
209
|
+
inheritAttrs: false,
|
|
210
|
+
props: {
|
|
211
|
+
name: {
|
|
212
|
+
type: String,
|
|
213
|
+
required: true
|
|
214
|
+
},
|
|
215
|
+
variations: {
|
|
216
|
+
type: Array,
|
|
217
|
+
required: true
|
|
218
|
+
},
|
|
219
|
+
component: {
|
|
220
|
+
type: [Object, Function],
|
|
221
|
+
required: true
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
setup(props) {
|
|
225
|
+
const { outputType } = useUniformContext();
|
|
226
|
+
return () => !isServer || outputType === "standard" ? h(TestStandard_default, { ...props }) : h(TestEdge_default, { ...props });
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
var Test_default = Test;
|
|
230
|
+
|
|
231
|
+
// src/components/UniformContextProvider.ts
|
|
232
|
+
import { defineComponent as defineComponent4 } from "vue-demi";
|
|
233
|
+
import { SERVER_STATE_ID } from "@uniformdev/context";
|
|
234
|
+
var UniformContextProvider = defineComponent4({
|
|
235
|
+
name: "UniformContextProvider",
|
|
236
|
+
inheritAttrs: false,
|
|
237
|
+
props: {
|
|
238
|
+
context: {
|
|
239
|
+
type: Object,
|
|
240
|
+
required: true
|
|
241
|
+
},
|
|
242
|
+
outputType: {
|
|
243
|
+
type: String,
|
|
244
|
+
default: "standard"
|
|
245
|
+
},
|
|
246
|
+
trackRouteOnRender: {
|
|
247
|
+
type: Boolean,
|
|
248
|
+
default: true
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
setup(props, context) {
|
|
252
|
+
provideUniformContext(props);
|
|
253
|
+
return () => h("article", [context.slots.default(), TransferState(props.context)]);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
var UniformContextProvider_default = UniformContextProvider;
|
|
257
|
+
function TransferState(context) {
|
|
258
|
+
const state = context.getServerToClientTransitionState();
|
|
259
|
+
return h("script", { id: SERVER_STATE_ID, type: "application/json", innerHTML: JSON.stringify(state) });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/components/personalize/Personalize.ts
|
|
263
|
+
import { defineComponent as defineComponent8 } from "vue-demi";
|
|
264
|
+
|
|
265
|
+
// src/components/personalize/PersonalizeStandard.ts
|
|
266
|
+
import { defineComponent as defineComponent6, ref as ref2, watch, toRaw as toRaw2 } from "vue-demi";
|
|
267
|
+
|
|
268
|
+
// src/providers/useScores.ts
|
|
269
|
+
import { ref, watchEffect } from "vue-demi";
|
|
270
|
+
import { dequal } from "dequal/lite";
|
|
271
|
+
var useScores = () => {
|
|
272
|
+
const { context } = useUniformContext();
|
|
273
|
+
const scores = ref(context.scores);
|
|
274
|
+
watchEffect(() => {
|
|
275
|
+
const scoringChangeListener = (updatedScores) => scores.value = updatedScores;
|
|
276
|
+
const currentScores = context.scores;
|
|
277
|
+
if (!dequal(scores.value, currentScores)) {
|
|
278
|
+
scores.value = currentScores;
|
|
279
|
+
}
|
|
280
|
+
context.events.on("scoresUpdated", scoringChangeListener);
|
|
281
|
+
return () => {
|
|
282
|
+
context.events.off("scoresUpdated", scoringChangeListener);
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
return scores;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/components/personalize/PersonalizeProvider.ts
|
|
289
|
+
import { defineComponent as defineComponent5 } from "vue-demi";
|
|
290
|
+
|
|
291
|
+
// src/providers/useIsPersonalized.ts
|
|
292
|
+
import { provide as provide2, inject as inject2 } from "vue-demi";
|
|
293
|
+
var isPersonalizedSymbol = Symbol("uniformIsPersonalized");
|
|
294
|
+
var provideIsPersonalized = (isPersonalized) => {
|
|
295
|
+
provide2(isPersonalizedSymbol, isPersonalized);
|
|
296
|
+
};
|
|
297
|
+
var useIsPersonalized = () => {
|
|
298
|
+
return inject2(isPersonalizedSymbol, false);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/components/personalize/PersonalizeProvider.ts
|
|
302
|
+
var PersonalizeProvider = defineComponent5({
|
|
303
|
+
name: "PersonalizeProvider",
|
|
304
|
+
inheritAttrs: false,
|
|
305
|
+
props: {
|
|
306
|
+
personalized: Boolean
|
|
307
|
+
},
|
|
308
|
+
setup(props, context) {
|
|
309
|
+
console.log("PersonalizeProvider props", JSON.stringify(props, null, 2));
|
|
310
|
+
console.log("PersonalizeProvider context", JSON.stringify(context, null, 2));
|
|
311
|
+
provideIsPersonalized(true);
|
|
312
|
+
return () => h(context.slots.default, {
|
|
313
|
+
...props
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
var PersonalizeProvider_default = PersonalizeProvider;
|
|
318
|
+
|
|
319
|
+
// src/components/personalize/PersonalizeStandard.ts
|
|
320
|
+
var PersonalizeStandard = defineComponent6({
|
|
321
|
+
name: "PersonalizeStandard",
|
|
322
|
+
inheritAttrs: false,
|
|
323
|
+
props: {
|
|
324
|
+
name: {
|
|
325
|
+
type: String,
|
|
326
|
+
required: true
|
|
327
|
+
},
|
|
328
|
+
variations: {
|
|
329
|
+
type: Array,
|
|
330
|
+
required: true
|
|
331
|
+
},
|
|
332
|
+
component: {
|
|
333
|
+
type: [Function, Object],
|
|
334
|
+
required: true
|
|
335
|
+
},
|
|
336
|
+
count: {
|
|
337
|
+
type: Number,
|
|
338
|
+
default: 1
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
setup(props) {
|
|
342
|
+
const { context: uniformContext } = useUniformContext();
|
|
343
|
+
const scores = useScores();
|
|
344
|
+
const personalize = () => {
|
|
345
|
+
var _a;
|
|
346
|
+
return uniformContext.personalize({
|
|
347
|
+
name: toRaw2(props.name),
|
|
348
|
+
variations: toRaw2(props.variations),
|
|
349
|
+
take: (_a = toRaw2(props.count)) != null ? _a : 1
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
const personalizedResult = ref2(personalize());
|
|
353
|
+
watch([scores, () => props.name, () => props.variations, () => props.count], () => {
|
|
354
|
+
personalizedResult.value = personalize();
|
|
355
|
+
});
|
|
356
|
+
return () => h(PersonalizeProvider_default, { personalized: true }, () => {
|
|
357
|
+
var _a;
|
|
358
|
+
return (_a = personalizedResult.value) == null ? void 0 : _a.variations.map((variation) => {
|
|
359
|
+
return h(props.component, {
|
|
360
|
+
key: variation.id,
|
|
361
|
+
personalizationResult: {
|
|
362
|
+
variation,
|
|
363
|
+
personalizationOccurred: true
|
|
364
|
+
},
|
|
365
|
+
...variation
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
var PersonalizeStandard_default = PersonalizeStandard;
|
|
372
|
+
|
|
373
|
+
// src/components/personalize/PersonalizeEdge.ts
|
|
374
|
+
import { EdgeNodeTagName as EdgeNodeTagName2, ScriptType as ScriptType2 } from "@uniformdev/context";
|
|
375
|
+
import { defineComponent as defineComponent7 } from "vue-demi";
|
|
376
|
+
var PersonalizeStandard2 = defineComponent7({
|
|
377
|
+
name: "PersonalizeStandard",
|
|
378
|
+
inheritAttrs: false,
|
|
379
|
+
props: {
|
|
380
|
+
name: {
|
|
381
|
+
type: String,
|
|
382
|
+
required: true
|
|
383
|
+
},
|
|
384
|
+
variations: {
|
|
385
|
+
type: Array,
|
|
386
|
+
required: true
|
|
387
|
+
},
|
|
388
|
+
component: {
|
|
389
|
+
type: [Function, Object],
|
|
390
|
+
required: true
|
|
391
|
+
},
|
|
392
|
+
count: {
|
|
393
|
+
type: Number,
|
|
394
|
+
default: 1
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
setup(props) {
|
|
398
|
+
var _a;
|
|
399
|
+
const options = {
|
|
400
|
+
count: (_a = props.count) != null ? _a : 1
|
|
401
|
+
};
|
|
402
|
+
return () => [
|
|
403
|
+
h(EdgeNodeTagName2, { "data-type": ScriptType2.ListStart, innerHTML: JSON.stringify(options) }),
|
|
404
|
+
props.variations.map((variant) => {
|
|
405
|
+
return [
|
|
406
|
+
h(EdgeNodeTagName2, {
|
|
407
|
+
"data-type": ScriptType2.ListItemSettings,
|
|
408
|
+
innerHTML: JSON.stringify({ id: variant.id, pz: variant.pz || null }),
|
|
409
|
+
key: `LIS-${variant.id}`
|
|
410
|
+
}),
|
|
411
|
+
h(EdgeNodeTagName2, { "data-type": ScriptType2.ListItem, key: `LI-${variant.id}` }, h(props.component, {
|
|
412
|
+
personalizationResult: { variation: variant, personalizationOccurred: false },
|
|
413
|
+
...variant
|
|
414
|
+
}))
|
|
415
|
+
];
|
|
416
|
+
}),
|
|
417
|
+
h(EdgeNodeTagName2, { "data-type": ScriptType2.ListEnd })
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
var PersonalizeEdge_default = PersonalizeStandard2;
|
|
422
|
+
|
|
423
|
+
// src/components/personalize/Personalize.ts
|
|
424
|
+
var Personalize = defineComponent8({
|
|
425
|
+
name: "Personalize",
|
|
426
|
+
inheritAttrs: false,
|
|
427
|
+
props: {
|
|
428
|
+
name: {
|
|
429
|
+
type: String,
|
|
430
|
+
required: true
|
|
431
|
+
},
|
|
432
|
+
variations: {
|
|
433
|
+
type: Array,
|
|
434
|
+
required: true
|
|
435
|
+
},
|
|
436
|
+
component: {
|
|
437
|
+
type: [Function, Object],
|
|
438
|
+
required: true
|
|
439
|
+
},
|
|
440
|
+
count: {
|
|
441
|
+
type: Number,
|
|
442
|
+
default: 1
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
setup(props) {
|
|
446
|
+
const { outputType } = useUniformContext();
|
|
447
|
+
return () => h(!isServer || outputType === "standard" ? PersonalizeStandard_default : PersonalizeEdge_default, { ...props });
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
var Personalize_default = Personalize;
|
|
451
|
+
|
|
452
|
+
// src/components/track/Track.ts
|
|
453
|
+
import { defineComponent as defineComponent9, watchEffect as watchEffect2, ref as ref3, toRaw as toRaw3 } from "vue-demi";
|
|
454
|
+
var Track = defineComponent9({
|
|
455
|
+
name: "Track",
|
|
456
|
+
inheritAttrs: false,
|
|
457
|
+
props: {
|
|
458
|
+
behavior: {
|
|
459
|
+
type: [Object, Array]
|
|
460
|
+
},
|
|
461
|
+
tagName: {
|
|
462
|
+
type: String,
|
|
463
|
+
default: "div"
|
|
464
|
+
},
|
|
465
|
+
disableVisibilityTrigger: {
|
|
466
|
+
type: Boolean,
|
|
467
|
+
default: typeof window === "undefined" || !("IntersectionObserver" in window)
|
|
468
|
+
},
|
|
469
|
+
threshold: {
|
|
470
|
+
type: [Number, Array],
|
|
471
|
+
default: 0.5
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
setup(props, context) {
|
|
475
|
+
const currentUrl = typeof document === "undefined" ? "__uniform_ssr_url" : document.location.href;
|
|
476
|
+
const { context: uniformContext } = useUniformContext();
|
|
477
|
+
const insidePersonalizeComponent = useIsPersonalized();
|
|
478
|
+
const lastUrl = ref3("");
|
|
479
|
+
const hasTracked = ref3(false);
|
|
480
|
+
const wrapperEl = ref3();
|
|
481
|
+
const disconnect = ref3();
|
|
482
|
+
watchEffect2(() => {
|
|
483
|
+
const urlHasChanged = lastUrl.value !== currentUrl;
|
|
484
|
+
if (urlHasChanged) {
|
|
485
|
+
lastUrl.value = currentUrl;
|
|
486
|
+
hasTracked.value = false;
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
watchEffect2(() => {
|
|
490
|
+
var _a;
|
|
491
|
+
const hasNoBehaviorValue = !props.behavior || Array.isArray(props.behavior) && !props.behavior.length;
|
|
492
|
+
const cannotTrack = insidePersonalizeComponent || hasNoBehaviorValue;
|
|
493
|
+
if (cannotTrack || !wrapperEl.value) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const enrichments = Array.isArray(props.behavior) ? props.behavior : [props.behavior];
|
|
497
|
+
const pushBehaviorEnrichment = () => {
|
|
498
|
+
var _a2;
|
|
499
|
+
if (hasTracked.value) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
uniformContext == null ? void 0 : uniformContext.update({
|
|
503
|
+
enrichments: toRaw3(enrichments)
|
|
504
|
+
});
|
|
505
|
+
hasTracked.value = false;
|
|
506
|
+
(_a2 = disconnect.value) == null ? void 0 : _a2.call(disconnect);
|
|
507
|
+
};
|
|
508
|
+
if (props.disableVisibilityTrigger) {
|
|
509
|
+
pushBehaviorEnrichment();
|
|
510
|
+
} else {
|
|
511
|
+
(_a = disconnect.value) == null ? void 0 : _a.call(disconnect);
|
|
512
|
+
const instance = new IntersectionObserver(([entry]) => {
|
|
513
|
+
if (entry.isIntersecting) {
|
|
514
|
+
pushBehaviorEnrichment();
|
|
515
|
+
}
|
|
516
|
+
}, {
|
|
517
|
+
threshold: props.threshold
|
|
518
|
+
});
|
|
519
|
+
instance.observe(wrapperEl.value);
|
|
520
|
+
disconnect.value = () => {
|
|
521
|
+
var _a2;
|
|
522
|
+
return (_a2 = instance.disconnect) == null ? void 0 : _a2.call(instance);
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
return () => {
|
|
526
|
+
var _a2;
|
|
527
|
+
(_a2 = disconnect.value) == null ? void 0 : _a2.call(disconnect);
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
return () => h(props.tagName, { ref: wrapperEl, ...context.attrs }, context.slots.default());
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
var Track_default = Track;
|
|
534
|
+
|
|
535
|
+
// src/components/track/TrackSlot.ts
|
|
536
|
+
import { defineComponent as defineComponent10, ref as ref4, watchEffect as watchEffect3, toRaw as toRaw4 } from "vue-demi";
|
|
537
|
+
var TrackSlot = defineComponent10({
|
|
538
|
+
name: "TrackSlot",
|
|
539
|
+
inheritAttrs: false,
|
|
540
|
+
props: {
|
|
541
|
+
behavior: {
|
|
542
|
+
type: [Object, Array]
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
setup(props, context) {
|
|
546
|
+
const currentUrl = typeof document === "undefined" ? "__uniform_ssr_url" : document.location.href;
|
|
547
|
+
const { context: uniformContext } = useUniformContext();
|
|
548
|
+
const insidePersonalizeComponent = useIsPersonalized();
|
|
549
|
+
const lastUrl = ref4();
|
|
550
|
+
const hasTracked = ref4(false);
|
|
551
|
+
watchEffect3(() => {
|
|
552
|
+
const urlHasChanged = lastUrl.value !== currentUrl;
|
|
553
|
+
if (urlHasChanged) {
|
|
554
|
+
lastUrl.value = currentUrl;
|
|
555
|
+
hasTracked.value = false;
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
watchEffect3(() => {
|
|
559
|
+
const hasNoBehaviorValue = !props.behavior || Array.isArray(props.behavior) && !props.behavior.length;
|
|
560
|
+
const cannotTrack = insidePersonalizeComponent || hasNoBehaviorValue;
|
|
561
|
+
if (cannotTrack)
|
|
562
|
+
return;
|
|
563
|
+
const pushBehaviorEnrichment = () => {
|
|
564
|
+
if (hasTracked.value) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const enrichments = Array.isArray(props.behavior) ? props.behavior : [props.behavior];
|
|
568
|
+
uniformContext == null ? void 0 : uniformContext.update({
|
|
569
|
+
enrichments: toRaw4(enrichments)
|
|
570
|
+
});
|
|
571
|
+
hasTracked.value = true;
|
|
572
|
+
};
|
|
573
|
+
pushBehaviorEnrichment();
|
|
574
|
+
});
|
|
575
|
+
return () => h(context.slots.default, { ...context.attrs });
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
var TrackSlot_default = TrackSlot;
|
|
579
|
+
|
|
580
|
+
// src/providers/useQuirks.ts
|
|
581
|
+
import { ref as ref5, watch as watch2 } from "vue-demi";
|
|
582
|
+
var useQuirks = () => {
|
|
583
|
+
const { context } = useUniformContext();
|
|
584
|
+
const quirks = ref5(context.quirks);
|
|
585
|
+
const quirkChangeListener = (updateQuirks) => {
|
|
586
|
+
quirks.value = updateQuirks;
|
|
587
|
+
};
|
|
588
|
+
watch2(context, () => {
|
|
589
|
+
context.events.on("quirksUpdated", quirkChangeListener);
|
|
590
|
+
return () => {
|
|
591
|
+
context.events.off("quirksUpdated", quirkChangeListener);
|
|
592
|
+
};
|
|
593
|
+
});
|
|
594
|
+
return quirks;
|
|
595
|
+
};
|
|
596
|
+
export {
|
|
597
|
+
Personalize_default as Personalize,
|
|
598
|
+
PersonalizeEdge_default as PersonalizeEdge,
|
|
599
|
+
Test_default as Test,
|
|
600
|
+
Track_default as Track,
|
|
601
|
+
TrackSlot_default as TrackSlot,
|
|
602
|
+
UniformContextProvider_default as UniformContextProvider,
|
|
603
|
+
isUsingUniformContext,
|
|
604
|
+
onRouteChange,
|
|
605
|
+
provideIsPersonalized,
|
|
606
|
+
provideUniformContext,
|
|
607
|
+
uniformContextInjectionKey,
|
|
608
|
+
useIsPersonalized,
|
|
609
|
+
useQuirks,
|
|
610
|
+
useScores,
|
|
611
|
+
useUniformContext
|
|
612
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/context-vue",
|
|
3
|
-
"version": "16.2.1-nuxt.
|
|
3
|
+
"version": "16.2.1-nuxt.325+c1c2247c8",
|
|
4
4
|
"description": "Vue SDK for Uniform Context",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "tsup
|
|
17
|
+
"build": "tsup",
|
|
18
18
|
"dev": "tsup --watch",
|
|
19
19
|
"clean": "rimraf dist",
|
|
20
20
|
"test": "jest --maxWorkers=1 --passWithNoTests",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@uniformdev/context": "^16.2.1-nuxt.
|
|
25
|
+
"@uniformdev/context": "^16.2.1-nuxt.325+c1c2247c8",
|
|
26
26
|
"cookie-es": "^0.5.0",
|
|
27
27
|
"dequal": "^2.0.2",
|
|
28
28
|
"uuid": "8.3.2",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@testing-library/vue": "6.
|
|
41
|
+
"@testing-library/vue": "6.6.1",
|
|
42
42
|
"@types/uuid": "8.3.4",
|
|
43
43
|
"@vue/server-test-utils": "1.3.0",
|
|
44
44
|
"@vue/test-utils": "2.0.2",
|
|
45
45
|
"vue": "3.2.37",
|
|
46
|
-
"vue-server-renderer": "2.
|
|
47
|
-
"vue-template-compiler": "2.
|
|
46
|
+
"vue-server-renderer": "2.7.7",
|
|
47
|
+
"vue-template-compiler": "2.7.7"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"dist",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"last 2 versions",
|
|
64
64
|
"not dead"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "c1c2247c820522de8ca9707a76e5697b0e3df334"
|
|
67
67
|
}
|