@cocreate/utils 1.42.0 → 1.42.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ObjectId.js +54 -0
- package/dist/cjs/attributes.js +64 -0
- package/dist/cjs/checkValue.js +26 -0
- package/dist/cjs/clickedElement.js +48 -0
- package/dist/cjs/core.js +33 -0
- package/dist/cjs/createUpdate.js +188 -0
- package/dist/cjs/cssPath.js +60 -0
- package/dist/cjs/dataQuery.js +280 -0
- package/dist/cjs/dom.js +29 -0
- package/dist/cjs/domParser.js +44 -0
- package/dist/cjs/dotNotationToObject.js +103 -0
- package/dist/cjs/escapeHtml.js +25 -0
- package/dist/cjs/getRelativePath.js +39 -0
- package/dist/cjs/getValueFromObject.js +41 -0
- package/dist/cjs/index.js +112 -0
- package/dist/cjs/init-browser.js +4 -0
- package/dist/cjs/isValidDate.js +32 -0
- package/dist/cjs/objectToDotNotation.js +53 -0
- package/dist/cjs/objectToSearchParams.js +42 -0
- package/dist/cjs/operators copy.js +562 -0
- package/dist/cjs/operators.js +480 -0
- package/dist/cjs/parseTextToHtml.js +27 -0
- package/dist/cjs/queryElements.js +155 -0
- package/dist/cjs/safeParse.js +169 -0
- package/dist/cjs/uid.js +34 -0
- package/dist/esm/ObjectId.js +35 -0
- package/dist/esm/attributes.js +45 -0
- package/dist/esm/checkValue.js +7 -0
- package/dist/esm/clickedElement.js +29 -0
- package/dist/esm/core.js +14 -0
- package/dist/esm/createUpdate.js +185 -0
- package/dist/esm/cssPath.js +41 -0
- package/dist/esm/dataQuery.js +261 -0
- package/dist/esm/dom.js +10 -0
- package/dist/esm/domParser.js +25 -0
- package/dist/esm/dotNotationToObject.js +84 -0
- package/dist/esm/escapeHtml.js +6 -0
- package/dist/esm/getRelativePath.js +20 -0
- package/dist/esm/getValueFromObject.js +22 -0
- package/dist/esm/index.js +93 -0
- package/dist/esm/init-browser.js +4 -0
- package/dist/esm/isValidDate.js +13 -0
- package/dist/esm/objectToDotNotation.js +34 -0
- package/dist/esm/objectToSearchParams.js +23 -0
- package/dist/esm/operators copy.js +543 -0
- package/dist/esm/operators.js +461 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parseTextToHtml.js +8 -0
- package/dist/esm/queryElements.js +136 -0
- package/dist/esm/safeParse.js +150 -0
- package/dist/esm/uid.js +15 -0
- package/package.json +9 -111
- package/src/index.js +3 -3
- package/src/operators copy.js +687 -0
- package/src/operators.js +407 -526
- package/.github/FUNDING.yml +0 -3
- package/.github/workflows/automated.yml +0 -44
- package/.github/workflows/manual.yml +0 -44
- package/CHANGELOG.md +0 -2075
- package/CoCreate.config.js +0 -23
- package/demo/index.html +0 -23
- package/docs/index.html +0 -331
- package/prettier.config.js +0 -16
- package/release.config.js +0 -22
- package/webpack.config.js +0 -65
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var isValidDate_exports = {};
|
|
19
|
+
__export(isValidDate_exports, {
|
|
20
|
+
isValidDate: () => isValidDate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(isValidDate_exports);
|
|
23
|
+
function isValidDate(value) {
|
|
24
|
+
if (typeof value === "string" && value.length >= 20 && value.length <= 24) {
|
|
25
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?([-+]\d{2}:\d{2}|Z)?$/i.test(
|
|
26
|
+
value
|
|
27
|
+
)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var objectToDotNotation_exports = {};
|
|
19
|
+
__export(objectToDotNotation_exports, {
|
|
20
|
+
objectToDotNotation: () => objectToDotNotation
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(objectToDotNotation_exports);
|
|
23
|
+
function objectToDotNotation(input) {
|
|
24
|
+
const results = {};
|
|
25
|
+
function traverse(currentValue, path) {
|
|
26
|
+
if (typeof currentValue !== "object" || currentValue === null) {
|
|
27
|
+
if (path !== void 0 && path !== null && path !== "") {
|
|
28
|
+
results[path] = currentValue;
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(currentValue)) {
|
|
33
|
+
if (currentValue.length > 0) {
|
|
34
|
+
currentValue.forEach((item, index) => {
|
|
35
|
+
const nextPath = `${path}[${index}]`;
|
|
36
|
+
traverse(item, nextPath);
|
|
37
|
+
});
|
|
38
|
+
} else if (path) {
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
const keys = Object.keys(currentValue);
|
|
42
|
+
if (keys.length > 0) {
|
|
43
|
+
keys.forEach((key) => {
|
|
44
|
+
const nextPath = path ? `${path}.${key}` : key;
|
|
45
|
+
traverse(currentValue[key], nextPath);
|
|
46
|
+
});
|
|
47
|
+
} else if (path) {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
traverse(input, "");
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var objectToSearchParams_exports = {};
|
|
19
|
+
__export(objectToSearchParams_exports, {
|
|
20
|
+
objectToSearchParams: () => objectToSearchParams
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(objectToSearchParams_exports);
|
|
23
|
+
function objectToSearchParams(paramsObj) {
|
|
24
|
+
if (!paramsObj || typeof paramsObj !== "object" || Array.isArray(paramsObj)) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
const filteredObj = {};
|
|
28
|
+
for (const key in paramsObj) {
|
|
29
|
+
if (Object.hasOwn(paramsObj, key)) {
|
|
30
|
+
const value = paramsObj[key];
|
|
31
|
+
if (value !== null && value !== void 0) {
|
|
32
|
+
filteredObj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (Object.keys(filteredObj).length === 0) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const searchParams = new URLSearchParams(filteredObj);
|
|
40
|
+
const queryString = searchParams.toString();
|
|
41
|
+
return queryString ? `?${queryString}` : "";
|
|
42
|
+
}
|
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var operators_copy_exports = {};
|
|
19
|
+
__export(operators_copy_exports, {
|
|
20
|
+
customOperators: () => customOperators,
|
|
21
|
+
processOperators: () => processOperators,
|
|
22
|
+
processOperatorsAsync: () => processOperatorsAsync
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(operators_copy_exports);
|
|
25
|
+
var import_ObjectId = require("./ObjectId.js");
|
|
26
|
+
var import_uid = require("./uid.js");
|
|
27
|
+
var import_queryElements = require("./queryElements.js");
|
|
28
|
+
var import_getValueFromObject = require("./getValueFromObject.js");
|
|
29
|
+
const mathConstants = { PI: Math.PI, E: Math.E };
|
|
30
|
+
const mathFunctions = {
|
|
31
|
+
abs: Math.abs,
|
|
32
|
+
ceil: Math.ceil,
|
|
33
|
+
floor: Math.floor,
|
|
34
|
+
round: Math.round,
|
|
35
|
+
max: Math.max,
|
|
36
|
+
min: Math.min,
|
|
37
|
+
pow: Math.pow,
|
|
38
|
+
sqrt: Math.sqrt,
|
|
39
|
+
log: Math.log,
|
|
40
|
+
sin: Math.sin,
|
|
41
|
+
cos: Math.cos,
|
|
42
|
+
tan: Math.tan
|
|
43
|
+
};
|
|
44
|
+
class Ref {
|
|
45
|
+
constructor(obj, prop) {
|
|
46
|
+
this.obj = obj;
|
|
47
|
+
this.prop = prop;
|
|
48
|
+
}
|
|
49
|
+
get() {
|
|
50
|
+
return this.obj ? this.obj[this.prop] : void 0;
|
|
51
|
+
}
|
|
52
|
+
set(val) {
|
|
53
|
+
if (this.obj) this.obj[this.prop] = val;
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function unref(val) {
|
|
58
|
+
return val instanceof Ref ? val.get() : val;
|
|
59
|
+
}
|
|
60
|
+
function safeParse(expression, registry = /* @__PURE__ */ new Map()) {
|
|
61
|
+
if (typeof expression !== "string") return expression;
|
|
62
|
+
let currentExpr = expression.trim();
|
|
63
|
+
if (!currentExpr) return null;
|
|
64
|
+
const tokenizerRegex = /('[^']*'|"[^"]*"|\d+(?:\.\d+)?|>=|<=|===|!==|==|!=|&&|\|\||[a-zA-Z_][a-zA-Z0-9_\.]*|[\+\-\*\/\%\(\)\?\:\>\<\!\,\=])/g;
|
|
65
|
+
const tokens = currentExpr.match(tokenizerRegex) || [];
|
|
66
|
+
let pos = 0;
|
|
67
|
+
function peek() {
|
|
68
|
+
return tokens[pos];
|
|
69
|
+
}
|
|
70
|
+
function consume() {
|
|
71
|
+
return tokens[pos++];
|
|
72
|
+
}
|
|
73
|
+
function parse() {
|
|
74
|
+
return parseAssignment();
|
|
75
|
+
}
|
|
76
|
+
function parseAssignment() {
|
|
77
|
+
let left = parseTernary();
|
|
78
|
+
if (peek() === "=") {
|
|
79
|
+
consume();
|
|
80
|
+
let right = unref(parseAssignment());
|
|
81
|
+
if (left instanceof Ref) {
|
|
82
|
+
return left.set(right);
|
|
83
|
+
}
|
|
84
|
+
return right;
|
|
85
|
+
}
|
|
86
|
+
return left;
|
|
87
|
+
}
|
|
88
|
+
function parseTernary() {
|
|
89
|
+
let left = parseLogical();
|
|
90
|
+
if (peek() === "?") {
|
|
91
|
+
consume();
|
|
92
|
+
let trueExpr = parseTernary();
|
|
93
|
+
if (peek() === ":") {
|
|
94
|
+
consume();
|
|
95
|
+
let falseExpr = parseTernary();
|
|
96
|
+
return unref(left) ? unref(trueExpr) : unref(falseExpr);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return left;
|
|
100
|
+
}
|
|
101
|
+
function parseLogical() {
|
|
102
|
+
let left = parseComparison();
|
|
103
|
+
while (peek() === "&&" || peek() === "||") {
|
|
104
|
+
let op = consume();
|
|
105
|
+
let right = parseComparison();
|
|
106
|
+
if (op === "&&") left = unref(left) && unref(right);
|
|
107
|
+
if (op === "||") left = unref(left) || unref(right);
|
|
108
|
+
}
|
|
109
|
+
return left;
|
|
110
|
+
}
|
|
111
|
+
function parseComparison() {
|
|
112
|
+
let left = parseAdditive();
|
|
113
|
+
while ([">", "<", ">=", "<=", "===", "!==", "==", "!="].includes(peek())) {
|
|
114
|
+
let op = consume();
|
|
115
|
+
let right = parseAdditive();
|
|
116
|
+
let l = unref(left), r = unref(right);
|
|
117
|
+
if (op === ">") left = l > r;
|
|
118
|
+
if (op === "<") left = l < r;
|
|
119
|
+
if (op === ">=") left = l >= r;
|
|
120
|
+
if (op === "<=") left = l <= r;
|
|
121
|
+
if (op === "===") left = l === r;
|
|
122
|
+
if (op === "!==") left = l !== r;
|
|
123
|
+
if (op === "==") left = l == r;
|
|
124
|
+
if (op === "!=") left = l != r;
|
|
125
|
+
}
|
|
126
|
+
return left;
|
|
127
|
+
}
|
|
128
|
+
function parseAdditive() {
|
|
129
|
+
let left = parseMultiplicative();
|
|
130
|
+
while (["+", "-"].includes(peek())) {
|
|
131
|
+
let op = consume();
|
|
132
|
+
let right = parseMultiplicative();
|
|
133
|
+
if (op === "+") left = unref(left) + unref(right);
|
|
134
|
+
if (op === "-") left = unref(left) - unref(right);
|
|
135
|
+
}
|
|
136
|
+
return left;
|
|
137
|
+
}
|
|
138
|
+
function parseMultiplicative() {
|
|
139
|
+
let left = parsePrimary();
|
|
140
|
+
while (["*", "/", "%"].includes(peek())) {
|
|
141
|
+
let op = consume();
|
|
142
|
+
let right = parsePrimary();
|
|
143
|
+
if (op === "*") left = unref(left) * unref(right);
|
|
144
|
+
if (op === "/") left = unref(left) / unref(right);
|
|
145
|
+
if (op === "%") left = unref(left) % unref(right);
|
|
146
|
+
}
|
|
147
|
+
return left;
|
|
148
|
+
}
|
|
149
|
+
function parsePrimary() {
|
|
150
|
+
let token = consume();
|
|
151
|
+
if (!token) return void 0;
|
|
152
|
+
if (/^\d/.test(token)) return parseFloat(token);
|
|
153
|
+
if (token.startsWith("'") || token.startsWith('"')) {
|
|
154
|
+
return token.slice(1, -1);
|
|
155
|
+
}
|
|
156
|
+
if (token === "true") return true;
|
|
157
|
+
if (token === "false") return false;
|
|
158
|
+
if (token === "(") {
|
|
159
|
+
let expr = unref(parse());
|
|
160
|
+
if (peek() === ")") consume();
|
|
161
|
+
return expr;
|
|
162
|
+
}
|
|
163
|
+
if (token === "-") return -unref(parsePrimary());
|
|
164
|
+
if (token === "!") return !unref(parsePrimary());
|
|
165
|
+
if (mathConstants.hasOwnProperty(token)) return mathConstants[token];
|
|
166
|
+
if (peek() === "(" && mathFunctions.hasOwnProperty(token)) {
|
|
167
|
+
consume();
|
|
168
|
+
let args = [];
|
|
169
|
+
if (peek() !== ")") {
|
|
170
|
+
args.push(unref(parse()));
|
|
171
|
+
while (peek() === ",") {
|
|
172
|
+
consume();
|
|
173
|
+
args.push(unref(parse()));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (peek() === ")") consume();
|
|
177
|
+
return mathFunctions[token](...args);
|
|
178
|
+
}
|
|
179
|
+
let path = token.split(".");
|
|
180
|
+
let baseToken = path[0];
|
|
181
|
+
let val;
|
|
182
|
+
if (registry.has(baseToken)) {
|
|
183
|
+
val = registry.get(baseToken);
|
|
184
|
+
} else if (typeof window !== "undefined" && window[baseToken]) {
|
|
185
|
+
val = window[baseToken];
|
|
186
|
+
} else {
|
|
187
|
+
val = void 0;
|
|
188
|
+
}
|
|
189
|
+
if (path.length === 1) return val;
|
|
190
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
191
|
+
if (val !== null && val !== void 0) {
|
|
192
|
+
val = val[path[i]];
|
|
193
|
+
} else {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return new Ref(val, path[path.length - 1]);
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const result = parse();
|
|
201
|
+
return unref(result);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.warn(`safeParse error: ${error.message} (Expr: "${expression}")`, error);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const customOperators = new Map(
|
|
208
|
+
Object.entries({
|
|
209
|
+
$organization_id: () => localStorage.getItem("organization_id"),
|
|
210
|
+
$user_id: () => localStorage.getItem("user_id"),
|
|
211
|
+
$clientId: () => localStorage.getItem("clientId"),
|
|
212
|
+
$session_id: () => localStorage.getItem("session_id"),
|
|
213
|
+
$value: (element) => element.getValue() || "",
|
|
214
|
+
$innerWidth: () => window.innerWidth,
|
|
215
|
+
$innerHeight: () => window.innerHeight,
|
|
216
|
+
$href: () => window.location.href.replace(/\/$/, ""),
|
|
217
|
+
$origin: () => window.location.origin,
|
|
218
|
+
$protocol: () => window.location.protocol,
|
|
219
|
+
$hostname: () => window.location.hostname,
|
|
220
|
+
$host: () => window.location.host,
|
|
221
|
+
$port: () => window.location.port,
|
|
222
|
+
$pathname: () => window.location.pathname.replace(/\/$/, ""),
|
|
223
|
+
$hash: () => window.location.hash,
|
|
224
|
+
$subdomain: () => getSubdomain() || "",
|
|
225
|
+
$object_id: () => (0, import_ObjectId.ObjectId)().toString(),
|
|
226
|
+
"ObjectId()": () => (0, import_ObjectId.ObjectId)().toString(),
|
|
227
|
+
$query: (element, args) => (0, import_queryElements.queryElements)({ element, selector: args }),
|
|
228
|
+
// ✨ THE NEW AST PORTAL ✨
|
|
229
|
+
$eval: (element, args, context) => safeParse(args, context.registry),
|
|
230
|
+
$relativePath: () => {
|
|
231
|
+
let currentPath = window.location.pathname.replace(/\/[^\/]*$/, "");
|
|
232
|
+
let depth = currentPath.split("/").filter(Boolean).length;
|
|
233
|
+
return depth > 0 ? "../".repeat(depth) : "./";
|
|
234
|
+
},
|
|
235
|
+
$path: () => {
|
|
236
|
+
let path = window.location.pathname;
|
|
237
|
+
if (path.split("/").pop().includes(".")) {
|
|
238
|
+
path = path.replace(/\/[^\/]+$/, "/");
|
|
239
|
+
}
|
|
240
|
+
return path === "/" ? "" : path;
|
|
241
|
+
},
|
|
242
|
+
$param: (element, args) => args,
|
|
243
|
+
$getObjectValue: (element, args) => {
|
|
244
|
+
if (Array.isArray(args) && args.length >= 2) {
|
|
245
|
+
return (0, import_getValueFromObject.getValueFromObject)(args[0], args[1]);
|
|
246
|
+
}
|
|
247
|
+
return "";
|
|
248
|
+
},
|
|
249
|
+
$setValue: (element, args) => element.setValue(...args) || "",
|
|
250
|
+
$true: () => true,
|
|
251
|
+
$false: () => false,
|
|
252
|
+
$parse: (element, args) => {
|
|
253
|
+
let value = args || "";
|
|
254
|
+
try {
|
|
255
|
+
return JSON.parse(value);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
$numberFormat: (element, args) => {
|
|
261
|
+
let number = parseFloat(args[0]);
|
|
262
|
+
if (!Array.isArray(args)) args = [args];
|
|
263
|
+
const locale = args[0] || void 0;
|
|
264
|
+
const options = args[1] || {};
|
|
265
|
+
const numCandidate = args[2] !== void 0 ? args[2] : args[0];
|
|
266
|
+
number = parseFloat(numCandidate);
|
|
267
|
+
if (isNaN(number)) return String(numCandidate ?? "");
|
|
268
|
+
return new Intl.NumberFormat(locale, options).format(number);
|
|
269
|
+
},
|
|
270
|
+
$uid: (element, args) => (0, import_uid.uid)(args[0]) || ""
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
const isConstructor = (func, name) => {
|
|
274
|
+
try {
|
|
275
|
+
if (typeof func !== "function") return false;
|
|
276
|
+
if (/^\s*class\s+/.test(func.toString())) return true;
|
|
277
|
+
if (!func.prototype) return false;
|
|
278
|
+
const n = name || func.name;
|
|
279
|
+
if (n && /^[A-Z]/.test(n)) return true;
|
|
280
|
+
} catch (e) {
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
};
|
|
284
|
+
const findBareOperatorInPath = (path) => {
|
|
285
|
+
const trimmedPath = path.trim();
|
|
286
|
+
const match = trimmedPath.match(/^(\$[\w\-]+)/);
|
|
287
|
+
if (match) {
|
|
288
|
+
const key = match[1];
|
|
289
|
+
const remaining = trimmedPath.substring(key.length);
|
|
290
|
+
if (remaining.length === 0 || /^\s|\[|\./.test(remaining)) {
|
|
291
|
+
return key;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
};
|
|
296
|
+
const findInnermostFunctionCall = (expression) => {
|
|
297
|
+
let balance = 0;
|
|
298
|
+
let deepestStart = -1;
|
|
299
|
+
let deepestEnd = -1;
|
|
300
|
+
let deepestBalance = -1;
|
|
301
|
+
let inSingleQuote = false;
|
|
302
|
+
let inDoubleQuote = false;
|
|
303
|
+
for (let i = 0; i < expression.length; i++) {
|
|
304
|
+
const char = expression[i];
|
|
305
|
+
if (char === '"' && !inSingleQuote) {
|
|
306
|
+
inDoubleQuote = !inDoubleQuote;
|
|
307
|
+
continue;
|
|
308
|
+
} else if (char === "'" && !inDoubleQuote) {
|
|
309
|
+
inSingleQuote = !inDoubleQuote;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (inSingleQuote || inDoubleQuote) continue;
|
|
313
|
+
if (char === "(") {
|
|
314
|
+
balance++;
|
|
315
|
+
if (balance > deepestBalance) {
|
|
316
|
+
deepestBalance = balance;
|
|
317
|
+
deepestStart = i;
|
|
318
|
+
deepestEnd = -1;
|
|
319
|
+
}
|
|
320
|
+
} else if (char === ")") {
|
|
321
|
+
if (balance === deepestBalance) {
|
|
322
|
+
deepestEnd = i;
|
|
323
|
+
}
|
|
324
|
+
balance--;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (deepestStart === -1 || deepestEnd === -1 || deepestEnd <= deepestStart) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const rawArgs = expression.substring(deepestStart + 1, deepestEnd).trim();
|
|
331
|
+
let operatorStart = -1;
|
|
332
|
+
let nonWhitespaceFound = false;
|
|
333
|
+
for (let i = deepestStart - 1; i >= 0; i--) {
|
|
334
|
+
const char = expression[i];
|
|
335
|
+
if (!nonWhitespaceFound) {
|
|
336
|
+
if (/\s/.test(char)) continue;
|
|
337
|
+
nonWhitespaceFound = true;
|
|
338
|
+
}
|
|
339
|
+
let isOperatorChar = /[\w\-\$]/.test(char);
|
|
340
|
+
if (!isOperatorChar) {
|
|
341
|
+
operatorStart = i + 1;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
operatorStart = i;
|
|
345
|
+
}
|
|
346
|
+
if (operatorStart === -1) operatorStart = 0;
|
|
347
|
+
const operatorNameCandidate = expression.substring(operatorStart, deepestStart).trim();
|
|
348
|
+
if (/^\$[\w\-]+$/.test(operatorNameCandidate) || customOperators.has(operatorNameCandidate)) {
|
|
349
|
+
const fullMatch = expression.substring(operatorStart, deepestEnd + 1);
|
|
350
|
+
return { operator: operatorNameCandidate, args: rawArgs, fullMatch };
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
353
|
+
};
|
|
354
|
+
const findInnermostOperator = (expression) => {
|
|
355
|
+
function stripParentheses(str) {
|
|
356
|
+
let result = str;
|
|
357
|
+
if (result.startsWith("(")) result = result.substring(1);
|
|
358
|
+
if (result.endsWith(")")) result = result.substring(0, result.length - 1);
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
let args;
|
|
362
|
+
const functionCall = findInnermostFunctionCall(expression);
|
|
363
|
+
if (functionCall) {
|
|
364
|
+
args = stripParentheses(functionCall.args);
|
|
365
|
+
return {
|
|
366
|
+
operator: functionCall.operator,
|
|
367
|
+
args,
|
|
368
|
+
rawContent: functionCall.args,
|
|
369
|
+
fullMatch: functionCall.fullMatch
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const rawContent = expression.trim();
|
|
373
|
+
const innermostOperator = findBareOperatorInPath(rawContent);
|
|
374
|
+
if (innermostOperator) {
|
|
375
|
+
const operatorArgs = rawContent.substring(innermostOperator.length).trim();
|
|
376
|
+
args = stripParentheses(operatorArgs);
|
|
377
|
+
return { operator: innermostOperator, args, rawContent };
|
|
378
|
+
}
|
|
379
|
+
args = stripParentheses(rawContent);
|
|
380
|
+
return { operator: null, args, rawContent };
|
|
381
|
+
};
|
|
382
|
+
function processOperators(element, value, exclude = [], parent, params = [], objectRegistry = /* @__PURE__ */ new Map()) {
|
|
383
|
+
if (typeof value !== "string" || !value.includes("$") && !value.includes("ObjectId()")) {
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
let processedValue = value;
|
|
387
|
+
let hasPromise = false;
|
|
388
|
+
let unresolvedTokens = /* @__PURE__ */ new Map();
|
|
389
|
+
while (processedValue.includes("$") || processedValue.includes("ObjectId()")) {
|
|
390
|
+
const paramMatch = processedValue.match(/^\$\$PARAM_(\d+)\$\$/);
|
|
391
|
+
if (paramMatch && Array.isArray(params) && params.length > 0) {
|
|
392
|
+
const index = parseInt(paramMatch[1], 10);
|
|
393
|
+
if (index < params.length) {
|
|
394
|
+
const resolvedTokenValue = params[index];
|
|
395
|
+
processedValue = processedValue.replace(paramMatch[0], resolvedTokenValue);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const { operator, args, rawContent, fullMatch } = findInnermostOperator(processedValue);
|
|
400
|
+
if (!operator) break;
|
|
401
|
+
if (operator === "$param" && !args) break;
|
|
402
|
+
const textToReplace = fullMatch || rawContent;
|
|
403
|
+
if (exclude.includes(operator)) {
|
|
404
|
+
const token = `__UNRESOLVED_${unresolvedTokens.size}__`;
|
|
405
|
+
unresolvedTokens.set(token, textToReplace);
|
|
406
|
+
processedValue = processedValue.replace(textToReplace, token);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
let resolvedValue = resolveOperator(element, operator, args, parent, params, objectRegistry);
|
|
410
|
+
if (resolvedValue === void 0) {
|
|
411
|
+
const token = `__UNRESOLVED_${unresolvedTokens.size}__`;
|
|
412
|
+
unresolvedTokens.set(token, textToReplace);
|
|
413
|
+
processedValue = processedValue.replace(textToReplace, token);
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (resolvedValue instanceof Promise) {
|
|
417
|
+
const paramIndex = params.length;
|
|
418
|
+
params.push(resolvedValue);
|
|
419
|
+
processedValue = processedValue.replace(textToReplace, `$$PARAM_${paramIndex}$$`);
|
|
420
|
+
hasPromise = true;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
if (params.some((p) => p instanceof Promise)) {
|
|
424
|
+
hasPromise = true;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
let replacement = "";
|
|
428
|
+
if (operator === "$param") {
|
|
429
|
+
params.push(resolvedValue);
|
|
430
|
+
} else if (resolvedValue !== null && (typeof resolvedValue === "object" || typeof resolvedValue === "function")) {
|
|
431
|
+
const token = `__OBJ_${objectRegistry.size}__`;
|
|
432
|
+
objectRegistry.set(token, resolvedValue);
|
|
433
|
+
replacement = token;
|
|
434
|
+
} else {
|
|
435
|
+
replacement = resolvedValue ?? "";
|
|
436
|
+
}
|
|
437
|
+
if (processedValue === textToReplace) {
|
|
438
|
+
processedValue = replacement;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
processedValue = processedValue.replace(textToReplace, replacement);
|
|
442
|
+
if (!processedValue.includes("$") && !processedValue.includes("ObjectId()")) {
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
for (const [token, originalText] of unresolvedTokens.entries()) {
|
|
447
|
+
processedValue = processedValue.replace(token, originalText);
|
|
448
|
+
}
|
|
449
|
+
if (typeof processedValue === "string") {
|
|
450
|
+
const exactMatch = processedValue.match(/^__OBJ_(\d+)__$/);
|
|
451
|
+
if (exactMatch && objectRegistry.has(processedValue)) {
|
|
452
|
+
processedValue = objectRegistry.get(processedValue);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (hasPromise) {
|
|
456
|
+
return { value: processedValue, params, objectRegistry };
|
|
457
|
+
}
|
|
458
|
+
if (params.length) {
|
|
459
|
+
if (typeof processedValue === "string" && processedValue.trim() === "") {
|
|
460
|
+
return params;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return processedValue;
|
|
464
|
+
}
|
|
465
|
+
async function processOperatorsAsync(element, value, exclude = [], parent, params = [], objectRegistry = /* @__PURE__ */ new Map()) {
|
|
466
|
+
let result = processOperators(element, value, exclude, parent, params, objectRegistry);
|
|
467
|
+
while (typeof result === "object" && result.params) {
|
|
468
|
+
const resolvedParams = await Promise.all(result.params);
|
|
469
|
+
result = processOperators(
|
|
470
|
+
element,
|
|
471
|
+
result.value,
|
|
472
|
+
exclude,
|
|
473
|
+
parent,
|
|
474
|
+
resolvedParams,
|
|
475
|
+
result.objectRegistry || objectRegistry
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (result instanceof Promise) return await result;
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
function resolveOperator(element, operator, args, parent, params, objectRegistry) {
|
|
482
|
+
if (params.some((p) => p instanceof Promise)) return "";
|
|
483
|
+
if (args && typeof args === "string" && args.includes("$")) {
|
|
484
|
+
args = processOperators(element, args, [], operator, params, objectRegistry);
|
|
485
|
+
}
|
|
486
|
+
if (params.some((p) => p instanceof Promise)) return operator;
|
|
487
|
+
let targetElements = element ? [element] : [];
|
|
488
|
+
if (args && typeof args === "string" && !customOperators.has(operator)) {
|
|
489
|
+
targetElements = (0, import_queryElements.queryElements)({ element, selector: args });
|
|
490
|
+
if (!targetElements.length) return void 0;
|
|
491
|
+
}
|
|
492
|
+
let value = processValues(targetElements, operator, args, parent, objectRegistry);
|
|
493
|
+
if (value && typeof value === "string" && value.includes("$")) {
|
|
494
|
+
value = processOperators(element, value, [], parent, params, objectRegistry);
|
|
495
|
+
}
|
|
496
|
+
return value;
|
|
497
|
+
}
|
|
498
|
+
function processValues(elements, operator, args, parent, objectRegistry) {
|
|
499
|
+
let customOp = customOperators.get(operator);
|
|
500
|
+
let aggregatedString = "";
|
|
501
|
+
let hasValidProperty = false;
|
|
502
|
+
const context = { registry: objectRegistry, element: elements[0] };
|
|
503
|
+
if (customOp) hasValidProperty = true;
|
|
504
|
+
for (const el of elements) {
|
|
505
|
+
if (!el) continue;
|
|
506
|
+
let rawValue = customOp;
|
|
507
|
+
const propName = customOp ? null : operator.substring(1);
|
|
508
|
+
if (!customOp) {
|
|
509
|
+
if (propName in el) {
|
|
510
|
+
hasValidProperty = true;
|
|
511
|
+
rawValue = el[propName];
|
|
512
|
+
} else {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (typeof rawValue === "function") {
|
|
517
|
+
if (customOp) {
|
|
518
|
+
if (Array.isArray(args)) {
|
|
519
|
+
rawValue = rawValue(el, ...args, context);
|
|
520
|
+
} else {
|
|
521
|
+
rawValue = rawValue(el, args, context);
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
if (isConstructor(rawValue, propName)) {
|
|
525
|
+
if (Array.isArray(args)) {
|
|
526
|
+
rawValue = new rawValue(...args);
|
|
527
|
+
} else if (args !== void 0 && args !== "") {
|
|
528
|
+
rawValue = new rawValue(args);
|
|
529
|
+
} else {
|
|
530
|
+
rawValue = new rawValue();
|
|
531
|
+
}
|
|
532
|
+
} else {
|
|
533
|
+
if (Array.isArray(args)) {
|
|
534
|
+
rawValue = rawValue.apply(el, args);
|
|
535
|
+
} else if (args !== void 0 && args !== "") {
|
|
536
|
+
rawValue = rawValue.call(el, args);
|
|
537
|
+
} else {
|
|
538
|
+
rawValue = rawValue.call(el);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (parent === "$param") {
|
|
544
|
+
if (rawValue !== void 0 && rawValue !== null) return rawValue;
|
|
545
|
+
} else {
|
|
546
|
+
if (rawValue instanceof Promise || typeof rawValue === "object" && rawValue !== null || typeof rawValue === "function") {
|
|
547
|
+
return rawValue;
|
|
548
|
+
}
|
|
549
|
+
aggregatedString += String(rawValue ?? "");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!hasValidProperty) return void 0;
|
|
553
|
+
return aggregatedString;
|
|
554
|
+
}
|
|
555
|
+
function getSubdomain() {
|
|
556
|
+
const hostname = window.location.hostname;
|
|
557
|
+
const parts = hostname.split(".");
|
|
558
|
+
if (parts.length > 2 && isNaN(parseInt(parts[parts.length - 1]))) {
|
|
559
|
+
return parts.slice(0, parts.length - 2).join(".");
|
|
560
|
+
}
|
|
561
|
+
return null;
|
|
562
|
+
}
|