@usertour/helpers 0.0.42 → 0.0.44
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__/url.test.cjs +6 -0
- package/dist/__tests__/url.test.js +6 -0
- package/dist/chunk-MU3AHQEC.js +141 -0
- package/dist/{chunk-V3MO6EFY.js → chunk-OBKNA55U.js} +1 -0
- package/dist/content.cjs +86 -2
- package/dist/content.d.cts +4 -2
- package/dist/content.d.ts +4 -2
- package/dist/content.js +8 -3
- package/dist/convert-settings.cjs +1 -0
- package/dist/convert-settings.js +1 -1
- package/dist/index.cjs +76 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- package/package.json +2 -2
- package/dist/chunk-VWNWWZCH.js +0 -63
|
@@ -321,6 +321,12 @@ describe("URL Condition Evaluation", () => {
|
|
|
321
321
|
const excludes = [];
|
|
322
322
|
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
323
323
|
});
|
|
324
|
+
test("should handle URL patterns with wildcard in nested path", () => {
|
|
325
|
+
const url = "http://localhost:3004/client-view/sites/SUPERCONCEPTS/funds/aaaa/queries";
|
|
326
|
+
const includes = ["/client-view/sites/SUPERCONCEPTS/funds/*/queries"];
|
|
327
|
+
const excludes = [];
|
|
328
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
329
|
+
});
|
|
324
330
|
test("should handle URL patterns with fragments", () => {
|
|
325
331
|
const url = "https://example.com/dashboard#overview";
|
|
326
332
|
const includes = ["https://example.com/dashboard#*"];
|
|
@@ -243,6 +243,12 @@ describe("URL Condition Evaluation", () => {
|
|
|
243
243
|
const excludes = [];
|
|
244
244
|
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
245
245
|
});
|
|
246
|
+
test("should handle URL patterns with wildcard in nested path", () => {
|
|
247
|
+
const url = "http://localhost:3004/client-view/sites/SUPERCONCEPTS/funds/aaaa/queries";
|
|
248
|
+
const includes = ["/client-view/sites/SUPERCONCEPTS/funds/*/queries"];
|
|
249
|
+
const excludes = [];
|
|
250
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
251
|
+
});
|
|
246
252
|
test("should handle URL patterns with fragments", () => {
|
|
247
253
|
const url = "https://example.com/dashboard#overview";
|
|
248
254
|
const includes = ["https://example.com/dashboard#*"];
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isUndefined
|
|
3
|
+
} from "./chunk-GFH3VWOC.js";
|
|
4
|
+
|
|
5
|
+
// src/content.ts
|
|
6
|
+
import {
|
|
7
|
+
ContentEditorElementType,
|
|
8
|
+
ContentPriority
|
|
9
|
+
} from "@usertour/types";
|
|
10
|
+
import { deepmerge } from "deepmerge-ts";
|
|
11
|
+
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
12
|
+
var _a;
|
|
13
|
+
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return environmentList.every(
|
|
17
|
+
(env) => {
|
|
18
|
+
var _a2;
|
|
19
|
+
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
20
|
+
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
var rulesSetting = {
|
|
33
|
+
// frequency: {
|
|
34
|
+
// frequency: Frequency.ONCE,
|
|
35
|
+
// every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
|
|
36
|
+
// atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
|
|
37
|
+
// },
|
|
38
|
+
startIfNotComplete: false,
|
|
39
|
+
priority: ContentPriority.MEDIUM,
|
|
40
|
+
wait: 0
|
|
41
|
+
};
|
|
42
|
+
var hideRulesSetting = {};
|
|
43
|
+
var defaultContentConfig = {
|
|
44
|
+
enabledAutoStartRules: false,
|
|
45
|
+
enabledHideRules: false,
|
|
46
|
+
autoStartRules: [],
|
|
47
|
+
hideRules: [],
|
|
48
|
+
autoStartRulesSetting: rulesSetting,
|
|
49
|
+
hideRulesSetting
|
|
50
|
+
};
|
|
51
|
+
var buildConfig = (config) => {
|
|
52
|
+
return {
|
|
53
|
+
...defaultContentConfig,
|
|
54
|
+
...config,
|
|
55
|
+
autoStartRulesSetting: deepmerge(
|
|
56
|
+
defaultContentConfig.autoStartRulesSetting,
|
|
57
|
+
(config == null ? void 0 : config.autoStartRulesSetting) || {}
|
|
58
|
+
),
|
|
59
|
+
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
63
|
+
let url = "";
|
|
64
|
+
try {
|
|
65
|
+
for (const v of value) {
|
|
66
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
67
|
+
for (const vc of v.children) {
|
|
68
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
69
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
70
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
71
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
72
|
+
url += attrValue != null ? attrValue : fallback;
|
|
73
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
74
|
+
url += vc.fallback;
|
|
75
|
+
}
|
|
76
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
77
|
+
url += vc.text;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (_) {
|
|
83
|
+
}
|
|
84
|
+
return url;
|
|
85
|
+
};
|
|
86
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
87
|
+
return data.map((v) => {
|
|
88
|
+
if (v.children) {
|
|
89
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
90
|
+
}
|
|
91
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
92
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
93
|
+
if (!isUndefined(value)) {
|
|
94
|
+
v.value = String(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (v.type === "link" && userAttributes) {
|
|
98
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
99
|
+
}
|
|
100
|
+
return v;
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
104
|
+
return editorContents.map((editorContent) => {
|
|
105
|
+
if (!editorContent.children) {
|
|
106
|
+
return editorContent;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...editorContent,
|
|
110
|
+
children: editorContent.children.map((column) => {
|
|
111
|
+
if (!column.children) {
|
|
112
|
+
return column;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...column,
|
|
116
|
+
children: column.children.map((element) => {
|
|
117
|
+
if (element.element.type === ContentEditorElementType.TEXT) {
|
|
118
|
+
return {
|
|
119
|
+
...element,
|
|
120
|
+
element: {
|
|
121
|
+
...element.element,
|
|
122
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return { ...element };
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
isPublishedInAllEnvironments,
|
|
136
|
+
isPublishedAtLeastOneEnvironment,
|
|
137
|
+
defaultContentConfig,
|
|
138
|
+
buildConfig,
|
|
139
|
+
extractLinkUrl,
|
|
140
|
+
replaceUserAttr
|
|
141
|
+
};
|
|
@@ -209,6 +209,7 @@ var convertToCssVars = (settings, type = "tooltip") => {
|
|
|
209
209
|
"--usertour-widget-launcher-icon-active-color": settings.launcherIcon.color.active,
|
|
210
210
|
"--usertour-widget-launcher-icon-size": `${settings.launcherIcon.size}px`,
|
|
211
211
|
"--usertour-widget-beacon-color": settings.launcherBeacon.color,
|
|
212
|
+
"--usertour-widget-beacon-size": `${settings.launcherBeacon.size}px`,
|
|
212
213
|
"--usertour-widget-launcher-icon-opacity": settings.launcherIcon.opacity / 100,
|
|
213
214
|
"--usertour-widget-popper-padding-top": "2px",
|
|
214
215
|
"--usertour-widget-popper-padding-bottom": "2px",
|
package/dist/content.cjs
CHANGED
|
@@ -22,12 +22,23 @@ var content_exports = {};
|
|
|
22
22
|
__export(content_exports, {
|
|
23
23
|
buildConfig: () => buildConfig,
|
|
24
24
|
defaultContentConfig: () => defaultContentConfig,
|
|
25
|
+
extractLinkUrl: () => extractLinkUrl,
|
|
25
26
|
isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
|
|
26
|
-
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments
|
|
27
|
+
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments,
|
|
28
|
+
replaceUserAttr: () => replaceUserAttr
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(content_exports);
|
|
29
31
|
var import_types = require("@usertour/types");
|
|
30
32
|
var import_deepmerge_ts = require("deepmerge-ts");
|
|
33
|
+
|
|
34
|
+
// src/type-utils.ts
|
|
35
|
+
var nativeIsArray = Array.isArray;
|
|
36
|
+
var ObjProto = Object.prototype;
|
|
37
|
+
var objToString = ObjProto.toString;
|
|
38
|
+
var objHasOwn = ObjProto.hasOwnProperty;
|
|
39
|
+
var isUndefined = (x) => x === void 0;
|
|
40
|
+
|
|
41
|
+
// src/content.ts
|
|
31
42
|
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
32
43
|
var _a;
|
|
33
44
|
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
@@ -79,10 +90,83 @@ var buildConfig = (config) => {
|
|
|
79
90
|
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
80
91
|
};
|
|
81
92
|
};
|
|
93
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
94
|
+
let url = "";
|
|
95
|
+
try {
|
|
96
|
+
for (const v of value) {
|
|
97
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
98
|
+
for (const vc of v.children) {
|
|
99
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
100
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
101
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
102
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
103
|
+
url += attrValue != null ? attrValue : fallback;
|
|
104
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
105
|
+
url += vc.fallback;
|
|
106
|
+
}
|
|
107
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
108
|
+
url += vc.text;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (_) {
|
|
114
|
+
}
|
|
115
|
+
return url;
|
|
116
|
+
};
|
|
117
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
118
|
+
return data.map((v) => {
|
|
119
|
+
if (v.children) {
|
|
120
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
121
|
+
}
|
|
122
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
123
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
124
|
+
if (!isUndefined(value)) {
|
|
125
|
+
v.value = String(value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (v.type === "link" && userAttributes) {
|
|
129
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
130
|
+
}
|
|
131
|
+
return v;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
135
|
+
return editorContents.map((editorContent) => {
|
|
136
|
+
if (!editorContent.children) {
|
|
137
|
+
return editorContent;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
...editorContent,
|
|
141
|
+
children: editorContent.children.map((column) => {
|
|
142
|
+
if (!column.children) {
|
|
143
|
+
return column;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
...column,
|
|
147
|
+
children: column.children.map((element) => {
|
|
148
|
+
if (element.element.type === import_types.ContentEditorElementType.TEXT) {
|
|
149
|
+
return {
|
|
150
|
+
...element,
|
|
151
|
+
element: {
|
|
152
|
+
...element.element,
|
|
153
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return { ...element };
|
|
158
|
+
})
|
|
159
|
+
};
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
};
|
|
82
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
165
|
0 && (module.exports = {
|
|
84
166
|
buildConfig,
|
|
85
167
|
defaultContentConfig,
|
|
168
|
+
extractLinkUrl,
|
|
86
169
|
isPublishedAtLeastOneEnvironment,
|
|
87
|
-
isPublishedInAllEnvironments
|
|
170
|
+
isPublishedInAllEnvironments,
|
|
171
|
+
replaceUserAttr
|
|
88
172
|
});
|
package/dist/content.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Content, Environment, ContentVersion, ContentConfigObject } from '@usertour/types';
|
|
1
|
+
import { Content, Environment, ContentVersion, ContentConfigObject, UserTourTypes, ContentEditorRoot } from '@usertour/types';
|
|
2
2
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
7
|
+
declare const extractLinkUrl: (value: any[], userAttributes: UserTourTypes.Attributes) => string;
|
|
8
|
+
declare const replaceUserAttr: (editorContents: ContentEditorRoot[], userAttributes: UserTourTypes.Attributes) => ContentEditorRoot[];
|
|
7
9
|
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
|
10
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr };
|
package/dist/content.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Content, Environment, ContentVersion, ContentConfigObject } from '@usertour/types';
|
|
1
|
+
import { Content, Environment, ContentVersion, ContentConfigObject, UserTourTypes, ContentEditorRoot } from '@usertour/types';
|
|
2
2
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
7
|
+
declare const extractLinkUrl: (value: any[], userAttributes: UserTourTypes.Attributes) => string;
|
|
8
|
+
declare const replaceUserAttr: (editorContents: ContentEditorRoot[], userAttributes: UserTourTypes.Attributes) => ContentEditorRoot[];
|
|
7
9
|
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
|
10
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr };
|
package/dist/content.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig,
|
|
3
3
|
defaultContentConfig,
|
|
4
|
+
extractLinkUrl,
|
|
4
5
|
isPublishedAtLeastOneEnvironment,
|
|
5
|
-
isPublishedInAllEnvironments
|
|
6
|
-
|
|
6
|
+
isPublishedInAllEnvironments,
|
|
7
|
+
replaceUserAttr
|
|
8
|
+
} from "./chunk-MU3AHQEC.js";
|
|
9
|
+
import "./chunk-GFH3VWOC.js";
|
|
7
10
|
import "./chunk-XEO3YXBM.js";
|
|
8
11
|
export {
|
|
9
12
|
buildConfig,
|
|
10
13
|
defaultContentConfig,
|
|
14
|
+
extractLinkUrl,
|
|
11
15
|
isPublishedAtLeastOneEnvironment,
|
|
12
|
-
isPublishedInAllEnvironments
|
|
16
|
+
isPublishedInAllEnvironments,
|
|
17
|
+
replaceUserAttr
|
|
13
18
|
};
|
|
@@ -274,6 +274,7 @@ var convertToCssVars = (settings, type = "tooltip") => {
|
|
|
274
274
|
"--usertour-widget-launcher-icon-active-color": settings.launcherIcon.color.active,
|
|
275
275
|
"--usertour-widget-launcher-icon-size": `${settings.launcherIcon.size}px`,
|
|
276
276
|
"--usertour-widget-beacon-color": settings.launcherBeacon.color,
|
|
277
|
+
"--usertour-widget-beacon-size": `${settings.launcherBeacon.size}px`,
|
|
277
278
|
"--usertour-widget-launcher-icon-opacity": settings.launcherIcon.opacity / 100,
|
|
278
279
|
"--usertour-widget-popper-padding-top": "2px",
|
|
279
280
|
"--usertour-widget-popper-padding-bottom": "2px",
|
package/dist/convert-settings.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,7 @@ __export(src_exports, {
|
|
|
60
60
|
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
61
61
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
62
62
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
63
|
+
extractLinkUrl: () => extractLinkUrl,
|
|
63
64
|
fetch: () => fetch,
|
|
64
65
|
filterConditionsByType: () => filterConditionsByType,
|
|
65
66
|
filterNullAttributes: () => filterNullAttributes,
|
|
@@ -121,6 +122,7 @@ __export(src_exports, {
|
|
|
121
122
|
parseUrlParams: () => parseUrlParams,
|
|
122
123
|
regenerateConditionIds: () => regenerateConditionIds,
|
|
123
124
|
removeAuthToken: () => removeAuthToken,
|
|
125
|
+
replaceUserAttr: () => replaceUserAttr,
|
|
124
126
|
setAuthToken: () => setAuthToken,
|
|
125
127
|
storage: () => storage,
|
|
126
128
|
userAgent: () => userAgent,
|
|
@@ -432,6 +434,7 @@ var convertToCssVars = (settings, type = "tooltip") => {
|
|
|
432
434
|
"--usertour-widget-launcher-icon-active-color": settings.launcherIcon.color.active,
|
|
433
435
|
"--usertour-widget-launcher-icon-size": `${settings.launcherIcon.size}px`,
|
|
434
436
|
"--usertour-widget-beacon-color": settings.launcherBeacon.color,
|
|
437
|
+
"--usertour-widget-beacon-size": `${settings.launcherBeacon.size}px`,
|
|
435
438
|
"--usertour-widget-launcher-icon-opacity": settings.launcherIcon.opacity / 100,
|
|
436
439
|
"--usertour-widget-popper-padding-top": "2px",
|
|
437
440
|
"--usertour-widget-popper-padding-bottom": "2px",
|
|
@@ -1049,6 +1052,77 @@ var buildConfig = (config) => {
|
|
|
1049
1052
|
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
1050
1053
|
};
|
|
1051
1054
|
};
|
|
1055
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
1056
|
+
let url = "";
|
|
1057
|
+
try {
|
|
1058
|
+
for (const v of value) {
|
|
1059
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
1060
|
+
for (const vc of v.children) {
|
|
1061
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
1062
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
1063
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
1064
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
1065
|
+
url += attrValue != null ? attrValue : fallback;
|
|
1066
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
1067
|
+
url += vc.fallback;
|
|
1068
|
+
}
|
|
1069
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
1070
|
+
url += vc.text;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
} catch (_) {
|
|
1076
|
+
}
|
|
1077
|
+
return url;
|
|
1078
|
+
};
|
|
1079
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
1080
|
+
return data.map((v) => {
|
|
1081
|
+
if (v.children) {
|
|
1082
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
1083
|
+
}
|
|
1084
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
1085
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
1086
|
+
if (!isUndefined(value)) {
|
|
1087
|
+
v.value = String(value);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (v.type === "link" && userAttributes) {
|
|
1091
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
1092
|
+
}
|
|
1093
|
+
return v;
|
|
1094
|
+
});
|
|
1095
|
+
};
|
|
1096
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
1097
|
+
return editorContents.map((editorContent) => {
|
|
1098
|
+
if (!editorContent.children) {
|
|
1099
|
+
return editorContent;
|
|
1100
|
+
}
|
|
1101
|
+
return {
|
|
1102
|
+
...editorContent,
|
|
1103
|
+
children: editorContent.children.map((column) => {
|
|
1104
|
+
if (!column.children) {
|
|
1105
|
+
return column;
|
|
1106
|
+
}
|
|
1107
|
+
return {
|
|
1108
|
+
...column,
|
|
1109
|
+
children: column.children.map((element) => {
|
|
1110
|
+
if (element.element.type === import_types3.ContentEditorElementType.TEXT) {
|
|
1111
|
+
return {
|
|
1112
|
+
...element,
|
|
1113
|
+
element: {
|
|
1114
|
+
...element.element,
|
|
1115
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
return { ...element };
|
|
1120
|
+
})
|
|
1121
|
+
};
|
|
1122
|
+
})
|
|
1123
|
+
};
|
|
1124
|
+
});
|
|
1125
|
+
};
|
|
1052
1126
|
|
|
1053
1127
|
// src/utils.ts
|
|
1054
1128
|
var deepClone = (obj) => {
|
|
@@ -1652,6 +1726,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
1652
1726
|
evaluateRulesConditions,
|
|
1653
1727
|
evaluateTimeCondition,
|
|
1654
1728
|
evaluateUrlCondition,
|
|
1729
|
+
extractLinkUrl,
|
|
1655
1730
|
fetch,
|
|
1656
1731
|
filterConditionsByType,
|
|
1657
1732
|
filterNullAttributes,
|
|
@@ -1713,6 +1788,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
1713
1788
|
parseUrlParams,
|
|
1714
1789
|
regenerateConditionIds,
|
|
1715
1790
|
removeAuthToken,
|
|
1791
|
+
replaceUserAttr,
|
|
1716
1792
|
setAuthToken,
|
|
1717
1793
|
storage,
|
|
1718
1794
|
userAgent,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.cjs
|
|
|
5
5
|
export { defaultStep } from './settings.cjs';
|
|
6
6
|
export { isUrl } from './is-url.cjs';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.cjs';
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.cjs';
|
|
8
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.cjs';
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.cjs';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.js'
|
|
|
5
5
|
export { defaultStep } from './settings.js';
|
|
6
6
|
export { isUrl } from './is-url.js';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.js';
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.js';
|
|
8
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.js';
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.js';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
package/dist/index.js
CHANGED
|
@@ -55,14 +55,16 @@ import {
|
|
|
55
55
|
import {
|
|
56
56
|
buildConfig,
|
|
57
57
|
defaultContentConfig,
|
|
58
|
+
extractLinkUrl,
|
|
58
59
|
isPublishedAtLeastOneEnvironment,
|
|
59
|
-
isPublishedInAllEnvironments
|
|
60
|
-
|
|
60
|
+
isPublishedInAllEnvironments,
|
|
61
|
+
replaceUserAttr
|
|
62
|
+
} from "./chunk-MU3AHQEC.js";
|
|
61
63
|
import {
|
|
62
64
|
convertSettings,
|
|
63
65
|
convertToCssVars,
|
|
64
66
|
mergeThemeDefaultSettings
|
|
65
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-OBKNA55U.js";
|
|
66
68
|
import {
|
|
67
69
|
generateAutoStateColors,
|
|
68
70
|
hexToHSLString,
|
|
@@ -152,6 +154,7 @@ export {
|
|
|
152
154
|
evaluateRulesConditions,
|
|
153
155
|
evaluateTimeCondition,
|
|
154
156
|
evaluateUrlCondition,
|
|
157
|
+
extractLinkUrl,
|
|
155
158
|
fetch,
|
|
156
159
|
filterConditionsByType,
|
|
157
160
|
filterNullAttributes,
|
|
@@ -213,6 +216,7 @@ export {
|
|
|
213
216
|
parseUrlParams,
|
|
214
217
|
regenerateConditionIds,
|
|
215
218
|
removeAuthToken,
|
|
219
|
+
replaceUserAttr,
|
|
216
220
|
setAuthToken,
|
|
217
221
|
storage,
|
|
218
222
|
userAgent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usertour/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utility functions and helpers shared across the UserTour project",
|
|
6
6
|
"homepage": "https://www.usertour.io",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
32
|
-
"@usertour/types": "^0.0.
|
|
32
|
+
"@usertour/types": "^0.0.31",
|
|
33
33
|
"chroma-js": "^3.1.2",
|
|
34
34
|
"class-variance-authority": "^0.4.0",
|
|
35
35
|
"clsx": "^1.2.1",
|
package/dist/chunk-VWNWWZCH.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// src/content.ts
|
|
2
|
-
import {
|
|
3
|
-
ContentPriority
|
|
4
|
-
} from "@usertour/types";
|
|
5
|
-
import { deepmerge } from "deepmerge-ts";
|
|
6
|
-
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
7
|
-
var _a;
|
|
8
|
-
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
return environmentList.every(
|
|
12
|
-
(env) => {
|
|
13
|
-
var _a2;
|
|
14
|
-
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
15
|
-
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
21
|
-
var _a;
|
|
22
|
-
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
var rulesSetting = {
|
|
28
|
-
// frequency: {
|
|
29
|
-
// frequency: Frequency.ONCE,
|
|
30
|
-
// every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
|
|
31
|
-
// atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
|
|
32
|
-
// },
|
|
33
|
-
startIfNotComplete: false,
|
|
34
|
-
priority: ContentPriority.MEDIUM,
|
|
35
|
-
wait: 0
|
|
36
|
-
};
|
|
37
|
-
var hideRulesSetting = {};
|
|
38
|
-
var defaultContentConfig = {
|
|
39
|
-
enabledAutoStartRules: false,
|
|
40
|
-
enabledHideRules: false,
|
|
41
|
-
autoStartRules: [],
|
|
42
|
-
hideRules: [],
|
|
43
|
-
autoStartRulesSetting: rulesSetting,
|
|
44
|
-
hideRulesSetting
|
|
45
|
-
};
|
|
46
|
-
var buildConfig = (config) => {
|
|
47
|
-
return {
|
|
48
|
-
...defaultContentConfig,
|
|
49
|
-
...config,
|
|
50
|
-
autoStartRulesSetting: deepmerge(
|
|
51
|
-
defaultContentConfig.autoStartRulesSetting,
|
|
52
|
-
(config == null ? void 0 : config.autoStartRulesSetting) || {}
|
|
53
|
-
),
|
|
54
|
-
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
isPublishedInAllEnvironments,
|
|
60
|
-
isPublishedAtLeastOneEnvironment,
|
|
61
|
-
defaultContentConfig,
|
|
62
|
-
buildConfig
|
|
63
|
-
};
|