@verbb/plugin-kit-forms 2.0.0
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/CHANGELOG.md +13 -0
- package/LICENSE.md +21 -0
- package/README.md +62 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +2174 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2174 @@
|
|
|
1
|
+
import { get, set } from "lodash-es";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/FormStateStore.ts
|
|
26
|
+
var FormStateStore = class {
|
|
27
|
+
state;
|
|
28
|
+
listeners = /* @__PURE__ */ new Set();
|
|
29
|
+
initialValues;
|
|
30
|
+
constructor(initialValues = {}) {
|
|
31
|
+
this.initialValues = { ...initialValues };
|
|
32
|
+
this.state = {
|
|
33
|
+
values: { ...initialValues },
|
|
34
|
+
errors: {},
|
|
35
|
+
touched: /* @__PURE__ */ new Set(),
|
|
36
|
+
dirty: /* @__PURE__ */ new Set()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
subscribe(listener) {
|
|
40
|
+
this.listeners.add(listener);
|
|
41
|
+
return () => {
|
|
42
|
+
this.listeners.delete(listener);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
notify() {
|
|
46
|
+
this.listeners.forEach((listener) => {
|
|
47
|
+
listener();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getValue(path) {
|
|
51
|
+
return get(this.state.values, path);
|
|
52
|
+
}
|
|
53
|
+
setValue(path, value) {
|
|
54
|
+
const nextErrors = { ...this.state.errors };
|
|
55
|
+
if (path in nextErrors) delete nextErrors[path];
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
const descendantPrefix = `${path}.`;
|
|
58
|
+
Object.keys(nextErrors).forEach((key) => {
|
|
59
|
+
if (key.startsWith(descendantPrefix)) delete nextErrors[key];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
this.state = {
|
|
63
|
+
...this.state,
|
|
64
|
+
values: (() => {
|
|
65
|
+
const cloneRoot = Array.isArray(this.state.values) ? [...this.state.values] : { ...this.state.values ?? {} };
|
|
66
|
+
set(cloneRoot, path, value);
|
|
67
|
+
return cloneRoot;
|
|
68
|
+
})(),
|
|
69
|
+
dirty: new Set(this.state.dirty).add(path),
|
|
70
|
+
errors: nextErrors
|
|
71
|
+
};
|
|
72
|
+
this.notify();
|
|
73
|
+
}
|
|
74
|
+
setValues(values) {
|
|
75
|
+
this.state = {
|
|
76
|
+
...this.state,
|
|
77
|
+
values: { ...values }
|
|
78
|
+
};
|
|
79
|
+
this.notify();
|
|
80
|
+
}
|
|
81
|
+
setErrors(errors) {
|
|
82
|
+
this.state = {
|
|
83
|
+
...this.state,
|
|
84
|
+
errors: { ...errors }
|
|
85
|
+
};
|
|
86
|
+
this.notify();
|
|
87
|
+
}
|
|
88
|
+
clearErrors() {
|
|
89
|
+
this.state = {
|
|
90
|
+
...this.state,
|
|
91
|
+
errors: {}
|
|
92
|
+
};
|
|
93
|
+
this.notify();
|
|
94
|
+
}
|
|
95
|
+
setTouched(path, touched = true) {
|
|
96
|
+
if (this.state.touched.has(path) === touched) return;
|
|
97
|
+
const nextTouched = new Set(this.state.touched);
|
|
98
|
+
if (touched) nextTouched.add(path);
|
|
99
|
+
else nextTouched.delete(path);
|
|
100
|
+
this.state = {
|
|
101
|
+
...this.state,
|
|
102
|
+
touched: nextTouched
|
|
103
|
+
};
|
|
104
|
+
this.notify();
|
|
105
|
+
}
|
|
106
|
+
reset(values = this.initialValues) {
|
|
107
|
+
this.initialValues = { ...values };
|
|
108
|
+
this.state = {
|
|
109
|
+
values: { ...values },
|
|
110
|
+
errors: {},
|
|
111
|
+
touched: /* @__PURE__ */ new Set(),
|
|
112
|
+
dirty: /* @__PURE__ */ new Set()
|
|
113
|
+
};
|
|
114
|
+
this.notify();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/normalizeSchema.ts
|
|
119
|
+
var normalizeSchema = (items, path = "root") => {
|
|
120
|
+
if (Array.isArray(items)) return items.map((item, index) => {
|
|
121
|
+
return normalizeSchema(item, `${path}.${index}`);
|
|
122
|
+
});
|
|
123
|
+
if (!items || typeof items !== "object") return items;
|
|
124
|
+
const itemWithId = { ...items };
|
|
125
|
+
const itemPath = path || "root";
|
|
126
|
+
if (!itemWithId._id) itemWithId._id = `schema_${itemPath}`;
|
|
127
|
+
if (Array.isArray(itemWithId.children)) itemWithId.children = itemWithId.children.map((child, index) => {
|
|
128
|
+
return normalizeSchema(child, `${itemPath}.children.${index}`);
|
|
129
|
+
});
|
|
130
|
+
if (Array.isArray(itemWithId.schema)) itemWithId.schema = itemWithId.schema.map((child, index) => {
|
|
131
|
+
return normalizeSchema(child, `${itemPath}.schema.${index}`);
|
|
132
|
+
});
|
|
133
|
+
return itemWithId;
|
|
134
|
+
};
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region ../node_modules/@babel/runtime/helpers/interopRequireDefault.js
|
|
137
|
+
var require_interopRequireDefault = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
138
|
+
function _interopRequireDefault(e) {
|
|
139
|
+
return e && e.__esModule ? e : { "default": e };
|
|
140
|
+
}
|
|
141
|
+
module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
142
|
+
}));
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region ../node_modules/@babel/runtime/helpers/typeof.js
|
|
145
|
+
var require_typeof = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
146
|
+
function _typeof(o) {
|
|
147
|
+
"@babel/helpers - typeof";
|
|
148
|
+
return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
149
|
+
return typeof o;
|
|
150
|
+
} : function(o) {
|
|
151
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
152
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof(o);
|
|
153
|
+
}
|
|
154
|
+
module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
155
|
+
}));
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region ../node_modules/@babel/runtime/helpers/toPrimitive.js
|
|
158
|
+
var require_toPrimitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
159
|
+
var _typeof = require_typeof()["default"];
|
|
160
|
+
function toPrimitive(t, r) {
|
|
161
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
162
|
+
var e = t[Symbol.toPrimitive];
|
|
163
|
+
if (void 0 !== e) {
|
|
164
|
+
var i = e.call(t, r || "default");
|
|
165
|
+
if ("object" != _typeof(i)) return i;
|
|
166
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
167
|
+
}
|
|
168
|
+
return ("string" === r ? String : Number)(t);
|
|
169
|
+
}
|
|
170
|
+
module.exports = toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
171
|
+
}));
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region ../node_modules/@babel/runtime/helpers/toPropertyKey.js
|
|
174
|
+
var require_toPropertyKey = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
175
|
+
var _typeof = require_typeof()["default"];
|
|
176
|
+
var toPrimitive = require_toPrimitive();
|
|
177
|
+
function toPropertyKey(t) {
|
|
178
|
+
var i = toPrimitive(t, "string");
|
|
179
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
180
|
+
}
|
|
181
|
+
module.exports = toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
182
|
+
}));
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region ../node_modules/@babel/runtime/helpers/defineProperty.js
|
|
185
|
+
var require_defineProperty = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
186
|
+
var toPropertyKey = require_toPropertyKey();
|
|
187
|
+
function _defineProperty(e, r, t) {
|
|
188
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
189
|
+
value: t,
|
|
190
|
+
enumerable: !0,
|
|
191
|
+
configurable: !0,
|
|
192
|
+
writable: !0
|
|
193
|
+
}) : e[r] = t, e;
|
|
194
|
+
}
|
|
195
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
196
|
+
}));
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region ../node_modules/@babel/runtime/helpers/classCallCheck.js
|
|
199
|
+
var require_classCallCheck = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
200
|
+
function _classCallCheck(a, n) {
|
|
201
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
202
|
+
}
|
|
203
|
+
module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
204
|
+
}));
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region ../node_modules/@babel/runtime/helpers/createClass.js
|
|
207
|
+
var require_createClass = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
208
|
+
var toPropertyKey = require_toPropertyKey();
|
|
209
|
+
function _defineProperties(e, r) {
|
|
210
|
+
for (var t = 0; t < r.length; t++) {
|
|
211
|
+
var o = r[t];
|
|
212
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, toPropertyKey(o.key), o);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function _createClass(e, r, t) {
|
|
216
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e;
|
|
217
|
+
}
|
|
218
|
+
module.exports = _createClass, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
219
|
+
}));
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region ../node_modules/@babel/runtime/helpers/arrayLikeToArray.js
|
|
222
|
+
var require_arrayLikeToArray = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
223
|
+
function _arrayLikeToArray(r, a) {
|
|
224
|
+
(null == a || a > r.length) && (a = r.length);
|
|
225
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
226
|
+
return n;
|
|
227
|
+
}
|
|
228
|
+
module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
229
|
+
}));
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region ../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js
|
|
232
|
+
var require_arrayWithoutHoles = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
233
|
+
var arrayLikeToArray = require_arrayLikeToArray();
|
|
234
|
+
function _arrayWithoutHoles(r) {
|
|
235
|
+
if (Array.isArray(r)) return arrayLikeToArray(r);
|
|
236
|
+
}
|
|
237
|
+
module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
238
|
+
}));
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region ../node_modules/@babel/runtime/helpers/iterableToArray.js
|
|
241
|
+
var require_iterableToArray = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
242
|
+
function _iterableToArray(r) {
|
|
243
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
244
|
+
}
|
|
245
|
+
module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
246
|
+
}));
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region ../node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js
|
|
249
|
+
var require_unsupportedIterableToArray = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
250
|
+
var arrayLikeToArray = require_arrayLikeToArray();
|
|
251
|
+
function _unsupportedIterableToArray(r, a) {
|
|
252
|
+
if (r) {
|
|
253
|
+
if ("string" == typeof r) return arrayLikeToArray(r, a);
|
|
254
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
255
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? arrayLikeToArray(r, a) : void 0;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
259
|
+
}));
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region ../node_modules/@babel/runtime/helpers/nonIterableSpread.js
|
|
262
|
+
var require_nonIterableSpread = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
263
|
+
function _nonIterableSpread() {
|
|
264
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
265
|
+
}
|
|
266
|
+
module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
267
|
+
}));
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region ../node_modules/@babel/runtime/helpers/toConsumableArray.js
|
|
270
|
+
var require_toConsumableArray = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
271
|
+
var arrayWithoutHoles = require_arrayWithoutHoles();
|
|
272
|
+
var iterableToArray = require_iterableToArray();
|
|
273
|
+
var unsupportedIterableToArray = require_unsupportedIterableToArray();
|
|
274
|
+
var nonIterableSpread = require_nonIterableSpread();
|
|
275
|
+
function _toConsumableArray(r) {
|
|
276
|
+
return arrayWithoutHoles(r) || iterableToArray(r) || unsupportedIterableToArray(r) || nonIterableSpread();
|
|
277
|
+
}
|
|
278
|
+
module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
279
|
+
}));
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region ../node_modules/jexl/dist/evaluator/handlers.js
|
|
282
|
+
var require_handlers$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
283
|
+
var _toConsumableArray2 = require_interopRequireDefault()(require_toConsumableArray());
|
|
284
|
+
var poolNames = {
|
|
285
|
+
functions: "Jexl Function",
|
|
286
|
+
transforms: "Transform"
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Evaluates an ArrayLiteral by returning its value, with each element
|
|
290
|
+
* independently run through the evaluator.
|
|
291
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
292
|
+
* ObjectLiteral as the top node
|
|
293
|
+
* @returns {Promise.<[]>} resolves to a map contained evaluated values.
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
exports.ArrayLiteral = function(ast) {
|
|
297
|
+
return this.evalArray(ast.value);
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Evaluates a BinaryExpression node by running the Grammar's evaluator for
|
|
301
|
+
* the given operator. Note that binary expressions support two types of
|
|
302
|
+
* evaluators: `eval` is called with the left and right operands pre-evaluated.
|
|
303
|
+
* `evalOnDemand`, if it exists, will be called with the left and right operands
|
|
304
|
+
* each individually wrapped in an object with an "eval" function that returns
|
|
305
|
+
* a promise with the resulting value. This allows the binary expression to
|
|
306
|
+
* evaluate the operands conditionally.
|
|
307
|
+
* @param {{type: 'BinaryExpression', operator: <string>, left: {},
|
|
308
|
+
* right: {}}} ast An expression tree with a BinaryExpression as the top
|
|
309
|
+
* node
|
|
310
|
+
* @returns {Promise<*>} resolves with the value of the BinaryExpression.
|
|
311
|
+
* @private
|
|
312
|
+
*/
|
|
313
|
+
exports.BinaryExpression = function(ast) {
|
|
314
|
+
var _this = this;
|
|
315
|
+
var grammarOp = this._grammar.elements[ast.operator];
|
|
316
|
+
if (grammarOp.evalOnDemand) {
|
|
317
|
+
var wrap = function wrap(subAst) {
|
|
318
|
+
return { eval: function _eval() {
|
|
319
|
+
return _this.eval(subAst);
|
|
320
|
+
} };
|
|
321
|
+
};
|
|
322
|
+
return grammarOp.evalOnDemand(wrap(ast.left), wrap(ast.right));
|
|
323
|
+
}
|
|
324
|
+
return this.Promise.all([this.eval(ast.left), this.eval(ast.right)]).then(function(arr) {
|
|
325
|
+
return grammarOp.eval(arr[0], arr[1]);
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Evaluates a ConditionalExpression node by first evaluating its test branch,
|
|
330
|
+
* and resolving with the consequent branch if the test is truthy, or the
|
|
331
|
+
* alternate branch if it is not. If there is no consequent branch, the test
|
|
332
|
+
* result will be used instead.
|
|
333
|
+
* @param {{type: 'ConditionalExpression', test: {}, consequent: {},
|
|
334
|
+
* alternate: {}}} ast An expression tree with a ConditionalExpression as
|
|
335
|
+
* the top node
|
|
336
|
+
* @private
|
|
337
|
+
*/
|
|
338
|
+
exports.ConditionalExpression = function(ast) {
|
|
339
|
+
var _this2 = this;
|
|
340
|
+
return this.eval(ast.test).then(function(res) {
|
|
341
|
+
if (res) {
|
|
342
|
+
if (ast.consequent) return _this2.eval(ast.consequent);
|
|
343
|
+
return res;
|
|
344
|
+
}
|
|
345
|
+
return _this2.eval(ast.alternate);
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* Evaluates a FilterExpression by applying it to the subject value.
|
|
350
|
+
* @param {{type: 'FilterExpression', relative: <boolean>, expr: {},
|
|
351
|
+
* subject: {}}} ast An expression tree with a FilterExpression as the top
|
|
352
|
+
* node
|
|
353
|
+
* @returns {Promise<*>} resolves with the value of the FilterExpression.
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
exports.FilterExpression = function(ast) {
|
|
357
|
+
var _this3 = this;
|
|
358
|
+
return this.eval(ast.subject).then(function(subject) {
|
|
359
|
+
if (ast.relative) return _this3._filterRelative(subject, ast.expr);
|
|
360
|
+
return _this3._filterStatic(subject, ast.expr);
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Evaluates an Identifier by either stemming from the evaluated 'from'
|
|
365
|
+
* expression tree or accessing the context provided when this Evaluator was
|
|
366
|
+
* constructed.
|
|
367
|
+
* @param {{type: 'Identifier', value: <string>, [from]: {}}} ast An expression
|
|
368
|
+
* tree with an Identifier as the top node
|
|
369
|
+
* @returns {Promise<*>|*} either the identifier's value, or a Promise that
|
|
370
|
+
* will resolve with the identifier's value.
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
exports.Identifier = function(ast) {
|
|
374
|
+
if (!ast.from) return ast.relative ? this._relContext[ast.value] : this._context[ast.value];
|
|
375
|
+
return this.eval(ast.from).then(function(context) {
|
|
376
|
+
if (context === void 0 || context === null) return;
|
|
377
|
+
if (Array.isArray(context)) context = context[0];
|
|
378
|
+
return context[ast.value];
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Evaluates a Literal by returning its value property.
|
|
383
|
+
* @param {{type: 'Literal', value: <string|number|boolean>}} ast An expression
|
|
384
|
+
* tree with a Literal as its only node
|
|
385
|
+
* @returns {string|number|boolean} The value of the Literal node
|
|
386
|
+
* @private
|
|
387
|
+
*/
|
|
388
|
+
exports.Literal = function(ast) {
|
|
389
|
+
return ast.value;
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Evaluates an ObjectLiteral by returning its value, with each key
|
|
393
|
+
* independently run through the evaluator.
|
|
394
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
395
|
+
* ObjectLiteral as the top node
|
|
396
|
+
* @returns {Promise<{}>} resolves to a map contained evaluated values.
|
|
397
|
+
* @private
|
|
398
|
+
*/
|
|
399
|
+
exports.ObjectLiteral = function(ast) {
|
|
400
|
+
return this.evalMap(ast.value);
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Evaluates a FunctionCall node by applying the supplied arguments to a
|
|
404
|
+
* function defined in one of the grammar's function pools.
|
|
405
|
+
* @param {{type: 'FunctionCall', name: <string>}} ast An
|
|
406
|
+
* expression tree with a FunctionCall as the top node
|
|
407
|
+
* @returns {Promise<*>|*} the value of the function call, or a Promise that
|
|
408
|
+
* will resolve with the resulting value.
|
|
409
|
+
* @private
|
|
410
|
+
*/
|
|
411
|
+
exports.FunctionCall = function(ast) {
|
|
412
|
+
var poolName = poolNames[ast.pool];
|
|
413
|
+
if (!poolName) throw new Error("Corrupt AST: Pool '".concat(ast.pool, "' not found"));
|
|
414
|
+
var func = this._grammar[ast.pool][ast.name];
|
|
415
|
+
if (!func) throw new Error("".concat(poolName, " ").concat(ast.name, " is not defined."));
|
|
416
|
+
return this.evalArray(ast.args || []).then(function(args) {
|
|
417
|
+
return func.apply(void 0, (0, _toConsumableArray2.default)(args));
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Evaluates a Unary expression by passing the right side through the
|
|
422
|
+
* operator's eval function.
|
|
423
|
+
* @param {{type: 'UnaryExpression', operator: <string>, right: {}}} ast An
|
|
424
|
+
* expression tree with a UnaryExpression as the top node
|
|
425
|
+
* @returns {Promise<*>} resolves with the value of the UnaryExpression.
|
|
426
|
+
* @constructor
|
|
427
|
+
*/
|
|
428
|
+
exports.UnaryExpression = function(ast) {
|
|
429
|
+
var _this4 = this;
|
|
430
|
+
return this.eval(ast.right).then(function(right) {
|
|
431
|
+
return _this4._grammar.elements[ast.operator].eval(right);
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
}));
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region ../node_modules/jexl/dist/evaluator/Evaluator.js
|
|
437
|
+
var require_Evaluator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
438
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
439
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
440
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
441
|
+
var handlers = require_handlers$1();
|
|
442
|
+
module.exports = /* @__PURE__ */ function() {
|
|
443
|
+
function Evaluator(grammar, context, relativeContext) {
|
|
444
|
+
var promise = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : Promise;
|
|
445
|
+
(0, _classCallCheck2.default)(this, Evaluator);
|
|
446
|
+
this._grammar = grammar;
|
|
447
|
+
this._context = context || {};
|
|
448
|
+
this._relContext = relativeContext || this._context;
|
|
449
|
+
this.Promise = promise;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Evaluates an expression tree within the configured context.
|
|
453
|
+
* @param {{}} ast An expression tree object
|
|
454
|
+
* @returns {Promise<*>} resolves with the resulting value of the expression.
|
|
455
|
+
*/
|
|
456
|
+
(0, _createClass2.default)(Evaluator, [
|
|
457
|
+
{
|
|
458
|
+
key: "eval",
|
|
459
|
+
value: function _eval(ast) {
|
|
460
|
+
var _this = this;
|
|
461
|
+
return this.Promise.resolve().then(function() {
|
|
462
|
+
return handlers[ast.type].call(_this, ast);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
key: "evalArray",
|
|
468
|
+
value: function evalArray(arr) {
|
|
469
|
+
var _this2 = this;
|
|
470
|
+
return this.Promise.all(arr.map(function(elem) {
|
|
471
|
+
return _this2.eval(elem);
|
|
472
|
+
}));
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
key: "evalMap",
|
|
477
|
+
value: function evalMap(map) {
|
|
478
|
+
var _this3 = this;
|
|
479
|
+
var keys = Object.keys(map);
|
|
480
|
+
var result = {};
|
|
481
|
+
var asts = keys.map(function(key) {
|
|
482
|
+
return _this3.eval(map[key]);
|
|
483
|
+
});
|
|
484
|
+
return this.Promise.all(asts).then(function(vals) {
|
|
485
|
+
vals.forEach(function(val, idx) {
|
|
486
|
+
result[keys[idx]] = val;
|
|
487
|
+
});
|
|
488
|
+
return result;
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
key: "_filterRelative",
|
|
494
|
+
value: function _filterRelative(subject, expr) {
|
|
495
|
+
var _this4 = this;
|
|
496
|
+
var promises = [];
|
|
497
|
+
if (!Array.isArray(subject)) subject = subject === void 0 ? [] : [subject];
|
|
498
|
+
subject.forEach(function(elem) {
|
|
499
|
+
var evalInst = new Evaluator(_this4._grammar, _this4._context, elem, _this4.Promise);
|
|
500
|
+
promises.push(evalInst.eval(expr));
|
|
501
|
+
});
|
|
502
|
+
return this.Promise.all(promises).then(function(values) {
|
|
503
|
+
var results = [];
|
|
504
|
+
values.forEach(function(value, idx) {
|
|
505
|
+
if (value) results.push(subject[idx]);
|
|
506
|
+
});
|
|
507
|
+
return results;
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
key: "_filterStatic",
|
|
513
|
+
value: function _filterStatic(subject, expr) {
|
|
514
|
+
return this.eval(expr).then(function(res) {
|
|
515
|
+
if (typeof res === "boolean") return res ? subject : void 0;
|
|
516
|
+
return subject[res];
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
]);
|
|
521
|
+
return Evaluator;
|
|
522
|
+
}();
|
|
523
|
+
}));
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region ../node_modules/jexl/dist/Lexer.js
|
|
526
|
+
var require_Lexer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
527
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
528
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
529
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
530
|
+
var numericRegex = /^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/;
|
|
531
|
+
var identRegex = /^[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*$/;
|
|
532
|
+
var escEscRegex = /\\\\/;
|
|
533
|
+
var whitespaceRegex = /^\s*$/;
|
|
534
|
+
var preOpRegexElems = [
|
|
535
|
+
"'(?:(?:\\\\')|[^'])*'",
|
|
536
|
+
"\"(?:(?:\\\\\")|[^\"])*\"",
|
|
537
|
+
"\\s+",
|
|
538
|
+
"\\btrue\\b",
|
|
539
|
+
"\\bfalse\\b"
|
|
540
|
+
];
|
|
541
|
+
var postOpRegexElems = ["[a-zA-Zа-яА-Я_À-ÖØ-öø-ÿ\\$][a-zA-Z0-9а-яА-Я_À-ÖØ-öø-ÿ\\$]*", "(?:(?:[0-9]*\\.[0-9]+)|[0-9]+)"];
|
|
542
|
+
var minusNegatesAfter = [
|
|
543
|
+
"binaryOp",
|
|
544
|
+
"unaryOp",
|
|
545
|
+
"openParen",
|
|
546
|
+
"openBracket",
|
|
547
|
+
"question",
|
|
548
|
+
"colon"
|
|
549
|
+
];
|
|
550
|
+
module.exports = /* @__PURE__ */ function() {
|
|
551
|
+
function Lexer(grammar) {
|
|
552
|
+
(0, _classCallCheck2.default)(this, Lexer);
|
|
553
|
+
this._grammar = grammar;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Splits a Jexl expression string into an array of expression elements.
|
|
557
|
+
* @param {string} str A Jexl expression string
|
|
558
|
+
* @returns {Array<string>} An array of substrings defining the functional
|
|
559
|
+
* elements of the expression.
|
|
560
|
+
*/
|
|
561
|
+
(0, _createClass2.default)(Lexer, [
|
|
562
|
+
{
|
|
563
|
+
key: "getElements",
|
|
564
|
+
value: function getElements(str) {
|
|
565
|
+
var regex = this._getSplitRegex();
|
|
566
|
+
return str.split(regex).filter(function(elem) {
|
|
567
|
+
return elem;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
key: "getTokens",
|
|
573
|
+
value: function getTokens(elements) {
|
|
574
|
+
var tokens = [];
|
|
575
|
+
var negate = false;
|
|
576
|
+
for (var i = 0; i < elements.length; i++) if (this._isWhitespace(elements[i])) {
|
|
577
|
+
if (tokens.length) tokens[tokens.length - 1].raw += elements[i];
|
|
578
|
+
} else if (elements[i] === "-" && this._isNegative(tokens)) negate = true;
|
|
579
|
+
else {
|
|
580
|
+
if (negate) {
|
|
581
|
+
elements[i] = "-" + elements[i];
|
|
582
|
+
negate = false;
|
|
583
|
+
}
|
|
584
|
+
tokens.push(this._createToken(elements[i]));
|
|
585
|
+
}
|
|
586
|
+
if (negate) tokens.push(this._createToken("-"));
|
|
587
|
+
return tokens;
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
key: "tokenize",
|
|
592
|
+
value: function tokenize(str) {
|
|
593
|
+
var elements = this.getElements(str);
|
|
594
|
+
return this.getTokens(elements);
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
key: "_createToken",
|
|
599
|
+
value: function _createToken(element) {
|
|
600
|
+
var token = {
|
|
601
|
+
type: "literal",
|
|
602
|
+
value: element,
|
|
603
|
+
raw: element
|
|
604
|
+
};
|
|
605
|
+
if (element[0] === "\"" || element[0] === "'") token.value = this._unquote(element);
|
|
606
|
+
else if (element.match(numericRegex)) token.value = parseFloat(element);
|
|
607
|
+
else if (element === "true" || element === "false") token.value = element === "true";
|
|
608
|
+
else if (this._grammar.elements[element]) token.type = this._grammar.elements[element].type;
|
|
609
|
+
else if (element.match(identRegex)) token.type = "identifier";
|
|
610
|
+
else throw new Error("Invalid expression token: ".concat(element));
|
|
611
|
+
return token;
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
key: "_escapeRegExp",
|
|
616
|
+
value: function _escapeRegExp(str) {
|
|
617
|
+
str = str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
618
|
+
if (str.match(identRegex)) str = "\\b" + str + "\\b";
|
|
619
|
+
return str;
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
key: "_getSplitRegex",
|
|
624
|
+
value: function _getSplitRegex() {
|
|
625
|
+
var _this = this;
|
|
626
|
+
if (!this._splitRegex) {
|
|
627
|
+
var elemArray = Object.keys(this._grammar.elements).sort(function(a, b) {
|
|
628
|
+
return b.length - a.length;
|
|
629
|
+
}).map(function(elem) {
|
|
630
|
+
return _this._escapeRegExp(elem);
|
|
631
|
+
}, this);
|
|
632
|
+
this._splitRegex = new RegExp("(" + [
|
|
633
|
+
preOpRegexElems.join("|"),
|
|
634
|
+
elemArray.join("|"),
|
|
635
|
+
postOpRegexElems.join("|")
|
|
636
|
+
].join("|") + ")");
|
|
637
|
+
}
|
|
638
|
+
return this._splitRegex;
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
key: "_isNegative",
|
|
643
|
+
value: function _isNegative(tokens) {
|
|
644
|
+
if (!tokens.length) return true;
|
|
645
|
+
return minusNegatesAfter.some(function(type) {
|
|
646
|
+
return type === tokens[tokens.length - 1].type;
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
key: "_isWhitespace",
|
|
652
|
+
value: function _isWhitespace(str) {
|
|
653
|
+
return !!str.match(whitespaceRegex);
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
key: "_unquote",
|
|
658
|
+
value: function _unquote(str) {
|
|
659
|
+
var quote = str[0];
|
|
660
|
+
var escQuoteRegex = new RegExp("\\\\" + quote, "g");
|
|
661
|
+
return str.substr(1, str.length - 2).replace(escQuoteRegex, quote).replace(escEscRegex, "\\");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
]);
|
|
665
|
+
return Lexer;
|
|
666
|
+
}();
|
|
667
|
+
}));
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region ../node_modules/jexl/dist/parser/handlers.js
|
|
670
|
+
var require_handlers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
671
|
+
/**
|
|
672
|
+
* Handles a subexpression that's used to define a transform argument's value.
|
|
673
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
674
|
+
*/
|
|
675
|
+
exports.argVal = function(ast) {
|
|
676
|
+
if (ast) this._cursor.args.push(ast);
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Handles new array literals by adding them as a new node in the AST,
|
|
680
|
+
* initialized with an empty array.
|
|
681
|
+
*/
|
|
682
|
+
exports.arrayStart = function() {
|
|
683
|
+
this._placeAtCursor({
|
|
684
|
+
type: "ArrayLiteral",
|
|
685
|
+
value: []
|
|
686
|
+
});
|
|
687
|
+
};
|
|
688
|
+
/**
|
|
689
|
+
* Handles a subexpression representing an element of an array literal.
|
|
690
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
691
|
+
*/
|
|
692
|
+
exports.arrayVal = function(ast) {
|
|
693
|
+
if (ast) this._cursor.value.push(ast);
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* Handles tokens of type 'binaryOp', indicating an operation that has two
|
|
697
|
+
* inputs: a left side and a right side.
|
|
698
|
+
* @param {{type: <string>}} token A token object
|
|
699
|
+
*/
|
|
700
|
+
exports.binaryOp = function(token) {
|
|
701
|
+
var precedence = this._grammar.elements[token.value].precedence || 0;
|
|
702
|
+
var parent = this._cursor._parent;
|
|
703
|
+
while (parent && parent.operator && this._grammar.elements[parent.operator].precedence >= precedence) {
|
|
704
|
+
this._cursor = parent;
|
|
705
|
+
parent = parent._parent;
|
|
706
|
+
}
|
|
707
|
+
var node = {
|
|
708
|
+
type: "BinaryExpression",
|
|
709
|
+
operator: token.value,
|
|
710
|
+
left: this._cursor
|
|
711
|
+
};
|
|
712
|
+
this._setParent(this._cursor, node);
|
|
713
|
+
this._cursor = parent;
|
|
714
|
+
this._placeAtCursor(node);
|
|
715
|
+
};
|
|
716
|
+
/**
|
|
717
|
+
* Handles successive nodes in an identifier chain. More specifically, it
|
|
718
|
+
* sets values that determine how the following identifier gets placed in the
|
|
719
|
+
* AST.
|
|
720
|
+
*/
|
|
721
|
+
exports.dot = function() {
|
|
722
|
+
this._nextIdentEncapsulate = this._cursor && this._cursor.type !== "UnaryExpression" && (this._cursor.type !== "BinaryExpression" || this._cursor.type === "BinaryExpression" && this._cursor.right);
|
|
723
|
+
this._nextIdentRelative = !this._cursor || this._cursor && !this._nextIdentEncapsulate;
|
|
724
|
+
if (this._nextIdentRelative) this._relative = true;
|
|
725
|
+
};
|
|
726
|
+
/**
|
|
727
|
+
* Handles a subexpression used for filtering an array returned by an
|
|
728
|
+
* identifier chain.
|
|
729
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
730
|
+
*/
|
|
731
|
+
exports.filter = function(ast) {
|
|
732
|
+
this._placeBeforeCursor({
|
|
733
|
+
type: "FilterExpression",
|
|
734
|
+
expr: ast,
|
|
735
|
+
relative: this._subParser.isRelative(),
|
|
736
|
+
subject: this._cursor
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* Handles identifier tokens when used to indicate the name of a function to
|
|
741
|
+
* be called.
|
|
742
|
+
* @param {{type: <string>}} token A token object
|
|
743
|
+
*/
|
|
744
|
+
exports.functionCall = function() {
|
|
745
|
+
this._placeBeforeCursor({
|
|
746
|
+
type: "FunctionCall",
|
|
747
|
+
name: this._cursor.value,
|
|
748
|
+
args: [],
|
|
749
|
+
pool: "functions"
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Handles identifier tokens by adding them as a new node in the AST.
|
|
754
|
+
* @param {{type: <string>}} token A token object
|
|
755
|
+
*/
|
|
756
|
+
exports.identifier = function(token) {
|
|
757
|
+
var node = {
|
|
758
|
+
type: "Identifier",
|
|
759
|
+
value: token.value
|
|
760
|
+
};
|
|
761
|
+
if (this._nextIdentEncapsulate) {
|
|
762
|
+
node.from = this._cursor;
|
|
763
|
+
this._placeBeforeCursor(node);
|
|
764
|
+
this._nextIdentEncapsulate = false;
|
|
765
|
+
} else {
|
|
766
|
+
if (this._nextIdentRelative) {
|
|
767
|
+
node.relative = true;
|
|
768
|
+
this._nextIdentRelative = false;
|
|
769
|
+
}
|
|
770
|
+
this._placeAtCursor(node);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* Handles literal values, such as strings, booleans, and numerics, by adding
|
|
775
|
+
* them as a new node in the AST.
|
|
776
|
+
* @param {{type: <string>}} token A token object
|
|
777
|
+
*/
|
|
778
|
+
exports.literal = function(token) {
|
|
779
|
+
this._placeAtCursor({
|
|
780
|
+
type: "Literal",
|
|
781
|
+
value: token.value
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* Queues a new object literal key to be written once a value is collected.
|
|
786
|
+
* @param {{type: <string>}} token A token object
|
|
787
|
+
*/
|
|
788
|
+
exports.objKey = function(token) {
|
|
789
|
+
this._curObjKey = token.value;
|
|
790
|
+
};
|
|
791
|
+
/**
|
|
792
|
+
* Handles new object literals by adding them as a new node in the AST,
|
|
793
|
+
* initialized with an empty object.
|
|
794
|
+
*/
|
|
795
|
+
exports.objStart = function() {
|
|
796
|
+
this._placeAtCursor({
|
|
797
|
+
type: "ObjectLiteral",
|
|
798
|
+
value: {}
|
|
799
|
+
});
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* Handles an object value by adding its AST to the queued key on the object
|
|
803
|
+
* literal node currently at the cursor.
|
|
804
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
805
|
+
*/
|
|
806
|
+
exports.objVal = function(ast) {
|
|
807
|
+
this._cursor.value[this._curObjKey] = ast;
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Handles traditional subexpressions, delineated with the groupStart and
|
|
811
|
+
* groupEnd elements.
|
|
812
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
813
|
+
*/
|
|
814
|
+
exports.subExpression = function(ast) {
|
|
815
|
+
this._placeAtCursor(ast);
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* Handles a completed alternate subexpression of a ternary operator.
|
|
819
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
820
|
+
*/
|
|
821
|
+
exports.ternaryEnd = function(ast) {
|
|
822
|
+
this._cursor.alternate = ast;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Handles a completed consequent subexpression of a ternary operator.
|
|
826
|
+
* @param {{type: <string>}} ast The subexpression tree
|
|
827
|
+
*/
|
|
828
|
+
exports.ternaryMid = function(ast) {
|
|
829
|
+
this._cursor.consequent = ast;
|
|
830
|
+
};
|
|
831
|
+
/**
|
|
832
|
+
* Handles the start of a new ternary expression by encapsulating the entire
|
|
833
|
+
* AST in a ConditionalExpression node, and using the existing tree as the
|
|
834
|
+
* test element.
|
|
835
|
+
*/
|
|
836
|
+
exports.ternaryStart = function() {
|
|
837
|
+
this._tree = {
|
|
838
|
+
type: "ConditionalExpression",
|
|
839
|
+
test: this._tree
|
|
840
|
+
};
|
|
841
|
+
this._cursor = this._tree;
|
|
842
|
+
};
|
|
843
|
+
/**
|
|
844
|
+
* Handles identifier tokens when used to indicate the name of a transform to
|
|
845
|
+
* be applied.
|
|
846
|
+
* @param {{type: <string>}} token A token object
|
|
847
|
+
*/
|
|
848
|
+
exports.transform = function(token) {
|
|
849
|
+
this._placeBeforeCursor({
|
|
850
|
+
type: "FunctionCall",
|
|
851
|
+
name: token.value,
|
|
852
|
+
args: [this._cursor],
|
|
853
|
+
pool: "transforms"
|
|
854
|
+
});
|
|
855
|
+
};
|
|
856
|
+
/**
|
|
857
|
+
* Handles token of type 'unaryOp', indicating that the operation has only
|
|
858
|
+
* one input: a right side.
|
|
859
|
+
* @param {{type: <string>}} token A token object
|
|
860
|
+
*/
|
|
861
|
+
exports.unaryOp = function(token) {
|
|
862
|
+
this._placeAtCursor({
|
|
863
|
+
type: "UnaryExpression",
|
|
864
|
+
operator: token.value
|
|
865
|
+
});
|
|
866
|
+
};
|
|
867
|
+
}));
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region ../node_modules/jexl/dist/parser/states.js
|
|
870
|
+
var require_states = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
871
|
+
var h = require_handlers();
|
|
872
|
+
/**
|
|
873
|
+
* A mapping of all states in the finite state machine to a set of instructions
|
|
874
|
+
* for handling or transitioning into other states. Each state can be handled
|
|
875
|
+
* in one of two schemes: a tokenType map, or a subHandler.
|
|
876
|
+
*
|
|
877
|
+
* Standard expression elements are handled through the tokenType object. This
|
|
878
|
+
* is an object map of all legal token types to encounter in this state (and
|
|
879
|
+
* any unexpected token types will generate a thrown error) to an options
|
|
880
|
+
* object that defines how they're handled. The available options are:
|
|
881
|
+
*
|
|
882
|
+
* {string} toState: The name of the state to which to transition
|
|
883
|
+
* immediately after handling this token
|
|
884
|
+
* {string} handler: The handler function to call when this token type is
|
|
885
|
+
* encountered in this state. If omitted, the default handler
|
|
886
|
+
* matching the token's "type" property will be called. If the handler
|
|
887
|
+
* function does not exist, no call will be made and no error will be
|
|
888
|
+
* generated. This is useful for tokens whose sole purpose is to
|
|
889
|
+
* transition to other states.
|
|
890
|
+
*
|
|
891
|
+
* States that consume a subexpression should define a subHandler, the
|
|
892
|
+
* function to be called with an expression tree argument when the
|
|
893
|
+
* subexpression is complete. Completeness is determined through the
|
|
894
|
+
* endStates object, which maps tokens on which an expression should end to the
|
|
895
|
+
* state to which to transition once the subHandler function has been called.
|
|
896
|
+
*
|
|
897
|
+
* Additionally, any state in which it is legal to mark the AST as completed
|
|
898
|
+
* should have a 'completable' property set to boolean true. Attempting to
|
|
899
|
+
* call {@link Parser#complete} in any state without this property will result
|
|
900
|
+
* in a thrown Error.
|
|
901
|
+
*
|
|
902
|
+
* @type {{}}
|
|
903
|
+
*/
|
|
904
|
+
exports.states = {
|
|
905
|
+
expectOperand: { tokenTypes: {
|
|
906
|
+
literal: { toState: "expectBinOp" },
|
|
907
|
+
identifier: { toState: "identifier" },
|
|
908
|
+
unaryOp: {},
|
|
909
|
+
openParen: { toState: "subExpression" },
|
|
910
|
+
openCurl: {
|
|
911
|
+
toState: "expectObjKey",
|
|
912
|
+
handler: h.objStart
|
|
913
|
+
},
|
|
914
|
+
dot: { toState: "traverse" },
|
|
915
|
+
openBracket: {
|
|
916
|
+
toState: "arrayVal",
|
|
917
|
+
handler: h.arrayStart
|
|
918
|
+
}
|
|
919
|
+
} },
|
|
920
|
+
expectBinOp: {
|
|
921
|
+
tokenTypes: {
|
|
922
|
+
binaryOp: { toState: "expectOperand" },
|
|
923
|
+
pipe: { toState: "expectTransform" },
|
|
924
|
+
dot: { toState: "traverse" },
|
|
925
|
+
question: {
|
|
926
|
+
toState: "ternaryMid",
|
|
927
|
+
handler: h.ternaryStart
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
completable: true
|
|
931
|
+
},
|
|
932
|
+
expectTransform: { tokenTypes: { identifier: {
|
|
933
|
+
toState: "postTransform",
|
|
934
|
+
handler: h.transform
|
|
935
|
+
} } },
|
|
936
|
+
expectObjKey: { tokenTypes: {
|
|
937
|
+
identifier: {
|
|
938
|
+
toState: "expectKeyValSep",
|
|
939
|
+
handler: h.objKey
|
|
940
|
+
},
|
|
941
|
+
closeCurl: { toState: "expectBinOp" }
|
|
942
|
+
} },
|
|
943
|
+
expectKeyValSep: { tokenTypes: { colon: { toState: "objVal" } } },
|
|
944
|
+
postTransform: {
|
|
945
|
+
tokenTypes: {
|
|
946
|
+
openParen: { toState: "argVal" },
|
|
947
|
+
binaryOp: { toState: "expectOperand" },
|
|
948
|
+
dot: { toState: "traverse" },
|
|
949
|
+
openBracket: { toState: "filter" },
|
|
950
|
+
pipe: { toState: "expectTransform" }
|
|
951
|
+
},
|
|
952
|
+
completable: true
|
|
953
|
+
},
|
|
954
|
+
postArgs: {
|
|
955
|
+
tokenTypes: {
|
|
956
|
+
binaryOp: { toState: "expectOperand" },
|
|
957
|
+
dot: { toState: "traverse" },
|
|
958
|
+
openBracket: { toState: "filter" },
|
|
959
|
+
pipe: { toState: "expectTransform" }
|
|
960
|
+
},
|
|
961
|
+
completable: true
|
|
962
|
+
},
|
|
963
|
+
identifier: {
|
|
964
|
+
tokenTypes: {
|
|
965
|
+
binaryOp: { toState: "expectOperand" },
|
|
966
|
+
dot: { toState: "traverse" },
|
|
967
|
+
openBracket: { toState: "filter" },
|
|
968
|
+
openParen: {
|
|
969
|
+
toState: "argVal",
|
|
970
|
+
handler: h.functionCall
|
|
971
|
+
},
|
|
972
|
+
pipe: { toState: "expectTransform" },
|
|
973
|
+
question: {
|
|
974
|
+
toState: "ternaryMid",
|
|
975
|
+
handler: h.ternaryStart
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
completable: true
|
|
979
|
+
},
|
|
980
|
+
traverse: { tokenTypes: { identifier: { toState: "identifier" } } },
|
|
981
|
+
filter: {
|
|
982
|
+
subHandler: h.filter,
|
|
983
|
+
endStates: { closeBracket: "identifier" }
|
|
984
|
+
},
|
|
985
|
+
subExpression: {
|
|
986
|
+
subHandler: h.subExpression,
|
|
987
|
+
endStates: { closeParen: "expectBinOp" }
|
|
988
|
+
},
|
|
989
|
+
argVal: {
|
|
990
|
+
subHandler: h.argVal,
|
|
991
|
+
endStates: {
|
|
992
|
+
comma: "argVal",
|
|
993
|
+
closeParen: "postArgs"
|
|
994
|
+
}
|
|
995
|
+
},
|
|
996
|
+
objVal: {
|
|
997
|
+
subHandler: h.objVal,
|
|
998
|
+
endStates: {
|
|
999
|
+
comma: "expectObjKey",
|
|
1000
|
+
closeCurl: "expectBinOp"
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
arrayVal: {
|
|
1004
|
+
subHandler: h.arrayVal,
|
|
1005
|
+
endStates: {
|
|
1006
|
+
comma: "arrayVal",
|
|
1007
|
+
closeBracket: "expectBinOp"
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
ternaryMid: {
|
|
1011
|
+
subHandler: h.ternaryMid,
|
|
1012
|
+
endStates: { colon: "ternaryEnd" }
|
|
1013
|
+
},
|
|
1014
|
+
ternaryEnd: {
|
|
1015
|
+
subHandler: h.ternaryEnd,
|
|
1016
|
+
completable: true
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}));
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region ../node_modules/jexl/dist/parser/Parser.js
|
|
1022
|
+
var require_Parser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1023
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
1024
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
1025
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
1026
|
+
var handlers = require_handlers();
|
|
1027
|
+
var states = require_states().states;
|
|
1028
|
+
module.exports = /* @__PURE__ */ function() {
|
|
1029
|
+
function Parser(grammar, prefix, stopMap) {
|
|
1030
|
+
(0, _classCallCheck2.default)(this, Parser);
|
|
1031
|
+
this._grammar = grammar;
|
|
1032
|
+
this._state = "expectOperand";
|
|
1033
|
+
this._tree = null;
|
|
1034
|
+
this._exprStr = prefix || "";
|
|
1035
|
+
this._relative = false;
|
|
1036
|
+
this._stopMap = stopMap || {};
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Processes a new token into the AST and manages the transitions of the state
|
|
1040
|
+
* machine.
|
|
1041
|
+
* @param {{type: <string>}} token A token object, as provided by the
|
|
1042
|
+
* {@link Lexer#tokenize} function.
|
|
1043
|
+
* @throws {Error} if a token is added when the Parser has been marked as
|
|
1044
|
+
* complete by {@link #complete}, or if an unexpected token type is added.
|
|
1045
|
+
* @returns {boolean|*} the stopState value if this parser encountered a token
|
|
1046
|
+
* in the stopState mapb false if tokens can continue.
|
|
1047
|
+
*/
|
|
1048
|
+
(0, _createClass2.default)(Parser, [
|
|
1049
|
+
{
|
|
1050
|
+
key: "addToken",
|
|
1051
|
+
value: function addToken(token) {
|
|
1052
|
+
if (this._state === "complete") throw new Error("Cannot add a new token to a completed Parser");
|
|
1053
|
+
var state = states[this._state];
|
|
1054
|
+
var startExpr = this._exprStr;
|
|
1055
|
+
this._exprStr += token.raw;
|
|
1056
|
+
if (state.subHandler) {
|
|
1057
|
+
if (!this._subParser) this._startSubExpression(startExpr);
|
|
1058
|
+
var stopState = this._subParser.addToken(token);
|
|
1059
|
+
if (stopState) {
|
|
1060
|
+
this._endSubExpression();
|
|
1061
|
+
if (this._parentStop) return stopState;
|
|
1062
|
+
this._state = stopState;
|
|
1063
|
+
}
|
|
1064
|
+
} else if (state.tokenTypes[token.type]) {
|
|
1065
|
+
var typeOpts = state.tokenTypes[token.type];
|
|
1066
|
+
var handleFunc = handlers[token.type];
|
|
1067
|
+
if (typeOpts.handler) handleFunc = typeOpts.handler;
|
|
1068
|
+
if (handleFunc) handleFunc.call(this, token);
|
|
1069
|
+
if (typeOpts.toState) this._state = typeOpts.toState;
|
|
1070
|
+
} else if (this._stopMap[token.type]) return this._stopMap[token.type];
|
|
1071
|
+
else throw new Error("Token ".concat(token.raw, " (").concat(token.type, ") unexpected in expression: ").concat(this._exprStr));
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
key: "addTokens",
|
|
1077
|
+
value: function addTokens(tokens) {
|
|
1078
|
+
tokens.forEach(this.addToken, this);
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
{
|
|
1082
|
+
key: "complete",
|
|
1083
|
+
value: function complete() {
|
|
1084
|
+
if (this._cursor && !states[this._state].completable) throw new Error("Unexpected end of expression: ".concat(this._exprStr));
|
|
1085
|
+
if (this._subParser) this._endSubExpression();
|
|
1086
|
+
this._state = "complete";
|
|
1087
|
+
return this._cursor ? this._tree : null;
|
|
1088
|
+
}
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
key: "isRelative",
|
|
1092
|
+
value: function isRelative() {
|
|
1093
|
+
return this._relative;
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
key: "_endSubExpression",
|
|
1098
|
+
value: function _endSubExpression() {
|
|
1099
|
+
states[this._state].subHandler.call(this, this._subParser.complete());
|
|
1100
|
+
this._subParser = null;
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
key: "_placeAtCursor",
|
|
1105
|
+
value: function _placeAtCursor(node) {
|
|
1106
|
+
if (!this._cursor) this._tree = node;
|
|
1107
|
+
else {
|
|
1108
|
+
this._cursor.right = node;
|
|
1109
|
+
this._setParent(node, this._cursor);
|
|
1110
|
+
}
|
|
1111
|
+
this._cursor = node;
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
{
|
|
1115
|
+
key: "_placeBeforeCursor",
|
|
1116
|
+
value: function _placeBeforeCursor(node) {
|
|
1117
|
+
this._cursor = this._cursor._parent;
|
|
1118
|
+
this._placeAtCursor(node);
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
key: "_setParent",
|
|
1123
|
+
value: function _setParent(node, parent) {
|
|
1124
|
+
Object.defineProperty(node, "_parent", {
|
|
1125
|
+
value: parent,
|
|
1126
|
+
writable: true
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
key: "_startSubExpression",
|
|
1132
|
+
value: function _startSubExpression(exprStr) {
|
|
1133
|
+
var endStates = states[this._state].endStates;
|
|
1134
|
+
if (!endStates) {
|
|
1135
|
+
this._parentStop = true;
|
|
1136
|
+
endStates = this._stopMap;
|
|
1137
|
+
}
|
|
1138
|
+
this._subParser = new Parser(this._grammar, exprStr, endStates);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
]);
|
|
1142
|
+
return Parser;
|
|
1143
|
+
}();
|
|
1144
|
+
}));
|
|
1145
|
+
//#endregion
|
|
1146
|
+
//#region ../node_modules/jexl/dist/PromiseSync.js
|
|
1147
|
+
var require_PromiseSync = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1148
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
1149
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
1150
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
1151
|
+
var PromiseSync = /* @__PURE__ */ function() {
|
|
1152
|
+
function PromiseSync(fn) {
|
|
1153
|
+
(0, _classCallCheck2.default)(this, PromiseSync);
|
|
1154
|
+
fn(this._resolve.bind(this), this._reject.bind(this));
|
|
1155
|
+
}
|
|
1156
|
+
(0, _createClass2.default)(PromiseSync, [
|
|
1157
|
+
{
|
|
1158
|
+
key: "catch",
|
|
1159
|
+
value: function _catch(rejected) {
|
|
1160
|
+
if (this.error) try {
|
|
1161
|
+
this._resolve(rejected(this.error));
|
|
1162
|
+
} catch (e) {
|
|
1163
|
+
this._reject(e);
|
|
1164
|
+
}
|
|
1165
|
+
return this;
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
key: "then",
|
|
1170
|
+
value: function then(resolved, rejected) {
|
|
1171
|
+
if (!this.error) try {
|
|
1172
|
+
this._resolve(resolved(this.value));
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
this._reject(e);
|
|
1175
|
+
}
|
|
1176
|
+
if (rejected) this.catch(rejected);
|
|
1177
|
+
return this;
|
|
1178
|
+
}
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
key: "_reject",
|
|
1182
|
+
value: function _reject(error) {
|
|
1183
|
+
this.value = void 0;
|
|
1184
|
+
this.error = error;
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
key: "_resolve",
|
|
1189
|
+
value: function _resolve(val) {
|
|
1190
|
+
if (val instanceof PromiseSync) if (val.error) this._reject(val.error);
|
|
1191
|
+
else this._resolve(val.value);
|
|
1192
|
+
else {
|
|
1193
|
+
this.value = val;
|
|
1194
|
+
this.error = void 0;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
]);
|
|
1199
|
+
return PromiseSync;
|
|
1200
|
+
}();
|
|
1201
|
+
PromiseSync.all = function(vals) {
|
|
1202
|
+
return new PromiseSync(function(resolve) {
|
|
1203
|
+
resolve(vals.map(function(val) {
|
|
1204
|
+
while (val instanceof PromiseSync) {
|
|
1205
|
+
if (val.error) throw Error(val.error);
|
|
1206
|
+
val = val.value;
|
|
1207
|
+
}
|
|
1208
|
+
return val;
|
|
1209
|
+
}));
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1212
|
+
PromiseSync.resolve = function(val) {
|
|
1213
|
+
return new PromiseSync(function(resolve) {
|
|
1214
|
+
return resolve(val);
|
|
1215
|
+
});
|
|
1216
|
+
};
|
|
1217
|
+
PromiseSync.reject = function(error) {
|
|
1218
|
+
return new PromiseSync(function(resolve, reject) {
|
|
1219
|
+
return reject(error);
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
module.exports = PromiseSync;
|
|
1223
|
+
}));
|
|
1224
|
+
//#endregion
|
|
1225
|
+
//#region ../node_modules/jexl/dist/Expression.js
|
|
1226
|
+
var require_Expression = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1227
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
1228
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
1229
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
1230
|
+
var Evaluator = require_Evaluator();
|
|
1231
|
+
var Lexer = require_Lexer();
|
|
1232
|
+
var Parser = require_Parser();
|
|
1233
|
+
var PromiseSync = require_PromiseSync();
|
|
1234
|
+
module.exports = /* @__PURE__ */ function() {
|
|
1235
|
+
function Expression(grammar, exprStr) {
|
|
1236
|
+
(0, _classCallCheck2.default)(this, Expression);
|
|
1237
|
+
this._grammar = grammar;
|
|
1238
|
+
this._exprStr = exprStr;
|
|
1239
|
+
this._ast = null;
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Forces a compilation of the expression string that this Expression object
|
|
1243
|
+
* was constructed with. This function can be called multiple times; useful
|
|
1244
|
+
* if the language elements of the associated Jexl instance change.
|
|
1245
|
+
* @returns {Expression} this Expression instance, for convenience
|
|
1246
|
+
*/
|
|
1247
|
+
(0, _createClass2.default)(Expression, [
|
|
1248
|
+
{
|
|
1249
|
+
key: "compile",
|
|
1250
|
+
value: function compile() {
|
|
1251
|
+
var lexer = new Lexer(this._grammar);
|
|
1252
|
+
var parser = new Parser(this._grammar);
|
|
1253
|
+
var tokens = lexer.tokenize(this._exprStr);
|
|
1254
|
+
parser.addTokens(tokens);
|
|
1255
|
+
this._ast = parser.complete();
|
|
1256
|
+
return this;
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
key: "eval",
|
|
1261
|
+
value: function _eval() {
|
|
1262
|
+
var context = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1263
|
+
return this._eval(context, Promise);
|
|
1264
|
+
}
|
|
1265
|
+
},
|
|
1266
|
+
{
|
|
1267
|
+
key: "evalSync",
|
|
1268
|
+
value: function evalSync() {
|
|
1269
|
+
var context = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1270
|
+
var res = this._eval(context, PromiseSync);
|
|
1271
|
+
if (res.error) throw res.error;
|
|
1272
|
+
return res.value;
|
|
1273
|
+
}
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
key: "_eval",
|
|
1277
|
+
value: function _eval(context, promise) {
|
|
1278
|
+
var _this = this;
|
|
1279
|
+
return promise.resolve().then(function() {
|
|
1280
|
+
var ast = _this._getAst();
|
|
1281
|
+
return new Evaluator(_this._grammar, context, void 0, promise).eval(ast);
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
key: "_getAst",
|
|
1287
|
+
value: function _getAst() {
|
|
1288
|
+
if (!this._ast) this.compile();
|
|
1289
|
+
return this._ast;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
]);
|
|
1293
|
+
return Expression;
|
|
1294
|
+
}();
|
|
1295
|
+
}));
|
|
1296
|
+
//#endregion
|
|
1297
|
+
//#region ../node_modules/jexl/dist/grammar.js
|
|
1298
|
+
var require_grammar = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1299
|
+
exports.getGrammar = function() {
|
|
1300
|
+
return {
|
|
1301
|
+
/**
|
|
1302
|
+
* A map of all expression elements to their properties. Note that changes
|
|
1303
|
+
* here may require changes in the Lexer or Parser.
|
|
1304
|
+
* @type {{}}
|
|
1305
|
+
*/
|
|
1306
|
+
elements: {
|
|
1307
|
+
".": { type: "dot" },
|
|
1308
|
+
"[": { type: "openBracket" },
|
|
1309
|
+
"]": { type: "closeBracket" },
|
|
1310
|
+
"|": { type: "pipe" },
|
|
1311
|
+
"{": { type: "openCurl" },
|
|
1312
|
+
"}": { type: "closeCurl" },
|
|
1313
|
+
":": { type: "colon" },
|
|
1314
|
+
",": { type: "comma" },
|
|
1315
|
+
"(": { type: "openParen" },
|
|
1316
|
+
")": { type: "closeParen" },
|
|
1317
|
+
"?": { type: "question" },
|
|
1318
|
+
"+": {
|
|
1319
|
+
type: "binaryOp",
|
|
1320
|
+
precedence: 30,
|
|
1321
|
+
eval: function _eval(left, right) {
|
|
1322
|
+
return left + right;
|
|
1323
|
+
}
|
|
1324
|
+
},
|
|
1325
|
+
"-": {
|
|
1326
|
+
type: "binaryOp",
|
|
1327
|
+
precedence: 30,
|
|
1328
|
+
eval: function _eval(left, right) {
|
|
1329
|
+
return left - right;
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
"*": {
|
|
1333
|
+
type: "binaryOp",
|
|
1334
|
+
precedence: 40,
|
|
1335
|
+
eval: function _eval(left, right) {
|
|
1336
|
+
return left * right;
|
|
1337
|
+
}
|
|
1338
|
+
},
|
|
1339
|
+
"/": {
|
|
1340
|
+
type: "binaryOp",
|
|
1341
|
+
precedence: 40,
|
|
1342
|
+
eval: function _eval(left, right) {
|
|
1343
|
+
return left / right;
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
"//": {
|
|
1347
|
+
type: "binaryOp",
|
|
1348
|
+
precedence: 40,
|
|
1349
|
+
eval: function _eval(left, right) {
|
|
1350
|
+
return Math.floor(left / right);
|
|
1351
|
+
}
|
|
1352
|
+
},
|
|
1353
|
+
"%": {
|
|
1354
|
+
type: "binaryOp",
|
|
1355
|
+
precedence: 50,
|
|
1356
|
+
eval: function _eval(left, right) {
|
|
1357
|
+
return left % right;
|
|
1358
|
+
}
|
|
1359
|
+
},
|
|
1360
|
+
"^": {
|
|
1361
|
+
type: "binaryOp",
|
|
1362
|
+
precedence: 50,
|
|
1363
|
+
eval: function _eval(left, right) {
|
|
1364
|
+
return Math.pow(left, right);
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
"==": {
|
|
1368
|
+
type: "binaryOp",
|
|
1369
|
+
precedence: 20,
|
|
1370
|
+
eval: function _eval(left, right) {
|
|
1371
|
+
return left == right;
|
|
1372
|
+
}
|
|
1373
|
+
},
|
|
1374
|
+
"!=": {
|
|
1375
|
+
type: "binaryOp",
|
|
1376
|
+
precedence: 20,
|
|
1377
|
+
eval: function _eval(left, right) {
|
|
1378
|
+
return left != right;
|
|
1379
|
+
}
|
|
1380
|
+
},
|
|
1381
|
+
">": {
|
|
1382
|
+
type: "binaryOp",
|
|
1383
|
+
precedence: 20,
|
|
1384
|
+
eval: function _eval(left, right) {
|
|
1385
|
+
return left > right;
|
|
1386
|
+
}
|
|
1387
|
+
},
|
|
1388
|
+
">=": {
|
|
1389
|
+
type: "binaryOp",
|
|
1390
|
+
precedence: 20,
|
|
1391
|
+
eval: function _eval(left, right) {
|
|
1392
|
+
return left >= right;
|
|
1393
|
+
}
|
|
1394
|
+
},
|
|
1395
|
+
"<": {
|
|
1396
|
+
type: "binaryOp",
|
|
1397
|
+
precedence: 20,
|
|
1398
|
+
eval: function _eval(left, right) {
|
|
1399
|
+
return left < right;
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
"<=": {
|
|
1403
|
+
type: "binaryOp",
|
|
1404
|
+
precedence: 20,
|
|
1405
|
+
eval: function _eval(left, right) {
|
|
1406
|
+
return left <= right;
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
"&&": {
|
|
1410
|
+
type: "binaryOp",
|
|
1411
|
+
precedence: 10,
|
|
1412
|
+
evalOnDemand: function evalOnDemand(left, right) {
|
|
1413
|
+
return left.eval().then(function(leftVal) {
|
|
1414
|
+
if (!leftVal) return leftVal;
|
|
1415
|
+
return right.eval();
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
},
|
|
1419
|
+
"||": {
|
|
1420
|
+
type: "binaryOp",
|
|
1421
|
+
precedence: 10,
|
|
1422
|
+
evalOnDemand: function evalOnDemand(left, right) {
|
|
1423
|
+
return left.eval().then(function(leftVal) {
|
|
1424
|
+
if (leftVal) return leftVal;
|
|
1425
|
+
return right.eval();
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1429
|
+
in: {
|
|
1430
|
+
type: "binaryOp",
|
|
1431
|
+
precedence: 20,
|
|
1432
|
+
eval: function _eval(left, right) {
|
|
1433
|
+
if (typeof right === "string") return right.indexOf(left) !== -1;
|
|
1434
|
+
if (Array.isArray(right)) return right.some(function(elem) {
|
|
1435
|
+
return elem === left;
|
|
1436
|
+
});
|
|
1437
|
+
return false;
|
|
1438
|
+
}
|
|
1439
|
+
},
|
|
1440
|
+
"!": {
|
|
1441
|
+
type: "unaryOp",
|
|
1442
|
+
precedence: Infinity,
|
|
1443
|
+
eval: function _eval(right) {
|
|
1444
|
+
return !right;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
/**
|
|
1449
|
+
* A map of function names to javascript functions. A Jexl function
|
|
1450
|
+
* takes zero ore more arguemnts:
|
|
1451
|
+
*
|
|
1452
|
+
* - {*} ...args: A variable number of arguments passed to this function.
|
|
1453
|
+
* All of these are pre-evaluated to their actual values before calling
|
|
1454
|
+
* the function.
|
|
1455
|
+
*
|
|
1456
|
+
* The Jexl function should return either the transformed value, or
|
|
1457
|
+
* a Promises/A+ Promise object that resolves with the value and rejects
|
|
1458
|
+
* or throws only when an unrecoverable error occurs. Functions should
|
|
1459
|
+
* generally return undefined when they don't make sense to be used on the
|
|
1460
|
+
* given value type, rather than throw/reject. An error is only
|
|
1461
|
+
* appropriate when the function would normally return a value, but
|
|
1462
|
+
* cannot due to some other failure.
|
|
1463
|
+
*/
|
|
1464
|
+
functions: {},
|
|
1465
|
+
/**
|
|
1466
|
+
* A map of transform names to transform functions. A transform function
|
|
1467
|
+
* takes one ore more arguemnts:
|
|
1468
|
+
*
|
|
1469
|
+
* - {*} val: A value to be transformed
|
|
1470
|
+
* - {*} ...args: A variable number of arguments passed to this transform.
|
|
1471
|
+
* All of these are pre-evaluated to their actual values before calling
|
|
1472
|
+
* the function.
|
|
1473
|
+
*
|
|
1474
|
+
* The transform function should return either the transformed value, or
|
|
1475
|
+
* a Promises/A+ Promise object that resolves with the value and rejects
|
|
1476
|
+
* or throws only when an unrecoverable error occurs. Transforms should
|
|
1477
|
+
* generally return undefined when they don't make sense to be used on the
|
|
1478
|
+
* given value type, rather than throw/reject. An error is only
|
|
1479
|
+
* appropriate when the transform would normally return a value, but
|
|
1480
|
+
* cannot due to some other failure.
|
|
1481
|
+
*/
|
|
1482
|
+
transforms: {}
|
|
1483
|
+
};
|
|
1484
|
+
};
|
|
1485
|
+
}));
|
|
1486
|
+
//#endregion
|
|
1487
|
+
//#region src/schema.ts
|
|
1488
|
+
var import_Jexl = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1489
|
+
var _interopRequireDefault = require_interopRequireDefault();
|
|
1490
|
+
var _defineProperty2 = _interopRequireDefault(require_defineProperty());
|
|
1491
|
+
var _classCallCheck2 = _interopRequireDefault(require_classCallCheck());
|
|
1492
|
+
var _createClass2 = _interopRequireDefault(require_createClass());
|
|
1493
|
+
var Expression = require_Expression();
|
|
1494
|
+
var getGrammar = require_grammar().getGrammar;
|
|
1495
|
+
/**
|
|
1496
|
+
* Jexl is the Javascript Expression Language, capable of parsing and
|
|
1497
|
+
* evaluating basic to complex expression strings, combined with advanced
|
|
1498
|
+
* xpath-like drilldown into native Javascript objects.
|
|
1499
|
+
* @constructor
|
|
1500
|
+
*/
|
|
1501
|
+
var Jexl = /* @__PURE__ */ function() {
|
|
1502
|
+
function Jexl() {
|
|
1503
|
+
(0, _classCallCheck2.default)(this, Jexl);
|
|
1504
|
+
this.expr = this.expr.bind(this);
|
|
1505
|
+
this._grammar = getGrammar();
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Adds a binary operator to Jexl at the specified precedence. The higher the
|
|
1509
|
+
* precedence, the earlier the operator is applied in the order of operations.
|
|
1510
|
+
* For example, * has a higher precedence than +, because multiplication comes
|
|
1511
|
+
* before division.
|
|
1512
|
+
*
|
|
1513
|
+
* Please see grammar.js for a listing of all default operators and their
|
|
1514
|
+
* precedence values in order to choose the appropriate precedence for the
|
|
1515
|
+
* new operator.
|
|
1516
|
+
* @param {string} operator The operator string to be added
|
|
1517
|
+
* @param {number} precedence The operator's precedence
|
|
1518
|
+
* @param {function} fn A function to run to calculate the result. The function
|
|
1519
|
+
* will be called with two arguments: left and right, denoting the values
|
|
1520
|
+
* on either side of the operator. It should return either the resulting
|
|
1521
|
+
* value, or a Promise that resolves with the resulting value.
|
|
1522
|
+
* @param {boolean} [manualEval] If true, the `left` and `right` arguments
|
|
1523
|
+
* will be wrapped in objects with an `eval` function. Calling
|
|
1524
|
+
* left.eval() or right.eval() will return a promise that resolves to
|
|
1525
|
+
* that operand's actual value. This is useful to conditionally evaluate
|
|
1526
|
+
* operands.
|
|
1527
|
+
*/
|
|
1528
|
+
(0, _createClass2.default)(Jexl, [
|
|
1529
|
+
{
|
|
1530
|
+
key: "addBinaryOp",
|
|
1531
|
+
value: function addBinaryOp(operator, precedence, fn, manualEval) {
|
|
1532
|
+
this._addGrammarElement(operator, (0, _defineProperty2.default)({
|
|
1533
|
+
type: "binaryOp",
|
|
1534
|
+
precedence
|
|
1535
|
+
}, manualEval ? "evalOnDemand" : "eval", fn));
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
{
|
|
1539
|
+
key: "addFunction",
|
|
1540
|
+
value: function addFunction(name, fn) {
|
|
1541
|
+
this._grammar.functions[name] = fn;
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
key: "addFunctions",
|
|
1546
|
+
value: function addFunctions(map) {
|
|
1547
|
+
for (var key in map) this._grammar.functions[key] = map[key];
|
|
1548
|
+
}
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
key: "addUnaryOp",
|
|
1552
|
+
value: function addUnaryOp(operator, fn) {
|
|
1553
|
+
this._addGrammarElement(operator, {
|
|
1554
|
+
type: "unaryOp",
|
|
1555
|
+
weight: Infinity,
|
|
1556
|
+
eval: fn
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
key: "addTransform",
|
|
1562
|
+
value: function addTransform(name, fn) {
|
|
1563
|
+
this._grammar.transforms[name] = fn;
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
key: "addTransforms",
|
|
1568
|
+
value: function addTransforms(map) {
|
|
1569
|
+
for (var key in map) this._grammar.transforms[key] = map[key];
|
|
1570
|
+
}
|
|
1571
|
+
},
|
|
1572
|
+
{
|
|
1573
|
+
key: "compile",
|
|
1574
|
+
value: function compile(expression) {
|
|
1575
|
+
return this.createExpression(expression).compile();
|
|
1576
|
+
}
|
|
1577
|
+
},
|
|
1578
|
+
{
|
|
1579
|
+
key: "createExpression",
|
|
1580
|
+
value: function createExpression(expression) {
|
|
1581
|
+
return new Expression(this._grammar, expression);
|
|
1582
|
+
}
|
|
1583
|
+
},
|
|
1584
|
+
{
|
|
1585
|
+
key: "getFunction",
|
|
1586
|
+
value: function getFunction(name) {
|
|
1587
|
+
return this._grammar.functions[name];
|
|
1588
|
+
}
|
|
1589
|
+
},
|
|
1590
|
+
{
|
|
1591
|
+
key: "getTransform",
|
|
1592
|
+
value: function getTransform(name) {
|
|
1593
|
+
return this._grammar.transforms[name];
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
key: "eval",
|
|
1598
|
+
value: function _eval(expression) {
|
|
1599
|
+
var context = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1600
|
+
return this.createExpression(expression).eval(context);
|
|
1601
|
+
}
|
|
1602
|
+
},
|
|
1603
|
+
{
|
|
1604
|
+
key: "evalSync",
|
|
1605
|
+
value: function evalSync(expression) {
|
|
1606
|
+
var context = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1607
|
+
return this.createExpression(expression).evalSync(context);
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
key: "expr",
|
|
1612
|
+
value: function expr(strs) {
|
|
1613
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) args[_key - 1] = arguments[_key];
|
|
1614
|
+
var exprStr = strs.reduce(function(acc, str, idx) {
|
|
1615
|
+
var arg = idx < args.length ? args[idx] : "";
|
|
1616
|
+
acc += str + arg;
|
|
1617
|
+
return acc;
|
|
1618
|
+
}, "");
|
|
1619
|
+
return this.createExpression(exprStr);
|
|
1620
|
+
}
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
key: "removeOp",
|
|
1624
|
+
value: function removeOp(operator) {
|
|
1625
|
+
if (this._grammar.elements[operator] && (this._grammar.elements[operator].type === "binaryOp" || this._grammar.elements[operator].type === "unaryOp")) delete this._grammar.elements[operator];
|
|
1626
|
+
}
|
|
1627
|
+
},
|
|
1628
|
+
{
|
|
1629
|
+
key: "_addGrammarElement",
|
|
1630
|
+
value: function _addGrammarElement(str, obj) {
|
|
1631
|
+
this._grammar.elements[str] = obj;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
]);
|
|
1635
|
+
return Jexl;
|
|
1636
|
+
}();
|
|
1637
|
+
module.exports = new Jexl();
|
|
1638
|
+
module.exports.Jexl = Jexl;
|
|
1639
|
+
})))(), 1);
|
|
1640
|
+
var Jexl = "default" in import_Jexl ? import_Jexl.default : import_Jexl;
|
|
1641
|
+
var warnedConditions = /* @__PURE__ */ new Set();
|
|
1642
|
+
var evaluateCondition = (condition, data) => {
|
|
1643
|
+
if (!condition) return true;
|
|
1644
|
+
try {
|
|
1645
|
+
return Jexl.evalSync(condition, data);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
if (typeof condition === "string" && !warnedConditions.has(condition)) {
|
|
1648
|
+
warnedConditions.add(condition);
|
|
1649
|
+
console.warn("Condition evaluation error:", error, "Condition:", condition, "Data:", data);
|
|
1650
|
+
}
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
var traverseSchema = (node, visitor) => {
|
|
1655
|
+
if (Array.isArray(node)) node.forEach((child) => {
|
|
1656
|
+
return traverseSchema(child, visitor);
|
|
1657
|
+
});
|
|
1658
|
+
else if (node && typeof node === "object") {
|
|
1659
|
+
visitor(node);
|
|
1660
|
+
if (node.$field === "list") return;
|
|
1661
|
+
Object.values(node).forEach((value) => {
|
|
1662
|
+
if (value && (typeof value === "object" || Array.isArray(value))) traverseSchema(value, visitor);
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
var extractFields = (nodes) => {
|
|
1667
|
+
const fields = [];
|
|
1668
|
+
traverseSchema(nodes, (node) => {
|
|
1669
|
+
if (node.$field) fields.push(node);
|
|
1670
|
+
});
|
|
1671
|
+
return fields;
|
|
1672
|
+
};
|
|
1673
|
+
var extractFieldNames = (content) => {
|
|
1674
|
+
return extractFields(content).map((field) => {
|
|
1675
|
+
return field.name;
|
|
1676
|
+
}).filter((name) => {
|
|
1677
|
+
return typeof name === "string";
|
|
1678
|
+
});
|
|
1679
|
+
};
|
|
1680
|
+
var fieldNamesCache = /* @__PURE__ */ new WeakMap();
|
|
1681
|
+
var getSchemaFieldNames = (node) => {
|
|
1682
|
+
if (!node || typeof node !== "object" && !Array.isArray(node)) return [];
|
|
1683
|
+
const key = node;
|
|
1684
|
+
const cached = fieldNamesCache.get(key);
|
|
1685
|
+
if (cached) return cached;
|
|
1686
|
+
const fieldNames = extractFieldNames(node);
|
|
1687
|
+
fieldNamesCache.set(key, fieldNames);
|
|
1688
|
+
return fieldNames;
|
|
1689
|
+
};
|
|
1690
|
+
var hasErrorValue = (value) => {
|
|
1691
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
1692
|
+
if (!value) return false;
|
|
1693
|
+
if (typeof value === "object") {
|
|
1694
|
+
const entry = value;
|
|
1695
|
+
if (Array.isArray(entry.errors)) return entry.errors.length > 0;
|
|
1696
|
+
}
|
|
1697
|
+
return Boolean(value);
|
|
1698
|
+
};
|
|
1699
|
+
var createSchemaFieldIndex = (node) => {
|
|
1700
|
+
const fieldNames = getSchemaFieldNames(node);
|
|
1701
|
+
const fieldNameSet = new Set(fieldNames);
|
|
1702
|
+
return {
|
|
1703
|
+
fieldNames,
|
|
1704
|
+
hasField: (fieldName) => {
|
|
1705
|
+
return fieldNameSet.has(fieldName);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
};
|
|
1709
|
+
var hasSchemaErrors = (errors, node) => {
|
|
1710
|
+
if (!errors || !node) return false;
|
|
1711
|
+
return getSchemaFieldNames(node).some((fieldName) => {
|
|
1712
|
+
return hasErrorValue(errors[fieldName]);
|
|
1713
|
+
});
|
|
1714
|
+
};
|
|
1715
|
+
//#endregion
|
|
1716
|
+
//#region src/buildGroupedMessage.ts
|
|
1717
|
+
var buildGroupLabel = (parentLabel, childLabel) => {
|
|
1718
|
+
if (parentLabel && childLabel) return `${parentLabel}: ${childLabel}`;
|
|
1719
|
+
return parentLabel || childLabel || "";
|
|
1720
|
+
};
|
|
1721
|
+
var ATTRIBUTE_MESSAGE_PATTERN = /^(.+?) (cannot be blank\.|must be .+)$/;
|
|
1722
|
+
var buildGroupedMessage = (message, parentLabel, childLabel) => {
|
|
1723
|
+
const groupLabel = buildGroupLabel(parentLabel, childLabel);
|
|
1724
|
+
if (!groupLabel) return message;
|
|
1725
|
+
const match = String(message).match(ATTRIBUTE_MESSAGE_PATTERN);
|
|
1726
|
+
if (match) {
|
|
1727
|
+
const [, attribute, suffix] = match;
|
|
1728
|
+
return `${buildGroupLabel(parentLabel, (childLabel && attribute !== childLabel ? attribute : childLabel) || attribute)} ${suffix}`;
|
|
1729
|
+
}
|
|
1730
|
+
return `${groupLabel} ${message}`;
|
|
1731
|
+
};
|
|
1732
|
+
//#endregion
|
|
1733
|
+
//#region src/translate.ts
|
|
1734
|
+
var translationCategory = "plugin-handle";
|
|
1735
|
+
var translateFn;
|
|
1736
|
+
var setTranslationCategory = (category) => {
|
|
1737
|
+
translationCategory = category.trim() || "plugin-handle";
|
|
1738
|
+
};
|
|
1739
|
+
var setTranslateFunction = (fn) => {
|
|
1740
|
+
translateFn = fn;
|
|
1741
|
+
};
|
|
1742
|
+
var translate = (message, params) => {
|
|
1743
|
+
if (translateFn) return translateFn(translationCategory, message, params);
|
|
1744
|
+
if (typeof window !== "undefined") {
|
|
1745
|
+
const craft = window.Craft;
|
|
1746
|
+
if (craft?.t) return craft.t(translationCategory, message, params);
|
|
1747
|
+
}
|
|
1748
|
+
return message;
|
|
1749
|
+
};
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region src/rules/email.ts
|
|
1752
|
+
var emailRegex$1 = /(^$|^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$)/;
|
|
1753
|
+
var emailRule = (value, label) => {
|
|
1754
|
+
if (!emailRegex$1.test(String(value))) return translate("{attribute} must be a valid email address.", { attribute: label });
|
|
1755
|
+
return null;
|
|
1756
|
+
};
|
|
1757
|
+
//#endregion
|
|
1758
|
+
//#region src/rules/emailOrVariable.ts
|
|
1759
|
+
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$)/;
|
|
1760
|
+
var variableRegex = /({.*?})/;
|
|
1761
|
+
var emailOrVariableRule = (value, label) => {
|
|
1762
|
+
const text = String(value);
|
|
1763
|
+
if (!variableRegex.test(text) && !emailRegex.test(text)) return translate("{attribute} must be a valid email address or variable.", { attribute: label });
|
|
1764
|
+
return null;
|
|
1765
|
+
};
|
|
1766
|
+
//#endregion
|
|
1767
|
+
//#region src/rules/handle.ts
|
|
1768
|
+
var handleRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
1769
|
+
var handleRule = (value) => {
|
|
1770
|
+
const handle = String(value ?? "");
|
|
1771
|
+
if (!handleRegex.test(handle)) return translate("“{handle}” isn’t a valid handle.", { handle });
|
|
1772
|
+
return null;
|
|
1773
|
+
};
|
|
1774
|
+
//#endregion
|
|
1775
|
+
//#region src/rules/utils.ts
|
|
1776
|
+
var INVISIBLE_CHAR_PATTERN = /[\u200B\u200C\u200D\u2060\uFEFF]/g;
|
|
1777
|
+
var isRecord$2 = (value) => {
|
|
1778
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1779
|
+
};
|
|
1780
|
+
/** TipTap JSON nodes always carry a string `type` (paragraph, text, variableTag, …). */
|
|
1781
|
+
var isTipTapNode = (value) => {
|
|
1782
|
+
return isRecord$2(value) && typeof value.type === "string";
|
|
1783
|
+
};
|
|
1784
|
+
/**
|
|
1785
|
+
* True for TipTap document payloads: content arrays, `{ type: 'doc' }`, or JSON
|
|
1786
|
+
* strings of those. Avoids treating arbitrary object arrays (e.g. option rows) as docs.
|
|
1787
|
+
*/
|
|
1788
|
+
var isTipTapContent = (value) => {
|
|
1789
|
+
if (Array.isArray(value)) return value.length === 0 || value.every(isTipTapNode);
|
|
1790
|
+
if (isTipTapNode(value) && value.type === "doc") return true;
|
|
1791
|
+
return false;
|
|
1792
|
+
};
|
|
1793
|
+
var collectTipTapPlainText = (nodes) => {
|
|
1794
|
+
let text = "";
|
|
1795
|
+
const visit = (node) => {
|
|
1796
|
+
if (!isRecord$2(node)) return;
|
|
1797
|
+
if (node.type === "text" && typeof node.text === "string") {
|
|
1798
|
+
text += node.text.replace(INVISIBLE_CHAR_PATTERN, "");
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
if (node.type === "variableTag") {
|
|
1802
|
+
const attrs = isRecord$2(node.attrs) ? node.attrs : {};
|
|
1803
|
+
const label = typeof attrs.label === "string" ? attrs.label : "";
|
|
1804
|
+
const variableValue = typeof attrs.value === "string" ? attrs.value : "";
|
|
1805
|
+
text += (label || variableValue).replace(INVISIBLE_CHAR_PATTERN, "");
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
if (Array.isArray(node.content)) node.content.forEach(visit);
|
|
1809
|
+
};
|
|
1810
|
+
nodes.forEach(visit);
|
|
1811
|
+
return text.trim();
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1814
|
+
* TipTap editors persist empty docs as JSON (`[]`, `[{type:'paragraph'}]`, …),
|
|
1815
|
+
* which must count as blank for `required` — not as a filled string/object.
|
|
1816
|
+
*/
|
|
1817
|
+
var isEmptyTipTapValue = (value) => {
|
|
1818
|
+
let parsed = value;
|
|
1819
|
+
if (typeof value === "string") {
|
|
1820
|
+
const trimmed = value.trim();
|
|
1821
|
+
if (!trimmed) return true;
|
|
1822
|
+
if (trimmed[0] !== "[" && trimmed[0] !== "{") return false;
|
|
1823
|
+
try {
|
|
1824
|
+
parsed = JSON.parse(trimmed);
|
|
1825
|
+
} catch {
|
|
1826
|
+
return false;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
if (!isTipTapContent(parsed)) return false;
|
|
1830
|
+
let nodes;
|
|
1831
|
+
if (Array.isArray(parsed)) nodes = parsed;
|
|
1832
|
+
else if (isRecord$2(parsed) && Array.isArray(parsed.content)) nodes = parsed.content;
|
|
1833
|
+
else nodes = [parsed];
|
|
1834
|
+
if (!nodes.length) return true;
|
|
1835
|
+
return collectTipTapPlainText(nodes).length === 0;
|
|
1836
|
+
};
|
|
1837
|
+
var isEmptyValue = (value) => {
|
|
1838
|
+
if (value === void 0 || value === null) return true;
|
|
1839
|
+
if (typeof value === "string") {
|
|
1840
|
+
if (value === "") return true;
|
|
1841
|
+
return isEmptyTipTapValue(value);
|
|
1842
|
+
}
|
|
1843
|
+
if (Array.isArray(value)) {
|
|
1844
|
+
if (value.length === 0) return true;
|
|
1845
|
+
return isEmptyTipTapValue(value);
|
|
1846
|
+
}
|
|
1847
|
+
if (isTipTapContent(value)) return isEmptyTipTapValue(value);
|
|
1848
|
+
return false;
|
|
1849
|
+
};
|
|
1850
|
+
var getValueSize = (value) => {
|
|
1851
|
+
if (typeof value === "number") return value;
|
|
1852
|
+
if (typeof value === "string") {
|
|
1853
|
+
const trimmed = value.trim();
|
|
1854
|
+
if (trimmed !== "" && Number.isFinite(Number(trimmed))) return Number(trimmed);
|
|
1855
|
+
return value.length;
|
|
1856
|
+
}
|
|
1857
|
+
if (Array.isArray(value)) return value.length;
|
|
1858
|
+
return NaN;
|
|
1859
|
+
};
|
|
1860
|
+
//#endregion
|
|
1861
|
+
//#region src/rules/max.ts
|
|
1862
|
+
var maxRule = (value, label, args) => {
|
|
1863
|
+
const max = Number(args[0]);
|
|
1864
|
+
const size = getValueSize(value);
|
|
1865
|
+
if (!Number.isFinite(size) || size > max) return translate("{attribute} must be at most {max}.", {
|
|
1866
|
+
attribute: label,
|
|
1867
|
+
max: String(args[0])
|
|
1868
|
+
});
|
|
1869
|
+
return null;
|
|
1870
|
+
};
|
|
1871
|
+
//#endregion
|
|
1872
|
+
//#region src/rules/min.ts
|
|
1873
|
+
var minRule = (value, label, args) => {
|
|
1874
|
+
const min = Number(args[0]);
|
|
1875
|
+
const size = getValueSize(value);
|
|
1876
|
+
if (!Number.isFinite(size) || size < min) return translate("{attribute} must be at least {min}.", {
|
|
1877
|
+
attribute: label,
|
|
1878
|
+
min: String(args[0])
|
|
1879
|
+
});
|
|
1880
|
+
return null;
|
|
1881
|
+
};
|
|
1882
|
+
//#endregion
|
|
1883
|
+
//#region src/rules/required.ts
|
|
1884
|
+
var requiredRule = (value, label) => {
|
|
1885
|
+
if (isEmptyValue(value)) return translate("{attribute} cannot be blank.", { attribute: label });
|
|
1886
|
+
return null;
|
|
1887
|
+
};
|
|
1888
|
+
//#endregion
|
|
1889
|
+
//#region src/rules/requiredRichText.ts
|
|
1890
|
+
/**
|
|
1891
|
+
* Required check for TipTap/ProseMirror JSON fields (`validation: 'requiredRichText'`).
|
|
1892
|
+
* Empty docs are JSON (`[]` / bare paragraphs), not `''` — handled via `isEmptyValue`.
|
|
1893
|
+
*/
|
|
1894
|
+
var requiredRichTextRule = (value, label) => {
|
|
1895
|
+
if (isEmptyValue(value)) return translate("{attribute} cannot be blank.", { attribute: label });
|
|
1896
|
+
return null;
|
|
1897
|
+
};
|
|
1898
|
+
//#endregion
|
|
1899
|
+
//#region src/rules/requiredRules.ts
|
|
1900
|
+
var REQUIRED_RULE_NAMES = new Set(["required", "requiredRichText"]);
|
|
1901
|
+
var isRequiredRuleName = (ruleName) => {
|
|
1902
|
+
return REQUIRED_RULE_NAMES.has(ruleName);
|
|
1903
|
+
};
|
|
1904
|
+
//#endregion
|
|
1905
|
+
//#region src/rules/uniqueHandle.ts
|
|
1906
|
+
var isRecord$1 = (value) => {
|
|
1907
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1908
|
+
};
|
|
1909
|
+
var getHandleValue = (value) => {
|
|
1910
|
+
if (!isRecord$1(value)) return "";
|
|
1911
|
+
const settings = isRecord$1(value.settings) ? value.settings : {};
|
|
1912
|
+
return String(value.handle || settings.handle || "").trim();
|
|
1913
|
+
};
|
|
1914
|
+
var collectTopLevelFieldHandles = (values) => {
|
|
1915
|
+
const entries = [];
|
|
1916
|
+
(Array.isArray(values?.pages) ? values.pages : []).forEach((page, pageIndex) => {
|
|
1917
|
+
(Array.isArray(page?.rows) ? page.rows : []).forEach((row, rowIndex) => {
|
|
1918
|
+
(Array.isArray(row?.fields) ? row.fields : []).forEach((field, fieldIndex) => {
|
|
1919
|
+
const handle = getHandleValue(field);
|
|
1920
|
+
if (!handle) return;
|
|
1921
|
+
entries.push({
|
|
1922
|
+
path: `pages.${pageIndex}.rows.${rowIndex}.fields.${fieldIndex}.handle`,
|
|
1923
|
+
handle
|
|
1924
|
+
});
|
|
1925
|
+
});
|
|
1926
|
+
});
|
|
1927
|
+
});
|
|
1928
|
+
return entries;
|
|
1929
|
+
};
|
|
1930
|
+
var collectNestedFieldHandles = (values, parentFieldPath) => {
|
|
1931
|
+
const entries = [];
|
|
1932
|
+
const rows = get(values, `${parentFieldPath}.rows`, []);
|
|
1933
|
+
(Array.isArray(rows) ? rows : []).forEach((row, nestedRowIndex) => {
|
|
1934
|
+
(Array.isArray(row?.fields) ? row.fields : []).forEach((field, nestedFieldIndex) => {
|
|
1935
|
+
const handle = getHandleValue(field);
|
|
1936
|
+
if (!handle) return;
|
|
1937
|
+
entries.push({
|
|
1938
|
+
path: `${parentFieldPath}.rows.${nestedRowIndex}.fields.${nestedFieldIndex}.handle`,
|
|
1939
|
+
handle
|
|
1940
|
+
});
|
|
1941
|
+
});
|
|
1942
|
+
});
|
|
1943
|
+
return entries;
|
|
1944
|
+
};
|
|
1945
|
+
var collectNotificationHandles = (values) => {
|
|
1946
|
+
const entries = [];
|
|
1947
|
+
(Array.isArray(values?.notifications) ? values.notifications : []).forEach((notification, index) => {
|
|
1948
|
+
const handle = String(notification?.handle || "").trim();
|
|
1949
|
+
if (!handle) return;
|
|
1950
|
+
entries.push({
|
|
1951
|
+
path: `notifications.${index}.handle`,
|
|
1952
|
+
handle
|
|
1953
|
+
});
|
|
1954
|
+
});
|
|
1955
|
+
return entries;
|
|
1956
|
+
};
|
|
1957
|
+
var getScopedHandleEntries = (context) => {
|
|
1958
|
+
const { path, values } = context;
|
|
1959
|
+
const explicitScope = context?.field?.uniqueHandleScope;
|
|
1960
|
+
if (explicitScope === "topLevelFields") return collectTopLevelFieldHandles(values);
|
|
1961
|
+
if (explicitScope === "notifications") return collectNotificationHandles(values);
|
|
1962
|
+
if (explicitScope === "nestedSiblings") {
|
|
1963
|
+
const parentFieldPath = context?.field?.uniqueHandleScopePath;
|
|
1964
|
+
if (typeof parentFieldPath === "string" && parentFieldPath.trim() !== "") return collectNestedFieldHandles(values, parentFieldPath);
|
|
1965
|
+
}
|
|
1966
|
+
const nestedMatch = path.match(/^(pages\.\d+\.rows\.\d+\.fields\.\d+(?:\.rows\.\d+\.fields\.\d+)*)\.rows\.\d+\.fields\.\d+\.handle$/);
|
|
1967
|
+
if (nestedMatch) {
|
|
1968
|
+
const [, parentFieldPath] = nestedMatch;
|
|
1969
|
+
return collectNestedFieldHandles(values, parentFieldPath);
|
|
1970
|
+
}
|
|
1971
|
+
if (/^pages\.\d+\.rows\.\d+\.fields\.\d+\.handle$/.test(path)) return collectTopLevelFieldHandles(values);
|
|
1972
|
+
if (/^notifications\.\d+\.handle$/.test(path)) return collectNotificationHandles(values);
|
|
1973
|
+
return [];
|
|
1974
|
+
};
|
|
1975
|
+
var uniqueHandleRule = (value, label, args, context) => {
|
|
1976
|
+
if (!context?.path || !context?.values) return null;
|
|
1977
|
+
const handle = String(value ?? "").trim();
|
|
1978
|
+
if (!handle) return null;
|
|
1979
|
+
const entries = getScopedHandleEntries(context);
|
|
1980
|
+
const normalizedHandle = handle.toLowerCase();
|
|
1981
|
+
const scopedDuplicate = entries.some((entry) => {
|
|
1982
|
+
if (entry.path === context.path) return false;
|
|
1983
|
+
return entry.handle.toLowerCase() === normalizedHandle;
|
|
1984
|
+
});
|
|
1985
|
+
const reservedDuplicate = (Array.isArray(context.field?.reservedHandles) ? context.field.reservedHandles : []).some((reservedHandle) => {
|
|
1986
|
+
return String(reservedHandle || "").toLowerCase() === normalizedHandle;
|
|
1987
|
+
});
|
|
1988
|
+
if (!(scopedDuplicate || reservedDuplicate)) return null;
|
|
1989
|
+
return translate("{attribute} \"{value}\" has already been taken.", {
|
|
1990
|
+
attribute: label,
|
|
1991
|
+
value: handle
|
|
1992
|
+
});
|
|
1993
|
+
};
|
|
1994
|
+
//#endregion
|
|
1995
|
+
//#region src/rules/index.ts
|
|
1996
|
+
var ruleHandlers = {
|
|
1997
|
+
required: (value, label) => {
|
|
1998
|
+
return requiredRule(value, label);
|
|
1999
|
+
},
|
|
2000
|
+
requiredRichText: (value, label) => {
|
|
2001
|
+
return requiredRichTextRule(value, label);
|
|
2002
|
+
},
|
|
2003
|
+
min: (value, label, args) => {
|
|
2004
|
+
return minRule(value, label, args);
|
|
2005
|
+
},
|
|
2006
|
+
max: (value, label, args) => {
|
|
2007
|
+
return maxRule(value, label, args);
|
|
2008
|
+
},
|
|
2009
|
+
email: (value, label) => {
|
|
2010
|
+
return emailRule(value, label);
|
|
2011
|
+
},
|
|
2012
|
+
emailOrVariable: (value, label) => {
|
|
2013
|
+
return emailOrVariableRule(value, label);
|
|
2014
|
+
},
|
|
2015
|
+
handle: (value) => {
|
|
2016
|
+
return handleRule(value);
|
|
2017
|
+
},
|
|
2018
|
+
uniqueHandle: (value, label, args, context) => {
|
|
2019
|
+
return uniqueHandleRule(value, label, args, context);
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
//#endregion
|
|
2023
|
+
//#region src/ValidationEngine.ts
|
|
2024
|
+
var isRecord = (value) => {
|
|
2025
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2026
|
+
};
|
|
2027
|
+
var parseRules = (field) => {
|
|
2028
|
+
const tokens = (typeof field.validation === "string" ? field.validation : "").split("|").map((token) => {
|
|
2029
|
+
return token.trim();
|
|
2030
|
+
}).filter(Boolean);
|
|
2031
|
+
const hasRequiredRule = tokens.some((rule) => {
|
|
2032
|
+
const name = rule.split(":")[0];
|
|
2033
|
+
return isRequiredRuleName(name);
|
|
2034
|
+
});
|
|
2035
|
+
if (field.required && !hasRequiredRule) tokens.unshift("required");
|
|
2036
|
+
return tokens.map((token) => {
|
|
2037
|
+
const [name, ...rest] = token.split(":");
|
|
2038
|
+
return {
|
|
2039
|
+
name,
|
|
2040
|
+
args: rest.length > 0 ? rest.join(":").split(",") : []
|
|
2041
|
+
};
|
|
2042
|
+
});
|
|
2043
|
+
};
|
|
2044
|
+
var expandWildcardPaths = (values, path) => {
|
|
2045
|
+
if (!path.includes("*")) return [path];
|
|
2046
|
+
const parts = path.split(".");
|
|
2047
|
+
const results = [];
|
|
2048
|
+
const walk = (current, index, acc) => {
|
|
2049
|
+
if (index >= parts.length) {
|
|
2050
|
+
results.push(acc.join("."));
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
const part = parts[index];
|
|
2054
|
+
if (part === "*") {
|
|
2055
|
+
if (Array.isArray(current)) current.forEach((item, idx) => {
|
|
2056
|
+
walk(item, index + 1, [...acc, String(idx)]);
|
|
2057
|
+
});
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
if (isRecord(current) && part in current) {
|
|
2061
|
+
walk(current[part], index + 1, [...acc, part]);
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
walk(void 0, index + 1, [...acc, part]);
|
|
2065
|
+
};
|
|
2066
|
+
walk(values, 0, []);
|
|
2067
|
+
return results;
|
|
2068
|
+
};
|
|
2069
|
+
var validateValue = (field, rules, value, context) => {
|
|
2070
|
+
const label = String(field.label || field.name || "");
|
|
2071
|
+
const isRequired = rules.some((rule) => {
|
|
2072
|
+
return isRequiredRuleName(rule.name);
|
|
2073
|
+
});
|
|
2074
|
+
for (const rule of rules) {
|
|
2075
|
+
const { name, args } = rule;
|
|
2076
|
+
if (!isRequired && isEmptyValue(value)) continue;
|
|
2077
|
+
const handler = ruleHandlers[name];
|
|
2078
|
+
if (!handler) continue;
|
|
2079
|
+
const message = handler(value, label, args, context);
|
|
2080
|
+
if (message) return message;
|
|
2081
|
+
}
|
|
2082
|
+
return null;
|
|
2083
|
+
};
|
|
2084
|
+
var buildConditionData = (field, values, conditionDataResolver) => {
|
|
2085
|
+
const scopePath = typeof field?._scopePath === "string" ? field._scopePath : "";
|
|
2086
|
+
const scopedValues = scopePath ? get(values, scopePath) : null;
|
|
2087
|
+
const scopedObject = isRecord(scopedValues) ? scopedValues : {};
|
|
2088
|
+
const conditionContext = conditionDataResolver?.(values, field);
|
|
2089
|
+
const normalizedConditionContext = isRecord(conditionContext) ? conditionContext : {};
|
|
2090
|
+
const fieldData = isRecord(field._data) ? field._data : {};
|
|
2091
|
+
return {
|
|
2092
|
+
...values,
|
|
2093
|
+
...scopedObject,
|
|
2094
|
+
...fieldData,
|
|
2095
|
+
...normalizedConditionContext
|
|
2096
|
+
};
|
|
2097
|
+
};
|
|
2098
|
+
var shouldValidateField = (field, values, conditionDataResolver) => {
|
|
2099
|
+
const condition = field?.if;
|
|
2100
|
+
if (!condition) return true;
|
|
2101
|
+
try {
|
|
2102
|
+
return evaluateCondition(condition, buildConditionData(field, values, conditionDataResolver));
|
|
2103
|
+
} catch {
|
|
2104
|
+
return true;
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
var collectPathConditions = (schema) => {
|
|
2108
|
+
const pathConditions = /* @__PURE__ */ new Map();
|
|
2109
|
+
const walk = (node, currentPath = "", inherited = []) => {
|
|
2110
|
+
if (Array.isArray(node)) {
|
|
2111
|
+
node.forEach((child) => {
|
|
2112
|
+
walk(child, currentPath, inherited);
|
|
2113
|
+
});
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
if (!isRecord(node)) return;
|
|
2117
|
+
const name = typeof node.name === "string" && node.name ? node.name : "";
|
|
2118
|
+
let nodePath = currentPath;
|
|
2119
|
+
if (name) nodePath = currentPath ? `${currentPath}.${name}` : name;
|
|
2120
|
+
const ownCondition = typeof node.if === "string" && node.if ? [{
|
|
2121
|
+
condition: node.if,
|
|
2122
|
+
field: node
|
|
2123
|
+
}] : [];
|
|
2124
|
+
const nextInherited = [...inherited, ...ownCondition];
|
|
2125
|
+
if (nodePath && nextInherited.length) pathConditions.set(nodePath, nextInherited);
|
|
2126
|
+
if (Array.isArray(node.children)) walk(node.children, nodePath, nextInherited);
|
|
2127
|
+
if (Array.isArray(node.schema)) walk(node.schema, nodePath, nextInherited);
|
|
2128
|
+
};
|
|
2129
|
+
walk(schema, "", []);
|
|
2130
|
+
return pathConditions;
|
|
2131
|
+
};
|
|
2132
|
+
var shouldValidatePathConditions = (path, fallbackField, values, pathConditions, conditionDataResolver) => {
|
|
2133
|
+
const conditions = pathConditions.get(path) || [];
|
|
2134
|
+
if (!conditions.length) return true;
|
|
2135
|
+
return conditions.every(({ condition, field }) => {
|
|
2136
|
+
try {
|
|
2137
|
+
return evaluateCondition(condition, buildConditionData(field || fallbackField, values, conditionDataResolver));
|
|
2138
|
+
} catch {
|
|
2139
|
+
return true;
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
};
|
|
2143
|
+
var createValidationEngine = (index, options = {}) => {
|
|
2144
|
+
const { conditionDataResolver } = options;
|
|
2145
|
+
const fieldRules = /* @__PURE__ */ new Map();
|
|
2146
|
+
const pathConditions = collectPathConditions(index.schema);
|
|
2147
|
+
index.fieldEntries.forEach((entry) => {
|
|
2148
|
+
fieldRules.set(entry, parseRules(entry.field));
|
|
2149
|
+
});
|
|
2150
|
+
const validate = (values) => {
|
|
2151
|
+
const fieldErrors = {};
|
|
2152
|
+
index.fieldEntries.forEach((entry) => {
|
|
2153
|
+
const rules = fieldRules.get(entry) || [];
|
|
2154
|
+
if (!rules.length) return;
|
|
2155
|
+
if (!shouldValidateField(entry.field, values, conditionDataResolver)) return;
|
|
2156
|
+
expandWildcardPaths(values, entry.path).forEach((path) => {
|
|
2157
|
+
if (!shouldValidatePathConditions(path, entry.field, values, pathConditions, conditionDataResolver)) return;
|
|
2158
|
+
const value = get(values, path);
|
|
2159
|
+
const message = validateValue(entry.field, rules, value, {
|
|
2160
|
+
path,
|
|
2161
|
+
values,
|
|
2162
|
+
field: entry.field
|
|
2163
|
+
});
|
|
2164
|
+
if (message) fieldErrors[path] = [message];
|
|
2165
|
+
});
|
|
2166
|
+
});
|
|
2167
|
+
return Object.keys(fieldErrors).length > 0 ? { fields: fieldErrors } : void 0;
|
|
2168
|
+
};
|
|
2169
|
+
return { validate };
|
|
2170
|
+
};
|
|
2171
|
+
//#endregion
|
|
2172
|
+
export { FormStateStore, REQUIRED_RULE_NAMES, buildGroupedMessage, createSchemaFieldIndex, createValidationEngine, emailOrVariableRule, emailRule, evaluateCondition, extractFieldNames, extractFields, getSchemaFieldNames, handleRule, hasSchemaErrors, isRequiredRuleName, maxRule, minRule, normalizeSchema, requiredRichTextRule, requiredRule, ruleHandlers, setTranslateFunction, setTranslationCategory, translate, traverseSchema, uniqueHandleRule };
|
|
2173
|
+
|
|
2174
|
+
//# sourceMappingURL=index.js.map
|