@usertour/helpers 0.0.45 → 0.0.46

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.
@@ -59,6 +59,14 @@ var buildConfig = (config) => {
59
59
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
60
60
  };
61
61
  };
62
+ var extractUserAttributeValue = (element, userAttributes) => {
63
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
64
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
65
+ }
66
+ const attrValue = userAttributes[element.attrCode];
67
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
68
+ return attrValue != null ? attrValue : fallback;
69
+ };
62
70
  var extractLinkUrl = (value, userAttributes) => {
63
71
  let url = "";
64
72
  try {
@@ -66,13 +74,7 @@ var extractLinkUrl = (value, userAttributes) => {
66
74
  if ("children" in v && Array.isArray(v.children)) {
67
75
  for (const vc of v.children) {
68
76
  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
- }
77
+ url += String(extractUserAttributeValue(vc, userAttributes));
76
78
  } else if ("text" in vc && typeof vc.text === "string") {
77
79
  url += vc.text;
78
80
  }
@@ -89,7 +91,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
89
91
  v.children = replaceUserAttrForElement(v.children, userAttributes);
90
92
  }
91
93
  if (v.type === "user-attribute" && userAttributes) {
92
- const value = userAttributes[v.attrCode] || v.fallback;
94
+ const value = extractUserAttributeValue(v, userAttributes);
93
95
  if (!isUndefined(value)) {
94
96
  v.value = String(value);
95
97
  }
package/dist/content.cjs CHANGED
@@ -90,6 +90,14 @@ var buildConfig = (config) => {
90
90
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
91
91
  };
92
92
  };
93
+ var extractUserAttributeValue = (element, userAttributes) => {
94
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
95
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
96
+ }
97
+ const attrValue = userAttributes[element.attrCode];
98
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
99
+ return attrValue != null ? attrValue : fallback;
100
+ };
93
101
  var extractLinkUrl = (value, userAttributes) => {
94
102
  let url = "";
95
103
  try {
@@ -97,13 +105,7 @@ var extractLinkUrl = (value, userAttributes) => {
97
105
  if ("children" in v && Array.isArray(v.children)) {
98
106
  for (const vc of v.children) {
99
107
  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
- }
108
+ url += String(extractUserAttributeValue(vc, userAttributes));
107
109
  } else if ("text" in vc && typeof vc.text === "string") {
108
110
  url += vc.text;
109
111
  }
@@ -120,7 +122,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
120
122
  v.children = replaceUserAttrForElement(v.children, userAttributes);
121
123
  }
122
124
  if (v.type === "user-attribute" && userAttributes) {
123
- const value = userAttributes[v.attrCode] || v.fallback;
125
+ const value = extractUserAttributeValue(v, userAttributes);
124
126
  if (!isUndefined(value)) {
125
127
  v.value = String(value);
126
128
  }
package/dist/content.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  isPublishedAtLeastOneEnvironment,
6
6
  isPublishedInAllEnvironments,
7
7
  replaceUserAttr
8
- } from "./chunk-MU3AHQEC.js";
8
+ } from "./chunk-GK5DM6EN.js";
9
9
  import "./chunk-GFH3VWOC.js";
10
10
  import "./chunk-XEO3YXBM.js";
11
11
  export {
package/dist/index.cjs CHANGED
@@ -1053,6 +1053,14 @@ var buildConfig = (config) => {
1053
1053
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
1054
1054
  };
1055
1055
  };
1056
+ var extractUserAttributeValue = (element, userAttributes) => {
1057
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
1058
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
1059
+ }
1060
+ const attrValue = userAttributes[element.attrCode];
1061
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
1062
+ return attrValue != null ? attrValue : fallback;
1063
+ };
1056
1064
  var extractLinkUrl = (value, userAttributes) => {
1057
1065
  let url = "";
1058
1066
  try {
@@ -1060,13 +1068,7 @@ var extractLinkUrl = (value, userAttributes) => {
1060
1068
  if ("children" in v && Array.isArray(v.children)) {
1061
1069
  for (const vc of v.children) {
1062
1070
  if ("type" in vc && vc.type === "user-attribute") {
1063
- if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
1064
- const attrValue = userAttributes[vc.attrCode];
1065
- const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
1066
- url += attrValue != null ? attrValue : fallback;
1067
- } else if ("fallback" in vc && typeof vc.fallback === "string") {
1068
- url += vc.fallback;
1069
- }
1071
+ url += String(extractUserAttributeValue(vc, userAttributes));
1070
1072
  } else if ("text" in vc && typeof vc.text === "string") {
1071
1073
  url += vc.text;
1072
1074
  }
@@ -1083,7 +1085,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
1083
1085
  v.children = replaceUserAttrForElement(v.children, userAttributes);
1084
1086
  }
1085
1087
  if (v.type === "user-attribute" && userAttributes) {
1086
- const value = userAttributes[v.attrCode] || v.fallback;
1088
+ const value = extractUserAttributeValue(v, userAttributes);
1087
1089
  if (!isUndefined(value)) {
1088
1090
  v.value = String(value);
1089
1091
  }
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ import {
60
60
  isPublishedAtLeastOneEnvironment,
61
61
  isPublishedInAllEnvironments,
62
62
  replaceUserAttr
63
- } from "./chunk-MU3AHQEC.js";
63
+ } from "./chunk-GK5DM6EN.js";
64
64
  import {
65
65
  convertSettings,
66
66
  convertToCssVars,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
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.31",
32
+ "@usertour/types": "^0.0.33",
33
33
  "chroma-js": "^3.1.2",
34
34
  "class-variance-authority": "^0.4.0",
35
35
  "clsx": "^1.2.1",