@uniformdev/canvas-next-rsc-client 19.76.0 → 19.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,237 @@
1
1
  "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ // ../../node_modules/.pnpm/rfdc@1.3.0/node_modules/rfdc/index.js
29
+ var require_rfdc = __commonJS({
30
+ "../../node_modules/.pnpm/rfdc@1.3.0/node_modules/rfdc/index.js"(exports, module) {
31
+ "use strict";
32
+ module.exports = rfdc4;
33
+ function copyBuffer(cur) {
34
+ if (cur instanceof Buffer) {
35
+ return Buffer.from(cur);
36
+ }
37
+ return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
38
+ }
39
+ function rfdc4(opts) {
40
+ opts = opts || {};
41
+ if (opts.circles)
42
+ return rfdcCircles(opts);
43
+ return opts.proto ? cloneProto : clone2;
44
+ function cloneArray(a, fn) {
45
+ var keys = Object.keys(a);
46
+ var a2 = new Array(keys.length);
47
+ for (var i = 0; i < keys.length; i++) {
48
+ var k = keys[i];
49
+ var cur = a[k];
50
+ if (typeof cur !== "object" || cur === null) {
51
+ a2[k] = cur;
52
+ } else if (cur instanceof Date) {
53
+ a2[k] = new Date(cur);
54
+ } else if (ArrayBuffer.isView(cur)) {
55
+ a2[k] = copyBuffer(cur);
56
+ } else {
57
+ a2[k] = fn(cur);
58
+ }
59
+ }
60
+ return a2;
61
+ }
62
+ function clone2(o) {
63
+ if (typeof o !== "object" || o === null)
64
+ return o;
65
+ if (o instanceof Date)
66
+ return new Date(o);
67
+ if (Array.isArray(o))
68
+ return cloneArray(o, clone2);
69
+ if (o instanceof Map)
70
+ return new Map(cloneArray(Array.from(o), clone2));
71
+ if (o instanceof Set)
72
+ return new Set(cloneArray(Array.from(o), clone2));
73
+ var o2 = {};
74
+ for (var k in o) {
75
+ if (Object.hasOwnProperty.call(o, k) === false)
76
+ continue;
77
+ var cur = o[k];
78
+ if (typeof cur !== "object" || cur === null) {
79
+ o2[k] = cur;
80
+ } else if (cur instanceof Date) {
81
+ o2[k] = new Date(cur);
82
+ } else if (cur instanceof Map) {
83
+ o2[k] = new Map(cloneArray(Array.from(cur), clone2));
84
+ } else if (cur instanceof Set) {
85
+ o2[k] = new Set(cloneArray(Array.from(cur), clone2));
86
+ } else if (ArrayBuffer.isView(cur)) {
87
+ o2[k] = copyBuffer(cur);
88
+ } else {
89
+ o2[k] = clone2(cur);
90
+ }
91
+ }
92
+ return o2;
93
+ }
94
+ function cloneProto(o) {
95
+ if (typeof o !== "object" || o === null)
96
+ return o;
97
+ if (o instanceof Date)
98
+ return new Date(o);
99
+ if (Array.isArray(o))
100
+ return cloneArray(o, cloneProto);
101
+ if (o instanceof Map)
102
+ return new Map(cloneArray(Array.from(o), cloneProto));
103
+ if (o instanceof Set)
104
+ return new Set(cloneArray(Array.from(o), cloneProto));
105
+ var o2 = {};
106
+ for (var k in o) {
107
+ var cur = o[k];
108
+ if (typeof cur !== "object" || cur === null) {
109
+ o2[k] = cur;
110
+ } else if (cur instanceof Date) {
111
+ o2[k] = new Date(cur);
112
+ } else if (cur instanceof Map) {
113
+ o2[k] = new Map(cloneArray(Array.from(cur), cloneProto));
114
+ } else if (cur instanceof Set) {
115
+ o2[k] = new Set(cloneArray(Array.from(cur), cloneProto));
116
+ } else if (ArrayBuffer.isView(cur)) {
117
+ o2[k] = copyBuffer(cur);
118
+ } else {
119
+ o2[k] = cloneProto(cur);
120
+ }
121
+ }
122
+ return o2;
123
+ }
124
+ }
125
+ function rfdcCircles(opts) {
126
+ var refs = [];
127
+ var refsNew = [];
128
+ return opts.proto ? cloneProto : clone2;
129
+ function cloneArray(a, fn) {
130
+ var keys = Object.keys(a);
131
+ var a2 = new Array(keys.length);
132
+ for (var i = 0; i < keys.length; i++) {
133
+ var k = keys[i];
134
+ var cur = a[k];
135
+ if (typeof cur !== "object" || cur === null) {
136
+ a2[k] = cur;
137
+ } else if (cur instanceof Date) {
138
+ a2[k] = new Date(cur);
139
+ } else if (ArrayBuffer.isView(cur)) {
140
+ a2[k] = copyBuffer(cur);
141
+ } else {
142
+ var index = refs.indexOf(cur);
143
+ if (index !== -1) {
144
+ a2[k] = refsNew[index];
145
+ } else {
146
+ a2[k] = fn(cur);
147
+ }
148
+ }
149
+ }
150
+ return a2;
151
+ }
152
+ function clone2(o) {
153
+ if (typeof o !== "object" || o === null)
154
+ return o;
155
+ if (o instanceof Date)
156
+ return new Date(o);
157
+ if (Array.isArray(o))
158
+ return cloneArray(o, clone2);
159
+ if (o instanceof Map)
160
+ return new Map(cloneArray(Array.from(o), clone2));
161
+ if (o instanceof Set)
162
+ return new Set(cloneArray(Array.from(o), clone2));
163
+ var o2 = {};
164
+ refs.push(o);
165
+ refsNew.push(o2);
166
+ for (var k in o) {
167
+ if (Object.hasOwnProperty.call(o, k) === false)
168
+ continue;
169
+ var cur = o[k];
170
+ if (typeof cur !== "object" || cur === null) {
171
+ o2[k] = cur;
172
+ } else if (cur instanceof Date) {
173
+ o2[k] = new Date(cur);
174
+ } else if (cur instanceof Map) {
175
+ o2[k] = new Map(cloneArray(Array.from(cur), clone2));
176
+ } else if (cur instanceof Set) {
177
+ o2[k] = new Set(cloneArray(Array.from(cur), clone2));
178
+ } else if (ArrayBuffer.isView(cur)) {
179
+ o2[k] = copyBuffer(cur);
180
+ } else {
181
+ var i = refs.indexOf(cur);
182
+ if (i !== -1) {
183
+ o2[k] = refsNew[i];
184
+ } else {
185
+ o2[k] = clone2(cur);
186
+ }
187
+ }
188
+ }
189
+ refs.pop();
190
+ refsNew.pop();
191
+ return o2;
192
+ }
193
+ function cloneProto(o) {
194
+ if (typeof o !== "object" || o === null)
195
+ return o;
196
+ if (o instanceof Date)
197
+ return new Date(o);
198
+ if (Array.isArray(o))
199
+ return cloneArray(o, cloneProto);
200
+ if (o instanceof Map)
201
+ return new Map(cloneArray(Array.from(o), cloneProto));
202
+ if (o instanceof Set)
203
+ return new Set(cloneArray(Array.from(o), cloneProto));
204
+ var o2 = {};
205
+ refs.push(o);
206
+ refsNew.push(o2);
207
+ for (var k in o) {
208
+ var cur = o[k];
209
+ if (typeof cur !== "object" || cur === null) {
210
+ o2[k] = cur;
211
+ } else if (cur instanceof Date) {
212
+ o2[k] = new Date(cur);
213
+ } else if (cur instanceof Map) {
214
+ o2[k] = new Map(cloneArray(Array.from(cur), cloneProto));
215
+ } else if (cur instanceof Set) {
216
+ o2[k] = new Set(cloneArray(Array.from(cur), cloneProto));
217
+ } else if (ArrayBuffer.isView(cur)) {
218
+ o2[k] = copyBuffer(cur);
219
+ } else {
220
+ var i = refs.indexOf(cur);
221
+ if (i !== -1) {
222
+ o2[k] = refsNew[i];
223
+ } else {
224
+ o2[k] = cloneProto(cur);
225
+ }
226
+ }
227
+ }
228
+ refs.pop();
229
+ refsNew.pop();
230
+ return o2;
231
+ }
232
+ }
233
+ }
234
+ });
2
235
 
