@teamnovu/nuxt-statamic-formbuilder 1.4.0 → 1.4.2

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.4.0",
7
+ "version": "1.4.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -105,6 +105,32 @@ function resolveField(field, formValues) {
105
105
  }
106
106
  return dataGet(formValues, field);
107
107
  }
108
+ function normalizeScalar(value) {
109
+ if (typeof value !== "string") return value;
110
+ const trimmed = value.trim();
111
+ return trimmed === "" ? null : trimmed;
112
+ }
113
+ function compareScalarAgainstArray(lhs, rhs, op) {
114
+ const rhsValue = normalizeScalar(rhs);
115
+ const comparePair = (left, right) => {
116
+ switch (op) {
117
+ // eslint-disable-next-line eqeqeq
118
+ case "==":
119
+ return normalizeScalar(left) == right;
120
+ // eslint-disable-next-line eqeqeq
121
+ case "!=":
122
+ return normalizeScalar(left) != right;
123
+ case "===":
124
+ return normalizeScalar(left) === right;
125
+ case "!==":
126
+ return normalizeScalar(left) !== right;
127
+ }
128
+ };
129
+ if (op === "==" || op === "===") {
130
+ return lhs.some((value) => comparePair(value, rhsValue));
131
+ }
132
+ return lhs.every((value) => comparePair(value, rhsValue));
133
+ }
108
134
  function testCondition(condition, formValues) {
109
135
  const op = normalizeOperator(condition.operator);
110
136
  const rawLhs = resolveField(condition.field, formValues);
@@ -164,13 +190,20 @@ function testCondition(condition, formValues) {
164
190
  return lhsNum <= rhsNum;
165
191
  }
166
192
  }
167
- if (rawLhs !== null && typeof rawLhs === "object") return false;
168
- let lhs = rawLhs;
169
- if (typeof lhs === "string") {
170
- const trimmed = lhs.trim();
171
- lhs = trimmed === "" ? null : trimmed;
193
+ if (Array.isArray(rawLhs)) {
194
+ switch (op) {
195
+ case "==":
196
+ case "!=":
197
+ case "===":
198
+ case "!==":
199
+ return compareScalarAgainstArray(rawLhs, rhs, op);
200
+ default:
201
+ return false;
202
+ }
172
203
  }
173
- if (typeof rhs === "string") rhs = rhs.trim();
204
+ if (rawLhs !== null && typeof rawLhs === "object") return false;
205
+ const lhs = normalizeScalar(rawLhs);
206
+ rhs = normalizeScalar(rhs);
174
207
  switch (op) {
175
208
  // Loose equality intentional — mirrors the original eval() behaviour,
176
209
  // e.g. null == "null" should be false but null == null should be true.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/nuxt-statamic-formbuilder",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Headless Nuxt form builder with Statamic submit adapter",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/teamnovu/nuxt-statamic-formbuilder#readme",