@usertour/helpers 0.0.40 → 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.
- package/dist/__tests__/condition.test.js +2 -2
- package/dist/conditions/condition.js +2 -2
- package/dist/conditions/index.js +2 -2
- package/dist/content-helper.cjs +312 -0
- package/dist/content-helper.d.cts +32 -0
- package/dist/content-helper.d.ts +32 -0
- package/dist/content-helper.js +185 -0
- package/dist/index.js +25 -25
- package/package.json +1 -1
- package/dist/{chunk-E3B3AWMJ.js → chunk-SLM6E7HG.js} +3 -3
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
evaluateRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-SLM6E7HG.js";
|
|
6
6
|
import "../chunk-YYIGUZNZ.js";
|
|
7
7
|
import "../chunk-PAESAL23.js";
|
|
8
|
+
import "../chunk-3KG2HTZ3.js";
|
|
8
9
|
import "../chunk-KYDXF7SU.js";
|
|
9
10
|
import "../chunk-JQWKLXW6.js";
|
|
10
11
|
import "../chunk-GFH3VWOC.js";
|
|
11
|
-
import "../chunk-3KG2HTZ3.js";
|
|
12
12
|
import "../chunk-XEO3YXBM.js";
|
|
13
13
|
|
|
14
14
|
// src/__tests__/condition.test.ts
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
isConditionsActived,
|
|
9
9
|
isEqual,
|
|
10
10
|
regenerateConditionIds
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-SLM6E7HG.js";
|
|
12
12
|
import "../chunk-YYIGUZNZ.js";
|
|
13
13
|
import "../chunk-PAESAL23.js";
|
|
14
|
+
import "../chunk-3KG2HTZ3.js";
|
|
14
15
|
import "../chunk-KYDXF7SU.js";
|
|
15
16
|
import "../chunk-JQWKLXW6.js";
|
|
16
17
|
import "../chunk-GFH3VWOC.js";
|
|
17
|
-
import "../chunk-3KG2HTZ3.js";
|
|
18
18
|
import "../chunk-XEO3YXBM.js";
|
|
19
19
|
export {
|
|
20
20
|
allConditionsHaveIds,
|
package/dist/conditions/index.js
CHANGED
|
@@ -9,12 +9,13 @@ import {
|
|
|
9
9
|
isConditionsActived,
|
|
10
10
|
isEqual,
|
|
11
11
|
regenerateConditionIds
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-SLM6E7HG.js";
|
|
13
13
|
import {
|
|
14
14
|
evaluateUrlCondition,
|
|
15
15
|
isMatchUrlPattern
|
|
16
16
|
} from "../chunk-YYIGUZNZ.js";
|
|
17
17
|
import "../chunk-PAESAL23.js";
|
|
18
|
+
import "../chunk-3KG2HTZ3.js";
|
|
18
19
|
import {
|
|
19
20
|
evaluateAttributeCondition
|
|
20
21
|
} from "../chunk-KYDXF7SU.js";
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
normalizeTimeConditionData
|
|
27
28
|
} from "../chunk-JQWKLXW6.js";
|
|
28
29
|
import "../chunk-GFH3VWOC.js";
|
|
29
|
-
import "../chunk-3KG2HTZ3.js";
|
|
30
30
|
import "../chunk-XEO3YXBM.js";
|
|
31
31
|
export {
|
|
32
32
|
allConditionsHaveIds,
|
|
@@ -0,0 +1,312 @@
|
|
|
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/content-helper.ts
|
|
31
|
+
var content_helper_exports = {};
|
|
32
|
+
__export(content_helper_exports, {
|
|
33
|
+
createStepCopy: () => createStepCopy,
|
|
34
|
+
extractQuestionData: () => extractQuestionData,
|
|
35
|
+
generateUniqueCopyName: () => generateUniqueCopyName,
|
|
36
|
+
hasMissingRequiredData: () => hasMissingRequiredData,
|
|
37
|
+
isClickableElement: () => isClickableElement,
|
|
38
|
+
isMissingRequiredData: () => isMissingRequiredData,
|
|
39
|
+
isQuestionElement: () => isQuestionElement,
|
|
40
|
+
isRestrictedType: () => isRestrictedType,
|
|
41
|
+
processQuestionElements: () => processQuestionElements,
|
|
42
|
+
regenerateTarget: () => regenerateTarget,
|
|
43
|
+
regenerateTrigger: () => regenerateTrigger
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(content_helper_exports);
|
|
46
|
+
var import_types3 = require("@usertour/types");
|
|
47
|
+
|
|
48
|
+
// src/helper.ts
|
|
49
|
+
var import_clsx = require("clsx");
|
|
50
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
51
|
+
var import_uuid = require("uuid");
|
|
52
|
+
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
53
|
+
function cn(...inputs) {
|
|
54
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
55
|
+
}
|
|
56
|
+
var cuid = () => {
|
|
57
|
+
return (0, import_cuid2.createId)();
|
|
58
|
+
};
|
|
59
|
+
function formatDate(input) {
|
|
60
|
+
const date = new Date(input);
|
|
61
|
+
return date.toLocaleDateString("en-US", {
|
|
62
|
+
month: "long",
|
|
63
|
+
day: "numeric",
|
|
64
|
+
year: "numeric"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function absoluteUrl(path) {
|
|
68
|
+
return `${path}`;
|
|
69
|
+
}
|
|
70
|
+
var uuidV4 = () => {
|
|
71
|
+
return (0, import_uuid.v4)();
|
|
72
|
+
};
|
|
73
|
+
function hexToRgb(hex) {
|
|
74
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
75
|
+
return result ? {
|
|
76
|
+
r: Number.parseInt(result[1], 16),
|
|
77
|
+
g: Number.parseInt(result[2], 16),
|
|
78
|
+
b: Number.parseInt(result[3], 16)
|
|
79
|
+
} : null;
|
|
80
|
+
}
|
|
81
|
+
var isDark = (hex) => {
|
|
82
|
+
const rgb = hexToRgb(hex);
|
|
83
|
+
if (!rgb) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const { r, g, b } = rgb;
|
|
87
|
+
if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
var evalCode = (code) => {
|
|
93
|
+
try {
|
|
94
|
+
return eval(code);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Usertour.js: Error evaluating code:", error);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var getRandomColor = () => {
|
|
101
|
+
const colors = [
|
|
102
|
+
"bg-red-500",
|
|
103
|
+
"bg-orange-500",
|
|
104
|
+
"bg-yellow-500",
|
|
105
|
+
"bg-green-500",
|
|
106
|
+
"bg-teal-500",
|
|
107
|
+
"bg-blue-500",
|
|
108
|
+
"bg-indigo-500",
|
|
109
|
+
"bg-purple-500",
|
|
110
|
+
"bg-pink-500",
|
|
111
|
+
"bg-rose-500"
|
|
112
|
+
];
|
|
113
|
+
return colors[Math.floor(Math.random() * colors.length)];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/conditions/condition.ts
|
|
117
|
+
var import_types2 = require("@usertour/types");
|
|
118
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
119
|
+
|
|
120
|
+
// src/conditions/time.ts
|
|
121
|
+
var import_date_fns = require("date-fns");
|
|
122
|
+
|
|
123
|
+
// src/type-utils.ts
|
|
124
|
+
var nativeIsArray = Array.isArray;
|
|
125
|
+
var ObjProto = Object.prototype;
|
|
126
|
+
var objToString = ObjProto.toString;
|
|
127
|
+
var objHasOwn = ObjProto.hasOwnProperty;
|
|
128
|
+
var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
|
|
129
|
+
var isString = (x) => {
|
|
130
|
+
return objToString.call(x) === "[object String]";
|
|
131
|
+
};
|
|
132
|
+
var isEmptyString = (x) => isString(x) && x.trim().length === 0;
|
|
133
|
+
|
|
134
|
+
// src/conditions/attribute.ts
|
|
135
|
+
var import_types = require("@usertour/types");
|
|
136
|
+
var import_date_fns2 = require("date-fns");
|
|
137
|
+
|
|
138
|
+
// src/conditions/condition.ts
|
|
139
|
+
var regenerateConditionIds = (conditions) => {
|
|
140
|
+
return conditions.map((condition) => ({
|
|
141
|
+
...condition,
|
|
142
|
+
id: cuid(),
|
|
143
|
+
conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
|
|
144
|
+
}));
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/content-helper.ts
|
|
148
|
+
var isRestrictedType = (type) => {
|
|
149
|
+
const restrictedTypes = [
|
|
150
|
+
import_types3.ContentEditorElementType.NPS,
|
|
151
|
+
import_types3.ContentEditorElementType.STAR_RATING,
|
|
152
|
+
import_types3.ContentEditorElementType.SCALE,
|
|
153
|
+
import_types3.ContentEditorElementType.SINGLE_LINE_TEXT,
|
|
154
|
+
import_types3.ContentEditorElementType.MULTI_LINE_TEXT,
|
|
155
|
+
import_types3.ContentEditorElementType.MULTIPLE_CHOICE
|
|
156
|
+
];
|
|
157
|
+
return restrictedTypes.includes(type);
|
|
158
|
+
};
|
|
159
|
+
var isMissingRequiredData = (element) => {
|
|
160
|
+
var _a, _b, _c, _d;
|
|
161
|
+
if (isRestrictedType(element.type)) {
|
|
162
|
+
return isEmptyString((_a = element.data) == null ? void 0 : _a.name);
|
|
163
|
+
}
|
|
164
|
+
if (element.type === import_types3.ContentEditorElementType.BUTTON) {
|
|
165
|
+
if (isEmptyString((_b = element.data) == null ? void 0 : _b.text)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
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) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
var hasMissingRequiredData = (contents) => {
|
|
175
|
+
return contents.some(
|
|
176
|
+
(group) => group.children.some(
|
|
177
|
+
(column) => column.children.some((item) => isMissingRequiredData(item.element))
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
var isQuestionElement = (element) => {
|
|
182
|
+
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;
|
|
183
|
+
};
|
|
184
|
+
var isClickableElement = (element) => {
|
|
185
|
+
return element.type === import_types3.ContentEditorElementType.BUTTON || isQuestionElement(element);
|
|
186
|
+
};
|
|
187
|
+
var extractQuestionData = (data) => {
|
|
188
|
+
const result = [];
|
|
189
|
+
function isQuestionRootElement(item) {
|
|
190
|
+
return "element" in item && isQuestionElement(item.element);
|
|
191
|
+
}
|
|
192
|
+
function traverse(item) {
|
|
193
|
+
if (isQuestionRootElement(item)) {
|
|
194
|
+
result.push(item.element);
|
|
195
|
+
}
|
|
196
|
+
if ("children" in item && item.children) {
|
|
197
|
+
for (const child of item.children) {
|
|
198
|
+
traverse(child);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
for (const item of data) {
|
|
203
|
+
traverse(item);
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
};
|
|
207
|
+
var processQuestionElements = (contents) => {
|
|
208
|
+
if (!contents || !isArray(contents) || contents.length === 0) {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
return contents.map((group) => ({
|
|
212
|
+
...group,
|
|
213
|
+
children: group.children.map((column) => ({
|
|
214
|
+
...column,
|
|
215
|
+
children: column.children.map((item) => {
|
|
216
|
+
var _a, _b;
|
|
217
|
+
const element = item.element;
|
|
218
|
+
if (isQuestionElement(element)) {
|
|
219
|
+
const questionElement = element;
|
|
220
|
+
const updatedElement = {
|
|
221
|
+
...questionElement,
|
|
222
|
+
data: {
|
|
223
|
+
...questionElement.data,
|
|
224
|
+
cvid: cuid(),
|
|
225
|
+
...((_a = questionElement.data) == null ? void 0 : _a.actions) && isArray(questionElement.data.actions) ? { actions: regenerateConditionIds(questionElement.data.actions) } : {}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
...item,
|
|
230
|
+
element: updatedElement
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (element.type === import_types3.ContentEditorElementType.BUTTON) {
|
|
234
|
+
const buttonElement = element;
|
|
235
|
+
if (((_b = buttonElement.data) == null ? void 0 : _b.actions) && isArray(buttonElement.data.actions)) {
|
|
236
|
+
return {
|
|
237
|
+
...item,
|
|
238
|
+
element: {
|
|
239
|
+
...buttonElement,
|
|
240
|
+
data: {
|
|
241
|
+
...buttonElement.data,
|
|
242
|
+
actions: regenerateConditionIds(buttonElement.data.actions)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return item;
|
|
249
|
+
})
|
|
250
|
+
}))
|
|
251
|
+
}));
|
|
252
|
+
};
|
|
253
|
+
var regenerateTrigger = (trigger) => {
|
|
254
|
+
return trigger.map((t) => ({
|
|
255
|
+
...t,
|
|
256
|
+
id: cuid(),
|
|
257
|
+
conditions: regenerateConditionIds(t.conditions),
|
|
258
|
+
actions: regenerateConditionIds(t.actions)
|
|
259
|
+
}));
|
|
260
|
+
};
|
|
261
|
+
var regenerateTarget = (target) => {
|
|
262
|
+
if (!target) {
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
if (target.actions && isArray(target.actions)) {
|
|
266
|
+
return {
|
|
267
|
+
...target,
|
|
268
|
+
actions: regenerateConditionIds(target.actions)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return target;
|
|
272
|
+
};
|
|
273
|
+
var generateUniqueCopyName = (originalName, existingNames) => {
|
|
274
|
+
let name = `${originalName} (copy)`;
|
|
275
|
+
if (existingNames == null ? void 0 : existingNames.includes(name)) {
|
|
276
|
+
let number = 2;
|
|
277
|
+
while (existingNames.includes(`${originalName} (copy ${number})`)) {
|
|
278
|
+
number++;
|
|
279
|
+
}
|
|
280
|
+
name = `${originalName} (copy ${number})`;
|
|
281
|
+
}
|
|
282
|
+
return name;
|
|
283
|
+
};
|
|
284
|
+
var createStepCopy = (originalStep, sequence, existingStepNames) => {
|
|
285
|
+
const { id, cvid, updatedAt, createdAt, ...rest } = originalStep;
|
|
286
|
+
const name = generateUniqueCopyName(originalStep == null ? void 0 : originalStep.name, existingStepNames);
|
|
287
|
+
const trigger = (originalStep == null ? void 0 : originalStep.trigger) ? regenerateTrigger(originalStep == null ? void 0 : originalStep.trigger) : [];
|
|
288
|
+
const data = (originalStep == null ? void 0 : originalStep.data) ? processQuestionElements(originalStep == null ? void 0 : originalStep.data) : [];
|
|
289
|
+
const target = regenerateTarget(originalStep == null ? void 0 : originalStep.target);
|
|
290
|
+
return {
|
|
291
|
+
...rest,
|
|
292
|
+
data,
|
|
293
|
+
trigger,
|
|
294
|
+
target,
|
|
295
|
+
name,
|
|
296
|
+
sequence
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
300
|
+
0 && (module.exports = {
|
|
301
|
+
createStepCopy,
|
|
302
|
+
extractQuestionData,
|
|
303
|
+
generateUniqueCopyName,
|
|
304
|
+
hasMissingRequiredData,
|
|
305
|
+
isClickableElement,
|
|
306
|
+
isMissingRequiredData,
|
|
307
|
+
isQuestionElement,
|
|
308
|
+
isRestrictedType,
|
|
309
|
+
processQuestionElements,
|
|
310
|
+
regenerateTarget,
|
|
311
|
+
regenerateTrigger
|
|
312
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ContentEditorElementType, ContentEditorElement, ContentEditorRoot, ContentEditorClickableElement, ContentEditorQuestionElement, StepTrigger, Step } from '@usertour/types';
|
|
2
|
+
|
|
3
|
+
declare const isRestrictedType: (type: ContentEditorElementType) => boolean;
|
|
4
|
+
declare const isMissingRequiredData: (element: ContentEditorElement) => boolean;
|
|
5
|
+
declare const hasMissingRequiredData: (contents: ContentEditorRoot[]) => boolean;
|
|
6
|
+
declare const isQuestionElement: (element: ContentEditorElement) => boolean;
|
|
7
|
+
declare const isClickableElement: (element: ContentEditorClickableElement) => boolean;
|
|
8
|
+
declare const extractQuestionData: (data: ContentEditorRoot[]) => ContentEditorQuestionElement[];
|
|
9
|
+
/**
|
|
10
|
+
* Process question elements in content editor data to replace cvid with new cuid
|
|
11
|
+
* Also process actions field in all elements (button and question elements) to regenerate condition IDs
|
|
12
|
+
* @param contents - The content editor root array to process
|
|
13
|
+
* @returns A new array with question element cvids replaced by new cuids and actions regenerated
|
|
14
|
+
*/
|
|
15
|
+
declare const processQuestionElements: (contents: ContentEditorRoot[] | undefined) => ContentEditorRoot[];
|
|
16
|
+
declare const regenerateTrigger: (trigger: StepTrigger[]) => StepTrigger[];
|
|
17
|
+
/**
|
|
18
|
+
* Process target to regenerate condition IDs in actions field
|
|
19
|
+
* @param target - The target object to process
|
|
20
|
+
* @returns A new target object with regenerated action condition IDs, or undefined if target is undefined
|
|
21
|
+
*/
|
|
22
|
+
declare const regenerateTarget: (target: Step['target']) => Step['target'];
|
|
23
|
+
/**
|
|
24
|
+
* Generate a unique copy name based on the original name and existing names
|
|
25
|
+
* @param originalName - The original name to base the copy name on
|
|
26
|
+
* @param existingNames - Optional array of existing names to check against
|
|
27
|
+
* @returns A unique name in the format "Name (copy)", "Name (copy 2)", etc.
|
|
28
|
+
*/
|
|
29
|
+
declare const generateUniqueCopyName: (originalName: string, existingNames?: string[]) => string;
|
|
30
|
+
declare const createStepCopy: (originalStep: Step, sequence: number, existingStepNames?: string[]) => Step;
|
|
31
|
+
|
|
32
|
+
export { createStepCopy, extractQuestionData, generateUniqueCopyName, hasMissingRequiredData, isClickableElement, isMissingRequiredData, isQuestionElement, isRestrictedType, processQuestionElements, regenerateTarget, regenerateTrigger };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ContentEditorElementType, ContentEditorElement, ContentEditorRoot, ContentEditorClickableElement, ContentEditorQuestionElement, StepTrigger, Step } from '@usertour/types';
|
|
2
|
+
|
|
3
|
+
declare const isRestrictedType: (type: ContentEditorElementType) => boolean;
|
|
4
|
+
declare const isMissingRequiredData: (element: ContentEditorElement) => boolean;
|
|
5
|
+
declare const hasMissingRequiredData: (contents: ContentEditorRoot[]) => boolean;
|
|
6
|
+
declare const isQuestionElement: (element: ContentEditorElement) => boolean;
|
|
7
|
+
declare const isClickableElement: (element: ContentEditorClickableElement) => boolean;
|
|
8
|
+
declare const extractQuestionData: (data: ContentEditorRoot[]) => ContentEditorQuestionElement[];
|
|
9
|
+
/**
|
|
10
|
+
* Process question elements in content editor data to replace cvid with new cuid
|
|
11
|
+
* Also process actions field in all elements (button and question elements) to regenerate condition IDs
|
|
12
|
+
* @param contents - The content editor root array to process
|
|
13
|
+
* @returns A new array with question element cvids replaced by new cuids and actions regenerated
|
|
14
|
+
*/
|
|
15
|
+
declare const processQuestionElements: (contents: ContentEditorRoot[] | undefined) => ContentEditorRoot[];
|
|
16
|
+
declare const regenerateTrigger: (trigger: StepTrigger[]) => StepTrigger[];
|
|
17
|
+
/**
|
|
18
|
+
* Process target to regenerate condition IDs in actions field
|
|
19
|
+
* @param target - The target object to process
|
|
20
|
+
* @returns A new target object with regenerated action condition IDs, or undefined if target is undefined
|
|
21
|
+
*/
|
|
22
|
+
declare const regenerateTarget: (target: Step['target']) => Step['target'];
|
|
23
|
+
/**
|
|
24
|
+
* Generate a unique copy name based on the original name and existing names
|
|
25
|
+
* @param originalName - The original name to base the copy name on
|
|
26
|
+
* @param existingNames - Optional array of existing names to check against
|
|
27
|
+
* @returns A unique name in the format "Name (copy)", "Name (copy 2)", etc.
|
|
28
|
+
*/
|
|
29
|
+
declare const generateUniqueCopyName: (originalName: string, existingNames?: string[]) => string;
|
|
30
|
+
declare const createStepCopy: (originalStep: Step, sequence: number, existingStepNames?: string[]) => Step;
|
|
31
|
+
|
|
32
|
+
export { createStepCopy, extractQuestionData, generateUniqueCopyName, hasMissingRequiredData, isClickableElement, isMissingRequiredData, isQuestionElement, isRestrictedType, processQuestionElements, regenerateTarget, regenerateTrigger };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import "./chunk-7ODE2AIC.js";
|
|
2
|
+
import {
|
|
3
|
+
regenerateConditionIds
|
|
4
|
+
} from "./chunk-SLM6E7HG.js";
|
|
5
|
+
import "./chunk-YYIGUZNZ.js";
|
|
6
|
+
import "./chunk-PAESAL23.js";
|
|
7
|
+
import {
|
|
8
|
+
cuid
|
|
9
|
+
} from "./chunk-3KG2HTZ3.js";
|
|
10
|
+
import "./chunk-KYDXF7SU.js";
|
|
11
|
+
import "./chunk-JQWKLXW6.js";
|
|
12
|
+
import {
|
|
13
|
+
isArray,
|
|
14
|
+
isEmptyString
|
|
15
|
+
} from "./chunk-GFH3VWOC.js";
|
|
16
|
+
import "./chunk-XEO3YXBM.js";
|
|
17
|
+
|
|
18
|
+
// src/content-helper.ts
|
|
19
|
+
import {
|
|
20
|
+
ContentEditorElementType
|
|
21
|
+
} from "@usertour/types";
|
|
22
|
+
var isRestrictedType = (type) => {
|
|
23
|
+
const restrictedTypes = [
|
|
24
|
+
ContentEditorElementType.NPS,
|
|
25
|
+
ContentEditorElementType.STAR_RATING,
|
|
26
|
+
ContentEditorElementType.SCALE,
|
|
27
|
+
ContentEditorElementType.SINGLE_LINE_TEXT,
|
|
28
|
+
ContentEditorElementType.MULTI_LINE_TEXT,
|
|
29
|
+
ContentEditorElementType.MULTIPLE_CHOICE
|
|
30
|
+
];
|
|
31
|
+
return restrictedTypes.includes(type);
|
|
32
|
+
};
|
|
33
|
+
var isMissingRequiredData = (element) => {
|
|
34
|
+
var _a, _b, _c, _d;
|
|
35
|
+
if (isRestrictedType(element.type)) {
|
|
36
|
+
return isEmptyString((_a = element.data) == null ? void 0 : _a.name);
|
|
37
|
+
}
|
|
38
|
+
if (element.type === ContentEditorElementType.BUTTON) {
|
|
39
|
+
if (isEmptyString((_b = element.data) == null ? void 0 : _b.text)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
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) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
var hasMissingRequiredData = (contents) => {
|
|
49
|
+
return contents.some(
|
|
50
|
+
(group) => group.children.some(
|
|
51
|
+
(column) => column.children.some((item) => isMissingRequiredData(item.element))
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
var isQuestionElement = (element) => {
|
|
56
|
+
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;
|
|
57
|
+
};
|
|
58
|
+
var isClickableElement = (element) => {
|
|
59
|
+
return element.type === ContentEditorElementType.BUTTON || isQuestionElement(element);
|
|
60
|
+
};
|
|
61
|
+
var extractQuestionData = (data) => {
|
|
62
|
+
const result = [];
|
|
63
|
+
function isQuestionRootElement(item) {
|
|
64
|
+
return "element" in item && isQuestionElement(item.element);
|
|
65
|
+
}
|
|
66
|
+
function traverse(item) {
|
|
67
|
+
if (isQuestionRootElement(item)) {
|
|
68
|
+
result.push(item.element);
|
|
69
|
+
}
|
|
70
|
+
if ("children" in item && item.children) {
|
|
71
|
+
for (const child of item.children) {
|
|
72
|
+
traverse(child);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const item of data) {
|
|
77
|
+
traverse(item);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
var processQuestionElements = (contents) => {
|
|
82
|
+
if (!contents || !isArray(contents) || contents.length === 0) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return contents.map((group) => ({
|
|
86
|
+
...group,
|
|
87
|
+
children: group.children.map((column) => ({
|
|
88
|
+
...column,
|
|
89
|
+
children: column.children.map((item) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const element = item.element;
|
|
92
|
+
if (isQuestionElement(element)) {
|
|
93
|
+
const questionElement = element;
|
|
94
|
+
const updatedElement = {
|
|
95
|
+
...questionElement,
|
|
96
|
+
data: {
|
|
97
|
+
...questionElement.data,
|
|
98
|
+
cvid: cuid(),
|
|
99
|
+
...((_a = questionElement.data) == null ? void 0 : _a.actions) && isArray(questionElement.data.actions) ? { actions: regenerateConditionIds(questionElement.data.actions) } : {}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
...item,
|
|
104
|
+
element: updatedElement
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (element.type === ContentEditorElementType.BUTTON) {
|
|
108
|
+
const buttonElement = element;
|
|
109
|
+
if (((_b = buttonElement.data) == null ? void 0 : _b.actions) && isArray(buttonElement.data.actions)) {
|
|
110
|
+
return {
|
|
111
|
+
...item,
|
|
112
|
+
element: {
|
|
113
|
+
...buttonElement,
|
|
114
|
+
data: {
|
|
115
|
+
...buttonElement.data,
|
|
116
|
+
actions: regenerateConditionIds(buttonElement.data.actions)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return item;
|
|
123
|
+
})
|
|
124
|
+
}))
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
var regenerateTrigger = (trigger) => {
|
|
128
|
+
return trigger.map((t) => ({
|
|
129
|
+
...t,
|
|
130
|
+
id: cuid(),
|
|
131
|
+
conditions: regenerateConditionIds(t.conditions),
|
|
132
|
+
actions: regenerateConditionIds(t.actions)
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
135
|
+
var regenerateTarget = (target) => {
|
|
136
|
+
if (!target) {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
if (target.actions && isArray(target.actions)) {
|
|
140
|
+
return {
|
|
141
|
+
...target,
|
|
142
|
+
actions: regenerateConditionIds(target.actions)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return target;
|
|
146
|
+
};
|
|
147
|
+
var generateUniqueCopyName = (originalName, existingNames) => {
|
|
148
|
+
let name = `${originalName} (copy)`;
|
|
149
|
+
if (existingNames == null ? void 0 : existingNames.includes(name)) {
|
|
150
|
+
let number = 2;
|
|
151
|
+
while (existingNames.includes(`${originalName} (copy ${number})`)) {
|
|
152
|
+
number++;
|
|
153
|
+
}
|
|
154
|
+
name = `${originalName} (copy ${number})`;
|
|
155
|
+
}
|
|
156
|
+
return name;
|
|
157
|
+
};
|
|
158
|
+
var createStepCopy = (originalStep, sequence, existingStepNames) => {
|
|
159
|
+
const { id, cvid, updatedAt, createdAt, ...rest } = originalStep;
|
|
160
|
+
const name = generateUniqueCopyName(originalStep == null ? void 0 : originalStep.name, existingStepNames);
|
|
161
|
+
const trigger = (originalStep == null ? void 0 : originalStep.trigger) ? regenerateTrigger(originalStep == null ? void 0 : originalStep.trigger) : [];
|
|
162
|
+
const data = (originalStep == null ? void 0 : originalStep.data) ? processQuestionElements(originalStep == null ? void 0 : originalStep.data) : [];
|
|
163
|
+
const target = regenerateTarget(originalStep == null ? void 0 : originalStep.target);
|
|
164
|
+
return {
|
|
165
|
+
...rest,
|
|
166
|
+
data,
|
|
167
|
+
trigger,
|
|
168
|
+
target,
|
|
169
|
+
name,
|
|
170
|
+
sequence
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export {
|
|
174
|
+
createStepCopy,
|
|
175
|
+
extractQuestionData,
|
|
176
|
+
generateUniqueCopyName,
|
|
177
|
+
hasMissingRequiredData,
|
|
178
|
+
isClickableElement,
|
|
179
|
+
isMissingRequiredData,
|
|
180
|
+
isQuestionElement,
|
|
181
|
+
isRestrictedType,
|
|
182
|
+
processQuestionElements,
|
|
183
|
+
regenerateTarget,
|
|
184
|
+
regenerateTrigger
|
|
185
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./chunk-7ODE2AIC.js";
|
|
2
1
|
import {
|
|
3
2
|
isUrl
|
|
4
3
|
} from "./chunk-ZNFXGN3M.js";
|
|
@@ -10,6 +9,19 @@ import {
|
|
|
10
9
|
parseUrlParams,
|
|
11
10
|
wait
|
|
12
11
|
} from "./chunk-5C3J4DM2.js";
|
|
12
|
+
import {
|
|
13
|
+
capitalizeFirstLetter,
|
|
14
|
+
filterNullAttributes,
|
|
15
|
+
getAttributeType
|
|
16
|
+
} from "./chunk-EEYZG4JJ.js";
|
|
17
|
+
import {
|
|
18
|
+
getAuthToken,
|
|
19
|
+
removeAuthToken,
|
|
20
|
+
setAuthToken,
|
|
21
|
+
storage
|
|
22
|
+
} from "./chunk-FGFMTWFT.js";
|
|
23
|
+
import "./chunk-3ZGH3NRU.js";
|
|
24
|
+
import "./chunk-7ODE2AIC.js";
|
|
13
25
|
import {
|
|
14
26
|
allConditionsHaveIds,
|
|
15
27
|
assignConditionIds,
|
|
@@ -20,27 +32,26 @@ import {
|
|
|
20
32
|
isConditionsActived,
|
|
21
33
|
isEqual,
|
|
22
34
|
regenerateConditionIds
|
|
23
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-SLM6E7HG.js";
|
|
24
36
|
import {
|
|
25
37
|
evaluateUrlCondition,
|
|
26
38
|
isMatchUrlPattern
|
|
27
39
|
} from "./chunk-YYIGUZNZ.js";
|
|
28
40
|
import "./chunk-PAESAL23.js";
|
|
41
|
+
import {
|
|
42
|
+
absoluteUrl,
|
|
43
|
+
cn,
|
|
44
|
+
cuid,
|
|
45
|
+
evalCode,
|
|
46
|
+
formatDate,
|
|
47
|
+
getRandomColor,
|
|
48
|
+
hexToRgb,
|
|
49
|
+
isDark,
|
|
50
|
+
uuidV4
|
|
51
|
+
} from "./chunk-3KG2HTZ3.js";
|
|
29
52
|
import {
|
|
30
53
|
evaluateAttributeCondition
|
|
31
54
|
} from "./chunk-KYDXF7SU.js";
|
|
32
|
-
import {
|
|
33
|
-
capitalizeFirstLetter,
|
|
34
|
-
filterNullAttributes,
|
|
35
|
-
getAttributeType
|
|
36
|
-
} from "./chunk-EEYZG4JJ.js";
|
|
37
|
-
import {
|
|
38
|
-
getAuthToken,
|
|
39
|
-
removeAuthToken,
|
|
40
|
-
setAuthToken,
|
|
41
|
-
storage
|
|
42
|
-
} from "./chunk-FGFMTWFT.js";
|
|
43
|
-
import "./chunk-3ZGH3NRU.js";
|
|
44
55
|
import {
|
|
45
56
|
buildConfig,
|
|
46
57
|
defaultContentConfig,
|
|
@@ -114,17 +125,6 @@ import {
|
|
|
114
125
|
userAgent,
|
|
115
126
|
win
|
|
116
127
|
} from "./chunk-H7VA3ML2.js";
|
|
117
|
-
import {
|
|
118
|
-
absoluteUrl,
|
|
119
|
-
cn,
|
|
120
|
-
cuid,
|
|
121
|
-
evalCode,
|
|
122
|
-
formatDate,
|
|
123
|
-
getRandomColor,
|
|
124
|
-
hexToRgb,
|
|
125
|
-
isDark,
|
|
126
|
-
uuidV4
|
|
127
|
-
} from "./chunk-3KG2HTZ3.js";
|
|
128
128
|
import "./chunk-XEO3YXBM.js";
|
|
129
129
|
export {
|
|
130
130
|
AbortController,
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
evaluateUrlCondition
|
|
3
3
|
} from "./chunk-YYIGUZNZ.js";
|
|
4
|
+
import {
|
|
5
|
+
cuid
|
|
6
|
+
} from "./chunk-3KG2HTZ3.js";
|
|
4
7
|
import {
|
|
5
8
|
evaluateAttributeCondition
|
|
6
9
|
} from "./chunk-KYDXF7SU.js";
|
|
7
10
|
import {
|
|
8
11
|
evaluateTimeCondition
|
|
9
12
|
} from "./chunk-JQWKLXW6.js";
|
|
10
|
-
import {
|
|
11
|
-
cuid
|
|
12
|
-
} from "./chunk-3KG2HTZ3.js";
|
|
13
13
|
|
|
14
14
|
// src/conditions/condition.ts
|
|
15
15
|
import { RulesType } from "@usertour/types";
|