@usertour/helpers 0.0.39 → 0.0.40

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,976 +0,0 @@
1
- import {
2
- regenerateConditionIds
3
- } from "./chunk-SLM6E7HG.js";
4
- import {
5
- cuid,
6
- uuidV4
7
- } from "./chunk-3KG2HTZ3.js";
8
- import {
9
- isArray,
10
- isEmptyString
11
- } from "./chunk-GFH3VWOC.js";
12
-
13
- // src/editor-helper.ts
14
- import {
15
- ContentEditorElementType
16
- } from "@usertour/types";
17
- var EmptyGroup = {
18
- element: { type: "group" },
19
- children: []
20
- };
21
- var EmptyColumn = {
22
- element: {
23
- type: "column",
24
- width: { type: "fill" },
25
- justifyContent: "justify-center",
26
- style: {}
27
- },
28
- children: []
29
- };
30
- var EmptyButton = {
31
- element: {
32
- type: "button",
33
- data: {
34
- action: "next",
35
- text: "Next",
36
- type: "default"
37
- }
38
- }
39
- };
40
- var EmptyImage = {
41
- element: { type: "image", url: "" }
42
- };
43
- var EmptyEmbed = {
44
- element: { type: "embed", url: "" }
45
- };
46
- var EmptyText = {
47
- element: {
48
- type: "text",
49
- data: [{ type: "paragraph", children: [{ text: "Write text here" }] }]
50
- }
51
- };
52
- var createNewGroup = (children) => {
53
- return {
54
- ...EmptyGroup,
55
- id: uuidV4(),
56
- children: [
57
- {
58
- ...EmptyColumn,
59
- id: uuidV4(),
60
- children: [...children]
61
- }
62
- ]
63
- };
64
- };
65
- var createNewColumn = (children) => {
66
- return {
67
- ...EmptyColumn,
68
- id: uuidV4(),
69
- children: [...children]
70
- };
71
- };
72
- var defaultInitialValue = [
73
- {
74
- ...EmptyGroup,
75
- children: [
76
- {
77
- ...EmptyColumn,
78
- children: [
79
- {
80
- ...EmptyText
81
- }
82
- ]
83
- },
84
- {
85
- ...EmptyColumn,
86
- children: [
87
- {
88
- ...EmptyEmbed
89
- }
90
- ]
91
- }
92
- ]
93
- },
94
- {
95
- ...EmptyGroup,
96
- children: [
97
- {
98
- ...EmptyColumn,
99
- children: [
100
- {
101
- ...EmptyButton
102
- }
103
- ]
104
- },
105
- {
106
- ...EmptyColumn,
107
- children: [
108
- {
109
- ...EmptyImage
110
- }
111
- ]
112
- }
113
- ]
114
- }
115
- ];
116
- var groupData = [
117
- {
118
- type: "group",
119
- isFirst: true,
120
- isLast: true,
121
- children: [
122
- {
123
- type: "column",
124
- width: { type: "fill", value: 50 },
125
- justifyContent: "justify-center",
126
- style: { marginRight: "30" },
127
- children: [
128
- {
129
- type: "paragraph",
130
- children: [{ text: "Write text here" }]
131
- }
132
- ]
133
- },
134
- {
135
- type: "column",
136
- width: { type: "fill", value: 50 },
137
- justifyContent: "justify-center",
138
- style: { marginRight: "30" },
139
- children: [
140
- {
141
- type: "paragraph",
142
- children: [{ text: "Write text here" }]
143
- }
144
- ]
145
- }
146
- ]
147
- }
148
- ];
149
- var createValue1 = [
150
- // {
151
- // element: {
152
- // type: "group",
153
- // },
154
- // children: [
155
- // {
156
- // element: {
157
- // type: "column",
158
- // width: {
159
- // type: "fill",
160
- // },
161
- // justifyContent: "justify-start",
162
- // style: {},
163
- // },
164
- // children: [
165
- // {
166
- // element: {
167
- // type: "text",
168
- // data: [
169
- // {
170
- // type: "h1",
171
- // children: [
172
- // {
173
- // text: "This is Title",
174
- // },
175
- // ],
176
- // },
177
- // ],
178
- // },
179
- // children: null,
180
- // },
181
- // ],
182
- // },
183
- // ],
184
- // },
185
- {
186
- element: {
187
- type: "group"
188
- },
189
- children: [
190
- {
191
- element: {
192
- type: "column",
193
- justifyContent: "justify-start",
194
- width: {
195
- type: "fill"
196
- },
197
- style: {}
198
- },
199
- children: [
200
- {
201
- element: {
202
- type: "text",
203
- data: [
204
- {
205
- type: "paragraph",
206
- children: [
207
- {
208
- text: "Write text here"
209
- }
210
- ]
211
- },
212
- {
213
- type: "paragraph",
214
- children: [
215
- {
216
- text: ""
217
- }
218
- ]
219
- }
220
- ]
221
- }
222
- }
223
- ]
224
- }
225
- ]
226
- }
227
- ];
228
- var createValue2 = [
229
- {
230
- element: {
231
- type: "group"
232
- },
233
- children: [
234
- {
235
- element: {
236
- type: "column",
237
- justifyContent: "justify-center",
238
- width: {
239
- type: "fill"
240
- },
241
- style: {}
242
- },
243
- children: [
244
- {
245
- element: {
246
- type: "text",
247
- data: [
248
- {
249
- type: "paragraph",
250
- children: [
251
- {
252
- text: "Write text here"
253
- }
254
- ],
255
- align: "left"
256
- },
257
- {
258
- type: "paragraph",
259
- children: [
260
- {
261
- text: ""
262
- }
263
- ]
264
- }
265
- ]
266
- }
267
- }
268
- ]
269
- }
270
- ]
271
- },
272
- {
273
- element: {
274
- type: "group"
275
- },
276
- children: [
277
- {
278
- element: {
279
- type: "column",
280
- width: {
281
- type: "fill"
282
- },
283
- justifyContent: "justify-end",
284
- style: {}
285
- },
286
- children: [
287
- {
288
- element: {
289
- type: "button",
290
- data: {
291
- action: "goto",
292
- text: "Prev",
293
- type: "secondary"
294
- }
295
- },
296
- children: null
297
- },
298
- {
299
- element: {
300
- type: "button",
301
- data: {
302
- action: "goto",
303
- text: "Next",
304
- type: "default"
305
- },
306
- margin: {
307
- top: 0,
308
- left: "10",
309
- bottom: 0,
310
- right: 0,
311
- enabled: true
312
- }
313
- },
314
- children: null
315
- }
316
- ]
317
- }
318
- ]
319
- }
320
- ];
321
- var createValue3 = [
322
- {
323
- element: {
324
- type: "group"
325
- },
326
- children: [
327
- {
328
- element: {
329
- type: "column",
330
- style: {},
331
- width: {
332
- type: "fill"
333
- },
334
- justifyContent: "justify-center"
335
- },
336
- children: [
337
- {
338
- element: {
339
- 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",
340
- type: "image"
341
- },
342
- children: null
343
- }
344
- ]
345
- }
346
- ]
347
- },
348
- {
349
- element: {
350
- type: "group"
351
- },
352
- children: [
353
- {
354
- element: {
355
- type: "column",
356
- style: {},
357
- width: {
358
- type: "fill"
359
- },
360
- justifyContent: "justify-start"
361
- },
362
- children: [
363
- {
364
- element: {
365
- data: [
366
- {
367
- type: "paragraph",
368
- children: [
369
- {
370
- text: ""
371
- }
372
- ]
373
- },
374
- {
375
- type: "h1",
376
- align: "center",
377
- children: [
378
- {
379
- bold: true,
380
- text: "Welcome to Usertour!"
381
- }
382
- ]
383
- },
384
- {
385
- type: "paragraph",
386
- align: "center",
387
- children: [
388
- {
389
- text: ""
390
- }
391
- ]
392
- }
393
- ],
394
- type: "text"
395
- },
396
- children: null
397
- }
398
- ]
399
- }
400
- ]
401
- },
402
- {
403
- element: {
404
- type: "group"
405
- },
406
- children: [
407
- {
408
- element: {
409
- type: "column",
410
- style: {},
411
- width: {
412
- type: "fill"
413
- },
414
- justifyContent: "justify-center"
415
- },
416
- children: [
417
- {
418
- element: {
419
- data: {
420
- text: "Let's create a flow",
421
- type: "default",
422
- action: "goto",
423
- actions: [
424
- {
425
- data: {
426
- stepCvid: ""
427
- },
428
- type: "step-goto",
429
- operators: "and"
430
- }
431
- ]
432
- },
433
- type: "button"
434
- },
435
- children: null
436
- }
437
- ]
438
- }
439
- ]
440
- }
441
- ];
442
- var createValue4 = createValue3;
443
- var createValue5 = [
444
- {
445
- element: {
446
- type: "group"
447
- },
448
- children: [
449
- {
450
- element: {
451
- type: "column",
452
- justifyContent: "justify-center",
453
- width: {
454
- type: "fill"
455
- },
456
- style: {}
457
- },
458
- children: [
459
- {
460
- element: {
461
- type: "text",
462
- data: [
463
- {
464
- type: "paragraph",
465
- children: [
466
- {
467
- text: "Welcome to Usertour!"
468
- }
469
- ],
470
- align: "left"
471
- },
472
- {
473
- type: "paragraph",
474
- children: [
475
- {
476
- text: ""
477
- }
478
- ]
479
- }
480
- ]
481
- }
482
- }
483
- ]
484
- }
485
- ]
486
- },
487
- {
488
- element: {
489
- type: "group"
490
- },
491
- children: [
492
- {
493
- element: {
494
- type: "column",
495
- width: {
496
- type: "fill"
497
- },
498
- justifyContent: "justify-end",
499
- style: {}
500
- },
501
- children: [
502
- {
503
- element: {
504
- type: "button",
505
- data: {
506
- action: "goto",
507
- text: "Prev",
508
- type: "secondary"
509
- }
510
- },
511
- children: null
512
- },
513
- {
514
- element: {
515
- type: "button",
516
- data: {
517
- action: "goto",
518
- text: "Next",
519
- type: "default"
520
- },
521
- margin: {
522
- top: 0,
523
- left: "10",
524
- bottom: 0,
525
- right: 0,
526
- enabled: true
527
- }
528
- },
529
- children: null
530
- }
531
- ]
532
- }
533
- ]
534
- }
535
- ];
536
- var createValue6 = [
537
- {
538
- element: {
539
- type: "group"
540
- },
541
- children: [
542
- {
543
- element: {
544
- type: "column",
545
- justifyContent: "justify-center",
546
- width: {
547
- type: "fill"
548
- },
549
- style: {}
550
- },
551
- children: [
552
- {
553
- element: {
554
- type: "image",
555
- 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"
556
- },
557
- children: null
558
- }
559
- ]
560
- }
561
- ]
562
- },
563
- {
564
- element: {
565
- type: "group"
566
- },
567
- children: [
568
- {
569
- element: {
570
- type: "column",
571
- width: {
572
- type: "fill"
573
- },
574
- justifyContent: "justify-start",
575
- style: {}
576
- },
577
- children: [
578
- {
579
- element: {
580
- type: "text",
581
- data: [
582
- {
583
- type: "paragraph",
584
- children: [
585
- {
586
- text: ""
587
- }
588
- ]
589
- },
590
- {
591
- type: "paragraph",
592
- children: [
593
- {
594
- text: "Title"
595
- }
596
- ]
597
- }
598
- ]
599
- },
600
- children: null
601
- }
602
- ]
603
- }
604
- ]
605
- },
606
- {
607
- element: {
608
- type: "group"
609
- },
610
- children: [
611
- {
612
- element: {
613
- type: "column",
614
- width: {
615
- type: "fill"
616
- },
617
- justifyContent: "justify-start",
618
- style: {}
619
- },
620
- children: [
621
- {
622
- element: {
623
- type: "text",
624
- data: [
625
- {
626
- type: "paragraph",
627
- children: [
628
- {
629
- text: "Write text here"
630
- }
631
- ]
632
- }
633
- ]
634
- },
635
- children: null
636
- }
637
- ]
638
- }
639
- ]
640
- },
641
- {
642
- element: {
643
- type: "group"
644
- },
645
- children: [
646
- {
647
- element: {
648
- type: "column",
649
- justifyContent: "justify-end",
650
- width: {
651
- type: "fill"
652
- },
653
- style: {}
654
- },
655
- children: [
656
- {
657
- element: {
658
- type: "button",
659
- data: {
660
- text: "Prev",
661
- type: "secondary",
662
- action: "next"
663
- }
664
- },
665
- children: null
666
- },
667
- {
668
- element: {
669
- type: "button",
670
- data: {
671
- text: "Next",
672
- type: "",
673
- action: "next"
674
- },
675
- margin: {
676
- top: "0",
677
- left: "10",
678
- bottom: 0,
679
- right: 0,
680
- enabled: true
681
- }
682
- },
683
- children: null
684
- }
685
- ]
686
- }
687
- ]
688
- }
689
- ];
690
- var surveysValue = [
691
- {
692
- element: {
693
- type: "group"
694
- },
695
- children: [
696
- {
697
- element: {
698
- type: "column",
699
- style: {},
700
- width: {
701
- type: "fill"
702
- },
703
- justifyContent: "justify-start"
704
- },
705
- children: [
706
- {
707
- element: {
708
- data: [
709
- {
710
- type: "paragraph",
711
- children: [
712
- {
713
- text: ""
714
- }
715
- ]
716
- },
717
- {
718
- type: "h1",
719
- align: "center",
720
- children: [
721
- {
722
- bold: true,
723
- text: "How easy-to-use is our product?"
724
- }
725
- ]
726
- },
727
- {
728
- type: "paragraph",
729
- children: [
730
- {
731
- text: ""
732
- }
733
- ]
734
- }
735
- ],
736
- type: "text"
737
- }
738
- }
739
- ]
740
- }
741
- ]
742
- },
743
- {
744
- element: {
745
- type: "group"
746
- },
747
- children: [
748
- {
749
- element: {
750
- type: "column",
751
- style: {},
752
- width: {
753
- type: "fill"
754
- },
755
- justifyContent: "justify-center"
756
- },
757
- children: [
758
- {
759
- element: {
760
- data: {
761
- cvid: "oatboqldqf7qcxtl1kdrvsvk",
762
- name: "sss",
763
- actions: [
764
- {
765
- data: {},
766
- type: "flow-dismis",
767
- operators: "and"
768
- }
769
- ],
770
- lowLabel: "",
771
- highLabel: "",
772
- bindToAttribute: true,
773
- selectedAttribute: "nn5"
774
- },
775
- type: "nps"
776
- },
777
- children: null
778
- }
779
- ]
780
- }
781
- ]
782
- }
783
- ];
784
- var isRestrictedType = (type) => {
785
- const restrictedTypes = [
786
- ContentEditorElementType.NPS,
787
- ContentEditorElementType.STAR_RATING,
788
- ContentEditorElementType.SCALE,
789
- ContentEditorElementType.SINGLE_LINE_TEXT,
790
- ContentEditorElementType.MULTI_LINE_TEXT,
791
- ContentEditorElementType.MULTIPLE_CHOICE
792
- ];
793
- return restrictedTypes.includes(type);
794
- };
795
- var isMissingRequiredData = (element) => {
796
- var _a, _b, _c, _d;
797
- if (isRestrictedType(element.type)) {
798
- return isEmptyString((_a = element.data) == null ? void 0 : _a.name);
799
- }
800
- if (element.type === ContentEditorElementType.BUTTON) {
801
- if (isEmptyString((_b = element.data) == null ? void 0 : _b.text)) {
802
- return true;
803
- }
804
- 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) {
805
- return true;
806
- }
807
- }
808
- return false;
809
- };
810
- var hasMissingRequiredData = (contents) => {
811
- return contents.some(
812
- (group) => group.children.some(
813
- (column) => column.children.some((item) => isMissingRequiredData(item.element))
814
- )
815
- );
816
- };
817
- var isQuestionElement = (element) => {
818
- return element.type === ContentEditorElementType.SINGLE_LINE_TEXT || element.type === ContentEditorElementType.MULTI_LINE_TEXT || element.type === ContentEditorElementType.NPS || element.type === ContentEditorElementType.STAR_RATING || element.type === ContentEditorElementType.SCALE || element.type === ContentEditorElementType.MULTIPLE_CHOICE;
819
- };
820
- var isClickableElement = (element) => {
821
- return element.type === ContentEditorElementType.BUTTON || isQuestionElement(element);
822
- };
823
- var extractQuestionData = (data) => {
824
- const result = [];
825
- function isQuestionRootElement(item) {
826
- return "element" in item && isQuestionElement(item.element);
827
- }
828
- function traverse(item) {
829
- if (isQuestionRootElement(item)) {
830
- result.push(item.element);
831
- }
832
- if ("children" in item && item.children) {
833
- for (const child of item.children) {
834
- traverse(child);
835
- }
836
- }
837
- }
838
- for (const item of data) {
839
- traverse(item);
840
- }
841
- return result;
842
- };
843
- var getDefaultDataForType = (type) => {
844
- switch (type) {
845
- case "modal":
846
- return createValue4;
847
- case "hidden":
848
- return createValue2;
849
- default:
850
- return createValue1;
851
- }
852
- };
853
- var processQuestionElements = (contents) => {
854
- if (!contents || !isArray(contents) || contents.length === 0) {
855
- return [];
856
- }
857
- return contents.map((group) => ({
858
- ...group,
859
- children: group.children.map((column) => ({
860
- ...column,
861
- children: column.children.map((item) => {
862
- var _a, _b;
863
- const element = item.element;
864
- if (isQuestionElement(element)) {
865
- const questionElement = element;
866
- const updatedElement = {
867
- ...questionElement,
868
- data: {
869
- ...questionElement.data,
870
- cvid: cuid(),
871
- ...((_a = questionElement.data) == null ? void 0 : _a.actions) && isArray(questionElement.data.actions) ? { actions: regenerateConditionIds(questionElement.data.actions) } : {}
872
- }
873
- };
874
- return {
875
- ...item,
876
- element: updatedElement
877
- };
878
- }
879
- if (element.type === ContentEditorElementType.BUTTON) {
880
- const buttonElement = element;
881
- if (((_b = buttonElement.data) == null ? void 0 : _b.actions) && isArray(buttonElement.data.actions)) {
882
- return {
883
- ...item,
884
- element: {
885
- ...buttonElement,
886
- data: {
887
- ...buttonElement.data,
888
- actions: regenerateConditionIds(buttonElement.data.actions)
889
- }
890
- }
891
- };
892
- }
893
- }
894
- return item;
895
- })
896
- }))
897
- }));
898
- };
899
- var regenerateTrigger = (trigger) => {
900
- return trigger.map((t) => ({
901
- ...t,
902
- id: cuid(),
903
- conditions: regenerateConditionIds(t.conditions),
904
- actions: regenerateConditionIds(t.actions)
905
- }));
906
- };
907
- var regenerateTarget = (target) => {
908
- if (!target) {
909
- return void 0;
910
- }
911
- if (target.actions && isArray(target.actions)) {
912
- return {
913
- ...target,
914
- actions: regenerateConditionIds(target.actions)
915
- };
916
- }
917
- return target;
918
- };
919
- var generateUniqueCopyName = (originalName, existingNames) => {
920
- let name = `${originalName} (copy)`;
921
- if (existingNames == null ? void 0 : existingNames.includes(name)) {
922
- let number = 2;
923
- while (existingNames.includes(`${originalName} (copy ${number})`)) {
924
- number++;
925
- }
926
- name = `${originalName} (copy ${number})`;
927
- }
928
- return name;
929
- };
930
- var createStepCopy = (originalStep, sequence, existingStepNames) => {
931
- const { id, cvid, updatedAt, createdAt, ...rest } = originalStep;
932
- const name = generateUniqueCopyName(originalStep == null ? void 0 : originalStep.name, existingStepNames);
933
- const trigger = (originalStep == null ? void 0 : originalStep.trigger) ? regenerateTrigger(originalStep == null ? void 0 : originalStep.trigger) : [];
934
- const data = (originalStep == null ? void 0 : originalStep.data) ? processQuestionElements(originalStep == null ? void 0 : originalStep.data) : [];
935
- const target = regenerateTarget(originalStep == null ? void 0 : originalStep.target);
936
- return {
937
- ...rest,
938
- data,
939
- trigger,
940
- target,
941
- name,
942
- sequence
943
- };
944
- };
945
-
946
- export {
947
- EmptyGroup,
948
- EmptyColumn,
949
- EmptyButton,
950
- EmptyImage,
951
- EmptyEmbed,
952
- EmptyText,
953
- createNewGroup,
954
- createNewColumn,
955
- defaultInitialValue,
956
- groupData,
957
- createValue1,
958
- createValue2,
959
- createValue3,
960
- createValue4,
961
- createValue5,
962
- createValue6,
963
- surveysValue,
964
- isRestrictedType,
965
- isMissingRequiredData,
966
- hasMissingRequiredData,
967
- isQuestionElement,
968
- isClickableElement,
969
- extractQuestionData,
970
- getDefaultDataForType,
971
- processQuestionElements,
972
- regenerateTrigger,
973
- regenerateTarget,
974
- generateUniqueCopyName,
975
- createStepCopy
976
- };