3
236
  // src/components/ClientContextualEditingComponentWrapper.tsx
4
237
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
@@ -88,6 +321,549 @@ var ContextUpdateTransferClient = ({
88
321
  return null;
89
322
  };
90
323
 
324
+ // ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
325
+ var has = Object.prototype.hasOwnProperty;
326
+ function dequal(foo, bar) {
327
+ var ctor, len;
328
+ if (foo === bar)
329
+ return true;
330
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
331
+ if (ctor === Date)
332
+ return foo.getTime() === bar.getTime();
333
+ if (ctor === RegExp)
334
+ return foo.toString() === bar.toString();
335
+ if (ctor === Array) {
336
+ if ((len = foo.length) === bar.length) {
337
+ while (len-- && dequal(foo[len], bar[len]))
338
+ ;
339
+ }
340
+ return len === -1;
341
+ }
342
+ if (!ctor || typeof foo === "object") {
343
+ len = 0;
344
+ for (ctor in foo) {
345
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
346
+ return false;
347
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
348
+ return false;
349
+ }
350
+ return Object.keys(bar).length === len;
351
+ }
352
+ }
353
+ return foo !== foo && bar !== bar;
354
+ }
355
+
356
+ // ../../node_modules/.pnpm/js-cookie@3.0.5/node_modules/js-cookie/dist/js.cookie.mjs
357
+ function assign(target) {
358
+ for (var i = 1; i < arguments.length; i++) {
359
+ var source = arguments[i];
360
+ for (var key in source) {
361
+ target[key] = source[key];
362
+ }
363
+ }
364
+ return target;
365
+ }
366
+ var defaultConverter = {
367
+ read: function(value) {
368
+ if (value[0] === '"') {
369
+ value = value.slice(1, -1);
370
+ }
371
+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
372
+ },
373
+ write: function(value) {
374
+ return encodeURIComponent(value).replace(
375
+ /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
376
+ decodeURIComponent
377
+ );
378
+ }
379
+ };
380
+ function init(converter, defaultAttributes) {
381
+ function set(name, value, attributes) {
382
+ if (typeof document === "undefined") {
383
+ return;
384
+ }
385
+ attributes = assign({}, defaultAttributes, attributes);
386
+ if (typeof attributes.expires === "number") {
387
+ attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
388
+ }
389
+ if (attributes.expires) {
390
+ attributes.expires = attributes.expires.toUTCString();
391
+ }
392
+ name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
393
+ var stringifiedAttributes = "";
394
+ for (var attributeName in attributes) {
395
+ if (!attributes[attributeName]) {
396
+ continue;
397
+ }
398
+ stringifiedAttributes += "; " + attributeName;
399
+ if (attributes[attributeName] === true) {
400
+ continue;
401
+ }
402
+ stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
403
+ }
404
+ return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
405
+ }
406
+ function get(name) {
407
+ if (typeof document === "undefined" || arguments.length && !name) {
408
+ return;
409
+ }
410
+ var cookies = document.cookie ? document.cookie.split("; ") : [];
411
+ var jar = {};
412
+ for (var i = 0; i < cookies.length; i++) {
413
+ var parts = cookies[i].split("=");
414
+ var value = parts.slice(1).join("=");
415
+ try {
416
+ var found = decodeURIComponent(parts[0]);
417
+ jar[found] = converter.read(value, found);
418
+ if (name === found) {
419
+ break;
420
+ }
421
+ } catch (e) {
422
+ }
423
+ }
424
+ return name ? jar[name] : jar;
425
+ }
426
+ return Object.create(
427
+ {
428
+ set,
429
+ get,
430
+ remove: function(name, attributes) {
431
+ set(
432
+ name,
433
+ "",
434
+ assign({}, attributes, {
435
+ expires: -1
436
+ })
437
+ );
438
+ },
439
+ withAttributes: function(attributes) {
440
+ return init(this.converter, assign({}, this.attributes, attributes));
441
+ },
442
+ withConverter: function(converter2) {
443
+ return init(assign({}, this.converter, converter2), this.attributes);
444
+ }
445
+ },
446
+ {
447
+ attributes: { value: Object.freeze(defaultAttributes) },
448
+ converter: { value: Object.freeze(converter) }
449
+ }
450
+ );
451
+ }
452
+ var api = init(defaultConverter, { path: "/" });
453
+
454
+ // ../context/dist/index.mjs
455
+ var import_rfdc = __toESM(require_rfdc(), 1);
456
+ var import_rfdc2 = __toESM(require_rfdc(), 1);
457
+ var import_rfdc3 = __toESM(require_rfdc(), 1);
458
+ var __accessCheck = (obj, member, msg) => {
459
+ if (!member.has(obj))
460
+ throw TypeError("Cannot " + msg);
461
+ };
462
+ var __privateGet = (obj, member, getter) => {
463
+ __accessCheck(obj, member, "read from private field");
464
+ return getter ? getter.call(obj) : member.get(obj);
465
+ };
466
+ var __privateSet = (obj, member, value, setter) => {
467
+ __accessCheck(obj, member, "write to private field");
468
+ setter ? setter.call(obj, value) : member.set(obj, value);
469
+ return value;
470
+ };
471
+ var __privateMethod = (obj, member, method) => {
472
+ __accessCheck(obj, member, "access private method");
473
+ return method;
474
+ };
475
+ var ENR_SEPARATOR = "_";
476
+ var _evaluator;
477
+ var _onLogMessage;
478
+ _evaluator = /* @__PURE__ */ new WeakMap();
479
+ _onLogMessage = /* @__PURE__ */ new WeakMap();
480
+ var _mf;
481
+ var _signalInstances;
482
+ var _onLogMessage2;
483
+ _mf = /* @__PURE__ */ new WeakMap();
484
+ _signalInstances = /* @__PURE__ */ new WeakMap();
485
+ _onLogMessage2 = /* @__PURE__ */ new WeakMap();
486
+ function getEnrichmentVectorKey(category, value) {
487
+ return `${category}${ENR_SEPARATOR}${value}`;
488
+ }
489
+ function isNumberMatch(lhs, match) {
490
+ var _a;
491
+ if (typeof lhs === "undefined" || lhs === null) {
492
+ return false;
493
+ }
494
+ const lhsValue = Number(lhs);
495
+ if (isNaN(lhsValue)) {
496
+ return false;
497
+ }
498
+ switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
499
+ case "=":
500
+ return lhsValue === match.rhs;
501
+ case "!=":
502
+ return lhsValue !== match.rhs;
503
+ case ">":
504
+ return lhsValue > match.rhs;
505
+ case "<":
506
+ return lhsValue < match.rhs;
507
+ default:
508
+ console.warn(`Unknown match type ${match.op} is false.`);
509
+ return false;
510
+ }
511
+ }
512
+ function explainNumberMatch(lhs, match) {
513
+ return `${lhs} ${explainNumberMatchCriteria(match)}`;
514
+ }
515
+ function explainNumberMatchCriteria(match) {
516
+ return `${match.op} ${match.rhs}`;
517
+ }
518
+ var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
519
+ var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
520
+ var _a, _b;
521
+ if (criteria.type !== "PVC") {
522
+ return { result: false, changed: false };
523
+ }
524
+ const hasUrlChanged = Boolean(
525
+ update.state.url && (!update.previousState || ((_a = update.state.url) == null ? void 0 : _a.toString()) !== ((_b = update.previousState.url) == null ? void 0 : _b.toString()))
526
+ );
527
+ const existingValueNumber = update.visitor.sessionScores[pageViewCountDimension] || 0;
528
+ const updatedCount = existingValueNumber + 1;
529
+ const finalResult = { result: false, changed: hasUrlChanged };
530
+ const hasExistingPageViewIncrementCommand = commands.some(
531
+ (c) => c.type === "modscoreS" && c.data.dimension === pageViewCountDimension
532
+ );
533
+ if (hasUrlChanged && !hasExistingPageViewIncrementCommand) {
534
+ commands.push({
535
+ type: "modscoreS",
536
+ data: {
537
+ dimension: pageViewCountDimension,
538
+ delta: 1
539
+ }
540
+ });
541
+ }
542
+ if (isNumberMatch(updatedCount, criteria.match)) {
543
+ finalResult.result = true;
544
+ }
545
+ onLogMessage == null ? void 0 : onLogMessage([
546
+ "debug",
547
+ 203,
548
+ { criteria, result: finalResult, explanation: explainNumberMatch(updatedCount, criteria.match) }
549
+ ]);
550
+ return finalResult;
551
+ };
552
+ pageViewCountEvaluator.alwaysExecute = true;
553
+ var _evaluators;
554
+ _evaluators = /* @__PURE__ */ new WeakMap();
555
+ var _data;
556
+ var _initialData;
557
+ var _mitt;
558
+ _data = /* @__PURE__ */ new WeakMap();
559
+ _initialData = /* @__PURE__ */ new WeakMap();
560
+ _mitt = /* @__PURE__ */ new WeakMap();
561
+ var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
562
+ var b2s = alphabet.split("");
563
+ var s2b = new Array(123);
564
+ for (let i = 0; i < alphabet.length; i++) {
565
+ s2b[alphabet.charCodeAt(i)] = i;
566
+ }
567
+ var _cookieName;
568
+ var _cookieAttributes;
569
+ _cookieName = /* @__PURE__ */ new WeakMap();
570
+ _cookieAttributes = /* @__PURE__ */ new WeakMap();
571
+ var _fetchData;
572
+ var fetchData_fn;
573
+ _fetchData = /* @__PURE__ */ new WeakSet();
574
+ fetchData_fn = async function() {
575
+ const serviceData = await new Promise((resolve) => {
576
+ setTimeout(() => {
577
+ resolve(void 0);
578
+ }, 2e3);
579
+ });
580
+ if (serviceData) {
581
+ this.signalAsyncDataUpdate(serviceData);
582
+ }
583
+ };
584
+ var emptyVisitorData = () => ({
585
+ quirks: {},
586
+ scores: {},
587
+ sessionScores: {},
588
+ tests: {},
589
+ consent: false,
590
+ controlGroup: false
591
+ });
592
+ var clone = (0, import_rfdc.default)();
593
+ var STORAGE_KEY = "ufvisitor";
594
+ var _mitt2;
595
+ var _persist;
596
+ var _visitTimeout;
597
+ var _options;
598
+ var _currentData;
599
+ var currentData_get;
600
+ var _replaceData;
601
+ var replaceData_fn;
602
+ var _setVisitTimeout;
603
+ var setVisitTimeout_fn;
604
+ var _isExpired;
605
+ var isExpired_fn;
606
+ var _handleCaps;
607
+ var handleCaps_fn;
608
+ var _defaultData;
609
+ var defaultData_fn;
610
+ _mitt2 = /* @__PURE__ */ new WeakMap();
611
+ _persist = /* @__PURE__ */ new WeakMap();
612
+ _visitTimeout = /* @__PURE__ */ new WeakMap();
613
+ _options = /* @__PURE__ */ new WeakMap();
614
+ _currentData = /* @__PURE__ */ new WeakSet();
615
+ currentData_get = function() {
616
+ return __privateGet(this, _persist).get(STORAGE_KEY);
617
+ };
618
+ _replaceData = /* @__PURE__ */ new WeakSet();
619
+ replaceData_fn = function(data, quiet = false) {
620
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
621
+ const oldData = __privateGet(this, _currentData, currentData_get);
622
+ const now = Date.now();
623
+ if (data.controlGroup) {
624
+ data.scores = {};
625
+ data.sessionScores = {};
626
+ } else {
627
+ __privateMethod(this, _handleCaps, handleCaps_fn).call(this, data.scores);
628
+ __privateMethod(this, _handleCaps, handleCaps_fn).call(this, data.sessionScores);
629
+ (_b = (_a = __privateGet(this, _options)).decay) == null ? void 0 : _b.call(_a, {
630
+ now,
631
+ lastUpd: oldData == null ? void 0 : oldData.updated,
632
+ scores: data.scores,
633
+ sessionScores: data.sessionScores,
634
+ onLogMessage: __privateGet(this, _options).onLogMessage
635
+ });
636
+ }
637
+ const haveScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
638
+ const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
639
+ const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
640
+ const haveTestsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
641
+ const updatedData = {
642
+ updated: now,
643
+ visitorData: data
644
+ };
645
+ __privateMethod(this, _setVisitTimeout, setVisitTimeout_fn).call(this);
646
+ __privateGet(this, _persist).set(STORAGE_KEY, updatedData, !!data.consent);
647
+ (_d = (_c = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _d.call(_c, ["debug", 102, data]);
648
+ if (!quiet) {
649
+ if (haveScoresChanged || haveSessionScoresChanged) {
650
+ __privateGet(this, _mitt2).emit("scoresUpdated", data);
651
+ }
652
+ if (haveQuirksChanged) {
653
+ __privateGet(this, _mitt2).emit("quirksUpdated", data);
654
+ }
655
+ if (haveTestsChanged) {
656
+ __privateGet(this, _mitt2).emit("testsUpdated", data);
657
+ }
658
+ if (((_e = oldData == null ? void 0 : oldData.visitorData) == null ? void 0 : _e.consent) !== data.consent) {
659
+ __privateGet(this, _mitt2).emit("consentUpdated", data);
660
+ }
661
+ if (((_f = oldData == null ? void 0 : oldData.visitorData) == null ? void 0 : _f.controlGroup) !== data.controlGroup) {
662
+ __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
663
+ (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
664
+ }
665
+ }
666
+ };
667
+ _setVisitTimeout = /* @__PURE__ */ new WeakSet();
668
+ setVisitTimeout_fn = function() {
669
+ if (typeof document === "undefined" || !__privateGet(this, _options).visitLifespan) {
670
+ return;
671
+ }
672
+ if (__privateGet(this, _visitTimeout)) {
673
+ window.clearTimeout(__privateGet(this, _visitTimeout));
674
+ }
675
+ __privateSet(this, _visitTimeout, window.setTimeout(() => {
676
+ this.data;
677
+ }, __privateGet(this, _options).visitLifespan + 50));
678
+ };
679
+ _isExpired = /* @__PURE__ */ new WeakSet();
680
+ isExpired_fn = function(data) {
681
+ const expires = __privateGet(this, _options).visitLifespan;
682
+ return expires ? data.updated + expires < Date.now() : false;
683
+ };
684
+ _handleCaps = /* @__PURE__ */ new WeakSet();
685
+ handleCaps_fn = function(scores) {
686
+ var _a, _b;
687
+ if (!__privateGet(this, _options).manifest) {
688
+ return;
689
+ }
690
+ for (const dim in scores) {
691
+ const score = scores[dim];
692
+ const dimDef = __privateGet(this, _options).manifest.getDimensionByKey(dim);
693
+ if (!dimDef) {
694
+ continue;
695
+ }
696
+ if (score > dimDef.cap) {
697
+ (_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 110, { dim, score, cap: dimDef.cap }]);
698
+ scores[dim] = dimDef.cap;
699
+ }
700
+ }
701
+ };
702
+ _defaultData = /* @__PURE__ */ new WeakSet();
703
+ defaultData_fn = function() {
704
+ var _a, _b, _c;
705
+ return {
706
+ ...emptyVisitorData(),
707
+ consent: (_a = __privateGet(this, _options).defaultConsent) != null ? _a : false,
708
+ controlGroup: (_c = (_b = __privateGet(this, _options).manifest) == null ? void 0 : _b.rollForControlGroup()) != null ? _c : false
709
+ };
710
+ };
711
+ var _serverTransitionState;
712
+ var _scores;
713
+ var _state;
714
+ var _pzCache;
715
+ var _mitt3;
716
+ var _emitTest;
717
+ var emitTest_fn;
718
+ var _updateComputedScores;
719
+ var updateComputedScores_fn;
720
+ var _calculateScores;
721
+ var calculateScores_fn;
722
+ _serverTransitionState = /* @__PURE__ */ new WeakMap();
723
+ _scores = /* @__PURE__ */ new WeakMap();
724
+ _state = /* @__PURE__ */ new WeakMap();
725
+ _pzCache = /* @__PURE__ */ new WeakMap();
726
+ _mitt3 = /* @__PURE__ */ new WeakMap();
727
+ _emitTest = /* @__PURE__ */ new WeakSet();
728
+ emitTest_fn = function(event) {
729
+ __privateGet(this, _mitt3).emit("testResult", event);
730
+ };
731
+ _updateComputedScores = /* @__PURE__ */ new WeakSet();
732
+ updateComputedScores_fn = function(newData) {
733
+ const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
734
+ const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
735
+ if (newScoresHaveChanged) {
736
+ __privateSet(this, _scores, newScores);
737
+ __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
738
+ __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
739
+ }
740
+ };
741
+ _calculateScores = /* @__PURE__ */ new WeakSet();
742
+ calculateScores_fn = function(newData) {
743
+ var _a;
744
+ let newScores = { ...newData.scores };
745
+ for (const session in newData.sessionScores) {
746
+ newScores[session] = ((_a = newScores[session]) != null ? _a : 0) + newData.sessionScores[session];
747
+ }
748
+ newScores = this.manifest.computeAggregateDimensions(newScores);
749
+ return newScores;
750
+ };
751
+ var isBrowser = typeof top !== "undefined";
752
+ function enableContextDevTools(options) {
753
+ return {
754
+ logDrain: (message) => {
755
+ if (!isBrowser) {
756
+ return;
757
+ }
758
+ top == null ? void 0 : top.postMessage(
759
+ {
760
+ type: "uniform:context:log",
761
+ message
762
+ },
763
+ window.location.origin
764
+ );
765
+ },
766
+ init: (context) => {
767
+ const personalizations = [];
768
+ const tests = [];
769
+ const onContextDataUpdated = () => {
770
+ if (!isBrowser) {
771
+ return;
772
+ }
773
+ top == null ? void 0 : top.postMessage(
774
+ {
775
+ type: "uniform:context:data",
776
+ data: {
777
+ scores: context.scores,
778
+ data: context.storage.data,
779
+ manifest: context.manifest.data,
780
+ personalizations,
781
+ tests
782
+ }
783
+ },
784
+ window.location.origin
785
+ );
786
+ };
787
+ const onPersonalizationResult = (e) => {
788
+ if (!e.changed)
789
+ return;
790
+ personalizations.push(e);
791
+ };
792
+ const onTestResult = (e) => {
793
+ if (!e.variantAssigned)
794
+ return;
795
+ tests.push(e);
796
+ };
797
+ if (isBrowser) {
798
+ window.__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__ = context;
799
+ try {
800
+ top == null ? void 0 : top.addEventListener("message", async (event) => {
801
+ if (!event.data) {
802
+ return;
803
+ }
804
+ const message = event.data;
805
+ await handleMessageFromDevTools({
806
+ message,
807
+ context,
808
+ afterMessageReceived: options == null ? void 0 : options.onAfterMessageReceived
809
+ });
810
+ });
811
+ } catch (e) {
812
+ console.warn(
813
+ "Unable to initialize Uniform Context DevTools because it is in a cross-domain iframe.",
814
+ e
815
+ );
816
+ }
817
+ top == null ? void 0 : top.postMessage(
818
+ {
819
+ type: "uniform:context:hello",
820
+ uiVersion: 2
821
+ },
822
+ window.location.origin
823
+ );
824
+ onContextDataUpdated();
825
+ }
826
+ context.events.on("personalizationResult", onPersonalizationResult);
827
+ context.events.on("testResult", onTestResult);
828
+ context.events.on("scoresUpdated", onContextDataUpdated);
829
+ context.storage.events.on("*", onContextDataUpdated);
830
+ return () => {
831
+ context.events.off("scoresUpdated", onContextDataUpdated);
832
+ context.storage.events.off("*", onContextDataUpdated);
833
+ context.events.off("personalizationResult", onPersonalizationResult);
834
+ context.events.off("testResult", onTestResult);
835
+ };
836
+ }
837
+ };
838
+ }
839
+ async function handleMessageFromDevTools({
840
+ message,
841
+ context,
842
+ afterMessageReceived
843
+ }) {
844
+ let receivedUniformMessage = false;
845
+ if (message.type === "uniform-in:context:update" && message.newData) {
846
+ receivedUniformMessage = true;
847
+ await context.update(message.newData);
848
+ }
849
+ if (message.type === "uniform-in:context:commands" && message.commands && Array.isArray(message.commands)) {
850
+ receivedUniformMessage = true;
851
+ await context.storage.updateData(message.commands);
852
+ }
853
+ if (message.type === "uniform-in:context:forget") {
854
+ receivedUniformMessage = true;
855
+ await context.forget(false);
856
+ }
857
+ if (receivedUniformMessage && typeof afterMessageReceived === "function") {
858
+ afterMessageReceived(message);
859
+ }
860
+ }
861
+ var dc = (0, import_rfdc2.default)();
862
+ var dc2 = (0, import_rfdc3.default)();
863
+
864
+ // src/components/DefaultUniformClientContext.tsx
865
+ import { useRouter } from "next/navigation";
866
+
91
867
  // src/context/createClientUniformContext.ts
92
868
  import { createUniformContext } from "@uniformdev/canvas-next-rsc-shared";
93
869
  var createClientUniformContext = (options) => {
@@ -113,10 +889,22 @@ var useInitUniformContext = (callback) => {
113
889
  };
114
890
 
115
891
  // src/components/DefaultUniformClientContext.tsx
116
- var DefaultUniformClientContext = ({ manifest }) => {
892
+ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
893
+ const router = useRouter();
117
894
  useInitUniformContext(() => {
895
+ const plugins = [];
896
+ if (!disableDevTools) {
897
+ plugins.push(
898
+ enableContextDevTools({
899
+ onAfterMessageReceived: () => {
900
+ router.refresh();
901
+ }
902
+ })
903
+ );
904
+ }
118
905
  return createClientUniformContext({
119
- manifest
906
+ manifest,
907
+ plugins
120
908
  });
121
909
  });
122
910
  return null;
@@ -172,11 +960,11 @@ import {
172
960
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM as IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2,
173
961
  isAllowedReferrer
174
962
  } from "@uniformdev/canvas";
175
- import { useRouter, useSearchParams as useSearchParams3 } from "next/navigation";
963
+ import { useRouter as useRouter2, useSearchParams as useSearchParams3 } from "next/navigation";
176
964
  import { useEffect as useEffect7, useMemo, useRef } from "react";
177
965
  import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
178
966
  var UniformScript = () => {
179
- const router = useRouter();
967
+ const router = useRouter2();
180
968
  const params = useSearchParams3();
181
969
  const needsToRefreshRef = useRef(false);
182
970
  const enabled = params.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2) === "true";
@@ -255,3 +1043,8 @@ export {
255
1043
  useInitUniformContext,
256
1044
  useUniformContext
257
1045
  };
1046
+ /*! Bundled license information:
1047
+
1048
+ js-cookie/dist/js.cookie.mjs:
1049
+ (*! js-cookie v3.0.5 | MIT *)
1050
+ */