@usertour/helpers 0.0.39 → 0.0.41

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.
@@ -1,1125 +0,0 @@
1
- "use strict";
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 __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/editor-helper.ts
31
- var editor_helper_exports = {};
32
- __export(editor_helper_exports, {
33
- EmptyButton: () => EmptyButton,
34
- EmptyColumn: () => EmptyColumn,
35
- EmptyEmbed: () => EmptyEmbed,
36
- EmptyGroup: () => EmptyGroup,
37
- EmptyImage: () => EmptyImage,
38
- EmptyText: () => EmptyText,
39
- createNewColumn: () => createNewColumn,
40
- createNewGroup: () => createNewGroup,
41
- createStepCopy: () => createStepCopy,
42
- createValue1: () => createValue1,
43
- createValue2: () => createValue2,
44
- createValue3: () => createValue3,
45
- createValue4: () => createValue4,
46
- createValue5: () => createValue5,
47
- createValue6: () => createValue6,
48
- defaultInitialValue: () => defaultInitialValue,
49
- extractQuestionData: () => extractQuestionData,
50
- generateUniqueCopyName: () => generateUniqueCopyName,
51
- getDefaultDataForType: () => getDefaultDataForType,
52
- groupData: () => groupData,
53
- hasMissingRequiredData: () => hasMissingRequiredData,
54
- isClickableElement: () => isClickableElement,
55
- isMissingRequiredData: () => isMissingRequiredData,
56
- isQuestionElement: () => isQuestionElement,
57
- isRestrictedType: () => isRestrictedType,
58
- processQuestionElements: () => processQuestionElements,
59
- regenerateTarget: () => regenerateTarget,
60
- regenerateTrigger: () => regenerateTrigger,
61
- surveysValue: () => surveysValue
62
- });
63
- module.exports = __toCommonJS(editor_helper_exports);
64
- var import_types3 = require("@usertour/types");
65
-
66
- // src/helper.ts
67
- var import_clsx = require("clsx");
68
- var import_tailwind_merge = require("tailwind-merge");
69
- var import_uuid = require("uuid");
70
- var import_cuid2 = require("@paralleldrive/cuid2");
71
- function cn(...inputs) {
72
- return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
73
- }
74
- var cuid = () => {
75
- return (0, import_cuid2.createId)();
76
- };
77
- function formatDate(input) {
78
- const date = new Date(input);
79
- return date.toLocaleDateString("en-US", {
80
- month: "long",
81
- day: "numeric",
82
- year: "numeric"
83
- });
84
- }
85
- function absoluteUrl(path) {
86
- return `${path}`;
87
- }
88
- var uuidV4 = () => {
89
- return (0, import_uuid.v4)();
90
- };
91
- function hexToRgb(hex) {
92
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
93
- return result ? {
94
- r: Number.parseInt(result[1], 16),
95
- g: Number.parseInt(result[2], 16),
96
- b: Number.parseInt(result[3], 16)
97
- } : null;
98
- }
99
- var isDark = (hex) => {
100
- const rgb = hexToRgb(hex);
101
- if (!rgb) {
102
- return null;
103
- }
104
- const { r, g, b } = rgb;
105
- if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
106
- return true;
107
- }
108
- return false;
109
- };
110
- var evalCode = (code) => {
111
- try {
112
- return eval(code);
113
- } catch (error) {
114
- console.error("Usertour.js: Error evaluating code:", error);
115
- return null;
116
- }
117
- };
118
- var getRandomColor = () => {
119
- const colors = [
120
- "bg-red-500",
121
- "bg-orange-500",
122
- "bg-yellow-500",
123
- "bg-green-500",
124
- "bg-teal-500",
125
- "bg-blue-500",
126
- "bg-indigo-500",
127
- "bg-purple-500",
128
- "bg-pink-500",
129
- "bg-rose-500"
130
- ];
131
- return colors[Math.floor(Math.random() * colors.length)];
132
- };
133
-
134
- // src/type-utils.ts
135
- var nativeIsArray = Array.isArray;
136
- var ObjProto = Object.prototype;
137
- var objToString = ObjProto.toString;
138
- var objHasOwn = ObjProto.hasOwnProperty;
139
- var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
140
- var isString = (x) => {
141
- return objToString.call(x) === "[object String]";
142
- };
143
- var isEmptyString = (x) => isString(x) && x.trim().length === 0;
144
-
145
- // src/conditions/condition.ts
146
- var import_types2 = require("@usertour/types");
147
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
148
-
149
- // src/conditions/time.ts
150
- var import_date_fns = require("date-fns");
151
-
152
- // src/conditions/attribute.ts
153
- var import_types = require("@usertour/types");
154
- var import_date_fns2 = require("date-fns");
155
-
156
- // src/conditions/condition.ts
157
- var regenerateConditionIds = (conditions) => {
158
- return conditions.map((condition) => ({
159
- ...condition,
160
- id: cuid(),
161
- conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
162
- }));
163
- };
164
-
165
- // src/editor-helper.ts
166
- var EmptyGroup = {
167
- element: { type: "group" },
168
- children: []
169
- };
170
- var EmptyColumn = {
171
- element: {
172
- type: "column",
173
- width: { type: "fill" },
174
- justifyContent: "justify-center",
175
- style: {}
176
- },
177
- children: []
178
- };
179
- var EmptyButton = {
180
- element: {
181
- type: "button",
182
- data: {
183
- action: "next",
184
- text: "Next",
185
- type: "default"
186
- }
187
- }
188
- };
189
- var EmptyImage = {
190
- element: { type: "image", url: "" }
191
- };
192
- var EmptyEmbed = {
193
- element: { type: "embed", url: "" }
194
- };
195
- var EmptyText = {
196
- element: {
197
- type: "text",
198
- data: [{ type: "paragraph", children: [{ text: "Write text here" }] }]
199
- }
200
- };
201
- var createNewGroup = (children) => {
202
- return {
203
- ...EmptyGroup,
204
- id: uuidV4(),
205
- children: [
206
- {
207
- ...EmptyColumn,
208
- id: uuidV4(),
209
- children: [...children]
210
- }
211
- ]
212
- };
213
- };
214
- var createNewColumn = (children) => {
215
- return {
216
- ...EmptyColumn,
217
- id: uuidV4(),
218
- children: [...children]
219
- };
220
- };
221
- var defaultInitialValue = [
222
- {
223
- ...EmptyGroup,
224
- children: [
225
- {
226
- ...EmptyColumn,
227
- children: [
228
- {
229
- ...EmptyText
230
- }
231
- ]
232
- },
233
- {
234
- ...EmptyColumn,
235
- children: [
236
- {
237
- ...EmptyEmbed
238
- }
239
- ]
240
- }
241
- ]
242
- },
243
- {
244
- ...EmptyGroup,
245
- children: [
246
- {
247
- ...EmptyColumn,
248
- children: [
249
- {
250
- ...EmptyButton
251
- }
252
- ]
253
- },
254
- {
255
- ...EmptyColumn,
256
- children: [
257
- {
258
- ...EmptyImage
259
- }
260
- ]
261
- }
262
- ]
263
- }
264
- ];
265
- var groupData = [
266
- {
267
- type: "group",
268
- isFirst: true,
269
- isLast: true,
270
- children: [
271
- {
272
- type: "column",
273
- width: { type: "fill", value: 50 },
274
- justifyContent: "justify-center",
275
- style: { marginRight: "30" },
276
- children: [
277
- {
278
- type: "paragraph",
279
- children: [{ text: "Write text here" }]
280
- }
281
- ]
282
- },
283
- {
284
- type: "column",
285
- width: { type: "fill", value: 50 },
286
- justifyContent: "justify-center",
287
- style: { marginRight: "30" },
288
- children: [
289
- {
290
- type: "paragraph",
291
- children: [{ text: "Write text here" }]
292
- }
293
- ]
294
- }
295
- ]
296
- }
297
- ];
298
- var createValue1 = [
299
- // {
300
- // element: {
301
- // type: "group",
302
- // },
303
- // children: [
304
- // {
305
- // element: {
306
- // type: "column",
307
- // width: {
308
- // type: "fill",
309
- // },
310
- // justifyContent: "justify-start",
311
- // style: {},
312
- // },
313
- // children: [
314
- // {
315
- // element: {
316
- // type: "text",
317
- // data: [
318
- // {
319
- // type: "h1",
320
- // children: [
321
- // {
322
- // text: "This is Title",
323
- // },
324
- // ],
325
- // },
326
- // ],
327
- // },
328
- // children: null,
329
- // },
330
- // ],
331
- // },
332
- // ],
333
- // },
334
- {
335
- element: {
336
- type: "group"
337
- },
338
- children: [
339
- {
340
- element: {
341
- type: "column",
342
- justifyContent: "justify-start",
343
- width: {
344
- type: "fill"
345
- },
346
- style: {}
347
- },
348
- children: [
349
- {
350
- element: {
351
- type: "text",
352
- data: [
353
- {
354
- type: "paragraph",
355
- children: [
356
- {
357
- text: "Write text here"
358
- }
359
- ]
360
- },
361
- {
362
- type: "paragraph",
363
- children: [
364
- {
365
- text: ""
366
- }
367
- ]
368
- }
369
- ]
370
- }
371
- }
372
- ]
373
- }
374
- ]
375
- }
376
- ];
377
- var createValue2 = [
378
- {
379
- element: {
380
- type: "group"
381
- },
382
- children: [
383
- {
384
- element: {
385
- type: "column",
386
- justifyContent: "justify-center",
387
- width: {
388
- type: "fill"
389
- },
390
- style: {}
391
- },
392
- children: [
393
- {
394
- element: {
395
- type: "text",
396
- data: [
397
- {
398
- type: "paragraph",
399
- children: [
400
- {
401
- text: "Write text here"
402
- }
403
- ],
404
- align: "left"
405
- },
406
- {
407
- type: "paragraph",
408
- children: [
409
- {
410
- text: ""
411
- }
412
- ]
413
- }
414
- ]
415
- }
416
- }
417
- ]
418
- }
419
- ]
420
- },
421
- {
422
- element: {
423
- type: "group"
424
- },
425
- children: [
426
- {
427
- element: {
428
- type: "column",
429
- width: {
430
- type: "fill"
431
- },
432
- justifyContent: "justify-end",
433
- style: {}
434
- },
435
- children: [
436
- {
437
- element: {
438
- type: "button",
439
- data: {
440
- action: "goto",
441
- text: "Prev",
442
- type: "secondary"
443
- }
444
- },
445
- children: null
446
- },
447
- {
448
- element: {
449
- type: "button",
450
- data: {
451
- action: "goto",
452
- text: "Next",
453
- type: "default"
454
- },
455
- margin: {
456
- top: 0,
457
- left: "10",
458
- bottom: 0,
459
- right: 0,
460
- enabled: true
461
- }
462
- },
463
- children: null
464
- }
465
- ]
466
- }
467
- ]
468
- }
469
- ];
470
- var createValue3 = [
471
- {
472
- element: {
473
- type: "group"
474
- },
475
- children: [
476
- {
477
- element: {
478
- type: "column",
479
- style: {},
480
- width: {
481
- type: "fill"
482
- },
483
- justifyContent: "justify-center"
484
- },
485
- children: [
486
- {
487
- element: {
488
- url: "https://assets.usertour.io/5d9975de-f095-40ee-a6f9-8da3c3c38515/stick-figures-holding-word-welcome-vector-banner-text-welcome-welcome-together-people-big-colorful-letters-114865217.webp",
489
- type: "image"
490
- },
491
- children: null
492
- }
493
- ]
494
- }
495
- ]
496
- },
497
- {
498
- element: {
499
- type: "group"
500
- },
501
- children: [
502
- {
503
- element: {
504
- type: "column",
505
- style: {},
506
- width: {
507
- type: "fill"
508
- },
509
- justifyContent: "justify-start"
510
- },
511
- children: [
512
- {
513
- element: {
514
- data: [
515
- {
516
- type: "paragraph",
517
- children: [
518
- {
519
- text: ""
520
- }
521
- ]
522
- },
523
- {
524
- type: "h1",
525
- align: "center",
526
- children: [
527
- {
528
- bold: true,
529
- text: "Welcome to Usertour!"
530
- }
531
- ]
532
- },
533
- {
534
- type: "paragraph",
535
- align: "center",
536
- children: [
537
- {
538
- text: ""
539
- }
540
- ]
541
- }
542
- ],
543
- type: "text"
544
- },
545
- children: null
546
- }
547
- ]
548
- }
549
- ]
550
- },
551
- {
552
- element: {
553
- type: "group"
554
- },
555
- children: [
556
- {
557
- element: {
558
- type: "column",
559
- style: {},
560
- width: {
561
- type: "fill"
562
- },
563
- justifyContent: "justify-center"
564
- },
565
- children: [
566
- {
567
- element: {
568
- data: {
569
- text: "Let's create a flow",
570
- type: "default",
571
- action: "goto",
572
- actions: [
573
- {
574
- data: {
575
- stepCvid: ""
576
- },
577
- type: "step-goto",
578
- operators: "and"
579
- }
580
- ]
581
- },
582
- type: "button"
583
- },
584
- children: null
585
- }
586
- ]
587
- }
588
- ]
589
- }
590
- ];
591
- var createValue4 = createValue3;
592
- var createValue5 = [
593
- {
594
- element: {
595
- type: "group"
596
- },
597
- children: [
598
- {
599
- element: {
600
- type: "column",
601
- justifyContent: "justify-center",
602
- width: {
603
- type: "fill"
604
- },
605
- style: {}
606
- },
607
- children: [
608
- {
609
- element: {
610
- type: "text",
611
- data: [
612
- {
613
- type: "paragraph",
614
- children: [
615
- {
616
- text: "Welcome to Usertour!"
617
- }
618
- ],
619
- align: "left"
620
- },
621
- {
622
- type: "paragraph",
623
- children: [
624
- {
625
- text: ""
626
- }
627
- ]
628
- }
629
- ]
630
- }
631
- }
632
- ]
633
- }
634
- ]
635
- },
636
- {
637
- element: {
638
- type: "group"
639
- },
640
- children: [
641
- {
642
- element: {
643
- type: "column",
644
- width: {
645
- type: "fill"
646
- },
647
- justifyContent: "justify-end",
648
- style: {}
649
- },
650
- children: [
651
- {
652
- element: {
653
- type: "button",
654
- data: {
655
- action: "goto",
656
- text: "Prev",
657
- type: "secondary"
658
- }
659
- },
660
- children: null
661
- },
662
- {
663
- element: {
664
- type: "button",
665
- data: {
666
- action: "goto",
667
- text: "Next",
668
- type: "default"
669
- },
670
- margin: {
671
- top: 0,
672
- left: "10",
673
- bottom: 0,
674
- right: 0,
675
- enabled: true
676
- }
677
- },
678
- children: null
679
- }
680
- ]
681
- }
682
- ]
683
- }
684
- ];
685
- var createValue6 = [
686
- {
687
- element: {
688
- type: "group"
689
- },
690
- children: [
691
- {
692
- element: {
693
- type: "column",
694
- justifyContent: "justify-center",
695
- width: {
696
- type: "fill"
697
- },
698
- style: {}
699
- },
700
- children: [
701
- {
702
- element: {
703
- type: "image",
704
- url: "https://assets.usertour.io/5d9975de-f095-40ee-a6f9-8da3c3c38515/stick-figures-holding-word-welcome-vector-banner-text-welcome-welcome-together-people-big-colorful-letters-114865217.webp"
705
- },
706
- children: null
707
- }
708
- ]
709
- }
710
- ]
711
- },
712
- {
713
- element: {
714
- type: "group"
715
- },
716
- children: [
717
- {
718
- element: {
719
- type: "column",
720
- width: {
721
- type: "fill"
722
- },
723
- justifyContent: "justify-start",
724
- style: {}
725
- },
726
- children: [
727
- {
728
- element: {
729
- type: "text",
730
- data: [
731
- {
732
- type: "paragraph",
733
- children: [
734
- {
735
- text: ""
736
- }
737
- ]
738
- },
739
- {
740
- type: "paragraph",
741
- children: [
742
- {
743
- text: "Title"
744
- }
745
- ]
746
- }
747
- ]
748
- },
749
- children: null
750
- }
751
- ]
752
- }
753
- ]
754
- },
755
- {
756
- element: {
757
- type: "group"
758
- },
759
- children: [
760
- {
761
- element: {
762
- type: "column",
763
- width: {
764
- type: "fill"
765
- },
766
- justifyContent: "justify-start",
767
- style: {}
768
- },
769
- children: [
770
- {
771
- element: {
772
- type: "text",
773
- data: [
774
- {
775
- type: "paragraph",
776
- children: [
777
- {
778
- text: "Write text here"
779
- }
780
- ]
781
- }
782
- ]
783
- },
784
- children: null
785
- }
786
- ]
787
- }
788
- ]
789
- },
790
- {
791
- element: {
792
- type: "group"
793
- },
794
- children: [
795
- {
796
- element: {
797
- type: "column",
798
- justifyContent: "justify-end",
799
- width: {
800
- type: "fill"
801
- },
802
- style: {}
803
- },
804
- children: [
805
- {
806
- element: {
807
- type: "button",
808
- data: {
809
- text: "Prev",
810
- type: "secondary",
811
- action: "next"
812
- }
813
- },
814
- children: null
815
- },
816
- {
817
- element: {
818
- type: "button",
819
- data: {
820
- text: "Next",
821
- type: "",
822
- action: "next"
823
- },
824
- margin: {
825
- top: "0",
826
- left: "10",
827
- bottom: 0,
828
- right: 0,
829
- enabled: true
830
- }
831
- },
832
- children: null
833
- }
834
- ]
835
- }
836
- ]
837
- }
838
- ];
839
- var surveysValue = [
840
- {
841
- element: {
842
- type: "group"
843
- },
844
- children: [
845
- {
846
- element: {
847
- type: "column",
848
- style: {},
849
- width: {
850
- type: "fill"
851
- },
852
- justifyContent: "justify-start"
853
- },
854
- children: [
855
- {
856
- element: {
857
- data: [
858
- {
859
- type: "paragraph",
860
- children: [
861
- {
862
- text: ""
863
- }
864
- ]
865
- },
866
- {
867
- type: "h1",
868
- align: "center",
869
- children: [
870
- {
871
- bold: true,
872
- text: "How easy-to-use is our product?"
873
- }
874
- ]
875
- },
876
- {
877
- type: "paragraph",
878
- children: [
879
- {
880
- text: ""
881
- }
882
- ]
883
- }
884
- ],
885
- type: "text"
886
- }
887
- }
888
- ]
889
- }
890
- ]
891
- },
892
- {
893
- element: {
894
- type: "group"
895
- },
896
- children: [
897
- {
898
- element: {
899
- type: "column",
900
- style: {},
901
- width: {
902
- type: "fill"
903
- },
904
- justifyContent: "justify-center"
905
- },
906
- children: [
907
- {
908
- element: {
909
- data: {
910
- cvid: "oatboqldqf7qcxtl1kdrvsvk",
911
- name: "sss",
912
- actions: [
913
- {
914
- data: {},
915
- type: "flow-dismis",
916
- operators: "and"
917
- }
918
- ],
919
- lowLabel: "",
920
- highLabel: "",
921
- bindToAttribute: true,
922
- selectedAttribute: "nn5"
923
- },
924
- type: "nps"
925
- },
926
- children: null
927
- }
928
- ]
929
- }
930
- ]
931
- }
932
- ];
933
- var isRestrictedType = (type) => {
934
- const restrictedTypes = [
935
- import_types3.ContentEditorElementType.NPS,
936
- import_types3.ContentEditorElementType.STAR_RATING,
937
- import_types3.ContentEditorElementType.SCALE,
938
- import_types3.ContentEditorElementType.SINGLE_LINE_TEXT,
939
- import_types3.ContentEditorElementType.MULTI_LINE_TEXT,
940
- import_types3.ContentEditorElementType.MULTIPLE_CHOICE
941
- ];
942
- return restrictedTypes.includes(type);
943
- };
944
- var isMissingRequiredData = (element) => {
945
- var _a, _b, _c, _d;
946
- if (isRestrictedType(element.type)) {
947
- return isEmptyString((_a = element.data) == null ? void 0 : _a.name);
948
- }
949
- if (element.type === import_types3.ContentEditorElementType.BUTTON) {
950
- if (isEmptyString((_b = element.data) == null ? void 0 : _b.text)) {
951
- return true;
952
- }
953
- if (!((_c = element == null ? void 0 : element.data) == null ? void 0 : _c.actions) || ((_d = element == null ? void 0 : element.data) == null ? void 0 : _d.actions.length) === 0) {
954
- return true;
955
- }
956
- }
957
- return false;
958
- };
959
- var hasMissingRequiredData = (contents) => {
960
- return contents.some(
961
- (group) => group.children.some(
962
- (column) => column.children.some((item) => isMissingRequiredData(item.element))
963
- )
964
- );
965
- };
966
- var isQuestionElement = (element) => {
967
- return element.type === import_types3.ContentEditorElementType.SINGLE_LINE_TEXT || element.type === import_types3.ContentEditorElementType.MULTI_LINE_TEXT || element.type === import_types3.ContentEditorElementType.NPS || element.type === import_types3.ContentEditorElementType.STAR_RATING || element.type === import_types3.ContentEditorElementType.SCALE || element.type === import_types3.ContentEditorElementType.MULTIPLE_CHOICE;
968
- };
969
- var isClickableElement = (element) => {
970
- return element.type === import_types3.ContentEditorElementType.BUTTON || isQuestionElement(element);
971
- };
972
- var extractQuestionData = (data) => {
973
- const result = [];
974
- function isQuestionRootElement(item) {
975
- return "element" in item && isQuestionElement(item.element);
976
- }
977
- function traverse(item) {
978
- if (isQuestionRootElement(item)) {
979
- result.push(item.element);
980
- }
981
- if ("children" in item && item.children) {
982
- for (const child of item.children) {
983
- traverse(child);
984
- }
985
- }
986
- }
987
- for (const item of data) {
988
- traverse(item);
989
- }
990
- return result;
991
- };
992
- var getDefaultDataForType = (type) => {
993
- switch (type) {
994
- case "modal":
995
- return createValue4;
996
- case "hidden":
997
- return createValue2;
998
- default:
999
- return createValue1;
1000
- }
1001
- };
1002
- var processQuestionElements = (contents) => {
1003
- if (!contents || !isArray(contents) || contents.length === 0) {
1004
- return [];
1005
- }
1006
- return contents.map((group) => ({
1007
- ...group,
1008
- children: group.children.map((column) => ({
1009
- ...column,
1010
- children: column.children.map((item) => {
1011
- var _a, _b;
1012
- const element = item.element;
1013
- if (isQuestionElement(element)) {
1014
- const questionElement = element;
1015
- const updatedElement = {
1016
- ...questionElement,
1017
- data: {
1018
- ...questionElement.data,
1019
- cvid: cuid(),
1020
- ...((_a = questionElement.data) == null ? void 0 : _a.actions) && isArray(questionElement.data.actions) ? { actions: regenerateConditionIds(questionElement.data.actions) } : {}
1021
- }
1022
- };
1023
- return {
1024
- ...item,
1025
- element: updatedElement
1026
- };
1027
- }
1028
- if (element.type === import_types3.ContentEditorElementType.BUTTON) {
1029
- const buttonElement = element;
1030
- if (((_b = buttonElement.data) == null ? void 0 : _b.actions) && isArray(buttonElement.data.actions)) {
1031
- return {
1032
- ...item,
1033
- element: {
1034
- ...buttonElement,
1035
- data: {
1036
- ...buttonElement.data,
1037
- actions: regenerateConditionIds(buttonElement.data.actions)
1038
- }
1039
- }
1040
- };
1041
- }
1042
- }
1043
- return item;
1044
- })
1045
- }))
1046
- }));
1047
- };
1048
- var regenerateTrigger = (trigger) => {
1049
- return trigger.map((t) => ({
1050
- ...t,
1051
- id: cuid(),
1052
- conditions: regenerateConditionIds(t.conditions),
1053
- actions: regenerateConditionIds(t.actions)
1054
- }));
1055
- };
1056
- var regenerateTarget = (target) => {
1057
- if (!target) {
1058
- return void 0;
1059
- }
1060
- if (target.actions && isArray(target.actions)) {
1061
- return {
1062
- ...target,
1063
- actions: regenerateConditionIds(target.actions)
1064
- };
1065
- }
1066
- return target;
1067
- };
1068
- var generateUniqueCopyName = (originalName, existingNames) => {
1069
- let name = `${originalName} (copy)`;
1070
- if (existingNames == null ? void 0 : existingNames.includes(name)) {
1071
- let number = 2;
1072
- while (existingNames.includes(`${originalName} (copy ${number})`)) {
1073
- number++;
1074
- }
1075
- name = `${originalName} (copy ${number})`;
1076
- }
1077
- return name;
1078
- };
1079
- var createStepCopy = (originalStep, sequence, existingStepNames) => {
1080
- const { id, cvid, updatedAt, createdAt, ...rest } = originalStep;
1081
- const name = generateUniqueCopyName(originalStep == null ? void 0 : originalStep.name, existingStepNames);
1082
- const trigger = (originalStep == null ? void 0 : originalStep.trigger) ? regenerateTrigger(originalStep == null ? void 0 : originalStep.trigger) : [];
1083
- const data = (originalStep == null ? void 0 : originalStep.data) ? processQuestionElements(originalStep == null ? void 0 : originalStep.data) : [];
1084
- const target = regenerateTarget(originalStep == null ? void 0 : originalStep.target);
1085
- return {
1086
- ...rest,
1087
- data,
1088
- trigger,
1089
- target,
1090
- name,
1091
- sequence
1092
- };
1093
- };
1094
- // Annotate the CommonJS export names for ESM import in node:
1095
- 0 && (module.exports = {
1096
- EmptyButton,
1097
- EmptyColumn,
1098
- EmptyEmbed,
1099
- EmptyGroup,
1100
- EmptyImage,
1101
- EmptyText,
1102
- createNewColumn,
1103
- createNewGroup,
1104
- createStepCopy,
1105
- createValue1,
1106
- createValue2,
1107
- createValue3,
1108
- createValue4,
1109
- createValue5,
1110
- createValue6,
1111
- defaultInitialValue,
1112
- extractQuestionData,
1113
- generateUniqueCopyName,
1114
- getDefaultDataForType,
1115
- groupData,
1116
- hasMissingRequiredData,
1117
- isClickableElement,
1118
- isMissingRequiredData,
1119
- isQuestionElement,
1120
- isRestrictedType,
1121
- processQuestionElements,
1122
- regenerateTarget,
1123
- regenerateTrigger,
1124
- surveysValue
1125
- });