@commercelayer/app-elements 6.0.2 → 6.1.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/dist/{InputDateComponent-BvQk8yES.js → InputDateComponent-BZPoLLpr.js} +83 -83
- package/dist/RuleEngineComponent-DXSlt-Rv.js +1710 -0
- package/dist/{en-DZFYYpbl.js → en-zfMbz9a_.js} +50 -0
- package/dist/{it-B_kKLza9.js → it-6Nhey2x1.js} +50 -0
- package/dist/locales/en.d.ts +50 -0
- package/dist/{main-1tcoF6bR.js → main-CHMUH05z.js} +9958 -9540
- package/dist/main.js +164 -164
- package/dist/{parseISO-Di2ADkp1.js → parseISO-9qgqVQGb.js} +1 -1
- package/dist/style.css +1 -1
- package/dist/tailwind.global.css +4 -4
- package/dist/ui/forms/CodeEditor/CodeEditorComponent.d.ts +3 -2
- package/dist/ui/forms/InputSelect/GenericAsyncComponent.d.ts +3 -2
- package/dist/ui/forms/InputSelect/InputSelect.d.ts +7 -0
- package/dist/ui/forms/InputSelect/overrides.d.ts +3 -1
- package/dist/ui/forms/RuleEngine/InputResourcePath.d.ts +5 -0
- package/dist/ui/forms/RuleEngine/RuleEngineComponent.d.ts +7 -5
- package/dist/ui/forms/RuleEngine/RuleEngineContext.d.ts +11 -4
- package/dist/ui/forms/RuleEngine/utils.d.ts +9 -6
- package/dist/vendor.css +1 -1
- package/package.json +1 -1
- package/dist/RuleEngineComponent-C2H2NHg9.js +0 -1403
|
@@ -0,0 +1,1710 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as D, B as re, D as le, E as ie, I as oe, N as ce, O as ue, P as de, Z as S, b as me, d as pe, e as fe, f as he, g as ye, h as ge, i as be, j as xe, k as ve, l as M, n as je, o as _e, p as Te, q as Ne, r as we, s as $e, u as Ce, v as ke, w as Ee, x as Se, y as Ve, z as Re, A as Ie, C as Ae, F as Ze, G as De, H as Me, J as qe, K as Oe, L as Fe, M as Le, Q as ze, R as Pe, S as Ue, T as Je, U as We, V as Ke, W as Be, X as Ye, Y as Xe, _ as He, $ as Ge, a0 as Qe, a1 as et, a2 as tt, a3 as at, a4 as st, a5 as nt, a6 as rt, a7 as lt, a8 as it, a9 as q, aa as ot, ab as ct, ac as ut, ad as dt, ae as mt, af as pt, ag as ft, ah as ht, ai as yt, aj as gt, ak as bt, al as xt, am as vt, an as jt, ao as _t, ap as Tt, aq as Nt, ar as wt, as as $t, at as Ct, au as kt, av as Et, aw as St, ax as Vt, ay as Rt, az as It, aA as At, aB as Zt, aC as Dt, aD as Mt, aE as qt, aF as Ot, aG as Ft, aH as Lt, aI as zt, aJ as Pt, aK as Ut, aL as Jt, aM as Wt, aN as Kt, aO as Bt, aP as Yt, aQ as Xt, aR as Ht, aS as Gt, aT as e, aU as V, aV as Qt, aW as ea, aX as ta, aY as v, aZ as $, a_ as aa, a$ as R, b0 as g, b1 as A, b2 as w, b3 as x, b4 as N, b5 as sa, b6 as k, b7 as B, b8 as Y, b9 as X, ba as na, bb as ra, bc as H, bd as I, be as la, bf as ia, bg as oa } from "./main-CHMUH05z.js";
|
|
3
|
+
import O, { useReducer as ca, useCallback as C, useMemo as ua, createContext as da, useContext as ma, useRef as G, useState as f, useEffect as T } from "react";
|
|
4
|
+
import "react-hook-form";
|
|
5
|
+
import "wouter";
|
|
6
|
+
import { p as F } from "./parseISO-9qgqVQGb.js";
|
|
7
|
+
function L(t, a) {
|
|
8
|
+
const s = t.match(
|
|
9
|
+
/(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{0,7}))?(?:Z|(.)(\d{2}):?(\d{2})?)?/
|
|
10
|
+
);
|
|
11
|
+
return s ? D(
|
|
12
|
+
Date.UTC(
|
|
13
|
+
+s[1],
|
|
14
|
+
+s[2] - 1,
|
|
15
|
+
+s[3],
|
|
16
|
+
+s[4] - (+s[9] || 0) * (s[8] == "-" ? -1 : 1),
|
|
17
|
+
+s[5] - (+s[10] || 0) * (s[8] == "-" ? -1 : 1),
|
|
18
|
+
+s[6],
|
|
19
|
+
+((s[7] || "0") + "00").substring(0, 3)
|
|
20
|
+
),
|
|
21
|
+
a?.in
|
|
22
|
+
) : D(NaN, a?.in);
|
|
23
|
+
}
|
|
24
|
+
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
25
|
+
__proto__: null,
|
|
26
|
+
BRAND: re,
|
|
27
|
+
DIRTY: le,
|
|
28
|
+
EMPTY_PATH: ie,
|
|
29
|
+
INVALID: oe,
|
|
30
|
+
NEVER: ce,
|
|
31
|
+
OK: ue,
|
|
32
|
+
ParseStatus: de,
|
|
33
|
+
Schema: S,
|
|
34
|
+
ZodAny: me,
|
|
35
|
+
ZodArray: pe,
|
|
36
|
+
ZodBigInt: fe,
|
|
37
|
+
ZodBoolean: he,
|
|
38
|
+
ZodBranded: ye,
|
|
39
|
+
ZodCatch: ge,
|
|
40
|
+
ZodDate: be,
|
|
41
|
+
ZodDefault: xe,
|
|
42
|
+
ZodDiscriminatedUnion: ve,
|
|
43
|
+
ZodEffects: M,
|
|
44
|
+
ZodEnum: je,
|
|
45
|
+
ZodError: _e,
|
|
46
|
+
get ZodFirstPartyTypeKind() {
|
|
47
|
+
return Te;
|
|
48
|
+
},
|
|
49
|
+
ZodFunction: Ne,
|
|
50
|
+
ZodIntersection: we,
|
|
51
|
+
ZodIssueCode: $e,
|
|
52
|
+
ZodLazy: Ce,
|
|
53
|
+
ZodLiteral: ke,
|
|
54
|
+
ZodMap: Ee,
|
|
55
|
+
ZodNaN: Se,
|
|
56
|
+
ZodNativeEnum: Ve,
|
|
57
|
+
ZodNever: Re,
|
|
58
|
+
ZodNull: Ie,
|
|
59
|
+
ZodNullable: Ae,
|
|
60
|
+
ZodNumber: Ze,
|
|
61
|
+
ZodObject: De,
|
|
62
|
+
ZodOptional: Me,
|
|
63
|
+
ZodParsedType: qe,
|
|
64
|
+
ZodPipeline: Oe,
|
|
65
|
+
ZodPromise: Fe,
|
|
66
|
+
ZodReadonly: Le,
|
|
67
|
+
ZodRecord: ze,
|
|
68
|
+
ZodSchema: S,
|
|
69
|
+
ZodSet: Pe,
|
|
70
|
+
ZodString: Ue,
|
|
71
|
+
ZodSymbol: Je,
|
|
72
|
+
ZodTransformer: M,
|
|
73
|
+
ZodTuple: We,
|
|
74
|
+
ZodType: S,
|
|
75
|
+
ZodUndefined: Ke,
|
|
76
|
+
ZodUnion: Be,
|
|
77
|
+
ZodUnknown: Ye,
|
|
78
|
+
ZodVoid: Xe,
|
|
79
|
+
addIssueToContext: He,
|
|
80
|
+
any: Ge,
|
|
81
|
+
array: Qe,
|
|
82
|
+
bigint: et,
|
|
83
|
+
boolean: tt,
|
|
84
|
+
coerce: at,
|
|
85
|
+
custom: st,
|
|
86
|
+
date: nt,
|
|
87
|
+
datetimeRegex: rt,
|
|
88
|
+
defaultErrorMap: lt,
|
|
89
|
+
discriminatedUnion: it,
|
|
90
|
+
effect: q,
|
|
91
|
+
enum: ot,
|
|
92
|
+
function: ct,
|
|
93
|
+
getErrorMap: ut,
|
|
94
|
+
getParsedType: dt,
|
|
95
|
+
instanceof: mt,
|
|
96
|
+
intersection: pt,
|
|
97
|
+
isAborted: ft,
|
|
98
|
+
isAsync: ht,
|
|
99
|
+
isDirty: yt,
|
|
100
|
+
isValid: gt,
|
|
101
|
+
late: bt,
|
|
102
|
+
lazy: xt,
|
|
103
|
+
literal: vt,
|
|
104
|
+
makeIssue: jt,
|
|
105
|
+
map: _t,
|
|
106
|
+
nan: Tt,
|
|
107
|
+
nativeEnum: Nt,
|
|
108
|
+
never: wt,
|
|
109
|
+
null: $t,
|
|
110
|
+
nullable: Ct,
|
|
111
|
+
number: kt,
|
|
112
|
+
object: Et,
|
|
113
|
+
get objectUtil() {
|
|
114
|
+
return St;
|
|
115
|
+
},
|
|
116
|
+
oboolean: Vt,
|
|
117
|
+
onumber: Rt,
|
|
118
|
+
optional: It,
|
|
119
|
+
ostring: At,
|
|
120
|
+
pipeline: Zt,
|
|
121
|
+
preprocess: Dt,
|
|
122
|
+
promise: Mt,
|
|
123
|
+
quotelessJson: qt,
|
|
124
|
+
record: Ot,
|
|
125
|
+
set: Ft,
|
|
126
|
+
setErrorMap: Lt,
|
|
127
|
+
strictObject: zt,
|
|
128
|
+
string: Pt,
|
|
129
|
+
symbol: Ut,
|
|
130
|
+
transformer: q,
|
|
131
|
+
tuple: Jt,
|
|
132
|
+
undefined: Wt,
|
|
133
|
+
union: Kt,
|
|
134
|
+
unknown: Bt,
|
|
135
|
+
get util() {
|
|
136
|
+
return Yt;
|
|
137
|
+
},
|
|
138
|
+
void: Xt
|
|
139
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
140
|
+
function z(t, a, s) {
|
|
141
|
+
return t == null ? t : Ht(t, a, s);
|
|
142
|
+
}
|
|
143
|
+
function P(t, a) {
|
|
144
|
+
return t == null ? !0 : Gt(t, a);
|
|
145
|
+
}
|
|
146
|
+
const Q = da(
|
|
147
|
+
void 0
|
|
148
|
+
);
|
|
149
|
+
function pa(t, a) {
|
|
150
|
+
switch (a.type) {
|
|
151
|
+
case "SET_PATH": {
|
|
152
|
+
const s = { ...t.value };
|
|
153
|
+
if (a.value === null)
|
|
154
|
+
if (/\.\d+$/.test(a.path)) {
|
|
155
|
+
const l = a.path.replace(/\.\d+$/, ""), c = parseInt(a.path.match(/\d+$/)?.[0] ?? "0", 10), n = Qt(s, l);
|
|
156
|
+
Array.isArray(n) && (n.splice(c, 1), z(s, l, n), n.length === 0 && l.endsWith(".nested.conditions") && P(s, l.replace(/\.conditions$/, "")));
|
|
157
|
+
} else
|
|
158
|
+
P(s, a.path);
|
|
159
|
+
else
|
|
160
|
+
z(s, a.path, a.value);
|
|
161
|
+
return {
|
|
162
|
+
...t,
|
|
163
|
+
value: s
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
case "SET_SELECTED_RULE_INDEX":
|
|
167
|
+
return {
|
|
168
|
+
...t,
|
|
169
|
+
selectedRuleIndex: a.index
|
|
170
|
+
};
|
|
171
|
+
case "SET_VALUE":
|
|
172
|
+
return V(t.value, a.value) ? t : (a.value.rules?.length ?? 0) === 0 ? {
|
|
173
|
+
selectedRuleIndex: 0,
|
|
174
|
+
value: {
|
|
175
|
+
rules: [
|
|
176
|
+
{
|
|
177
|
+
name: "Rule name",
|
|
178
|
+
// @ts-expect-error Setting `null` is intentional for rendering an empty action
|
|
179
|
+
actions: [null],
|
|
180
|
+
// @ts-expect-error Setting `null` is intentional for rendering an empty condition
|
|
181
|
+
conditions: [null]
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
} : {
|
|
186
|
+
...t,
|
|
187
|
+
value: a.value
|
|
188
|
+
};
|
|
189
|
+
default:
|
|
190
|
+
return t;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function fa({
|
|
194
|
+
children: t,
|
|
195
|
+
initialValue: a
|
|
196
|
+
}) {
|
|
197
|
+
const [s, l] = ca(pa, {
|
|
198
|
+
value: a.value,
|
|
199
|
+
selectedRuleIndex: 0
|
|
200
|
+
}), c = C((u, i) => {
|
|
201
|
+
l({ type: "SET_PATH", path: u, value: i });
|
|
202
|
+
}, []), n = C((u) => {
|
|
203
|
+
l({ type: "SET_SELECTED_RULE_INDEX", index: u }), u < 0 && setTimeout(() => {
|
|
204
|
+
l({ type: "SET_SELECTED_RULE_INDEX", index: 0 });
|
|
205
|
+
}, 50);
|
|
206
|
+
}, []), r = C((u) => {
|
|
207
|
+
l({ type: "SET_VALUE", value: u });
|
|
208
|
+
}, []), o = ua(
|
|
209
|
+
() => ({
|
|
210
|
+
state: s,
|
|
211
|
+
setPath: c,
|
|
212
|
+
setSelectedRuleIndex: n,
|
|
213
|
+
setValue: r,
|
|
214
|
+
availableActionTypes: a.availableActionTypes,
|
|
215
|
+
schemaType: a.schemaType
|
|
216
|
+
}),
|
|
217
|
+
[
|
|
218
|
+
s,
|
|
219
|
+
c,
|
|
220
|
+
n,
|
|
221
|
+
r,
|
|
222
|
+
a.availableActionTypes,
|
|
223
|
+
a.schemaType
|
|
224
|
+
]
|
|
225
|
+
);
|
|
226
|
+
return /* @__PURE__ */ e.jsx(Q.Provider, { value: o, children: t });
|
|
227
|
+
}
|
|
228
|
+
function b() {
|
|
229
|
+
const t = ma(Q);
|
|
230
|
+
if (t === void 0)
|
|
231
|
+
throw new Error("useRuleEngine must be used within a RuleEngineProvider");
|
|
232
|
+
return t;
|
|
233
|
+
}
|
|
234
|
+
function ee({
|
|
235
|
+
value: t,
|
|
236
|
+
name: a,
|
|
237
|
+
preset: s
|
|
238
|
+
}) {
|
|
239
|
+
const { setPath: l, schemaType: c } = b(), { t: n } = ea(), r = G(null), o = c === "order-rules" ? "order" : c === "price-rules" ? "price" : void 0, u = ta(
|
|
240
|
+
(s === "condition" ? ha : s === "action" ? ya : []).filter(
|
|
241
|
+
(i) => o != null && i.startsWith(o)
|
|
242
|
+
).map((i) => ({
|
|
243
|
+
value: i,
|
|
244
|
+
label: n(`resource_paths.${i}`).replace(
|
|
245
|
+
"resource_paths.",
|
|
246
|
+
""
|
|
247
|
+
)
|
|
248
|
+
})),
|
|
249
|
+
"label"
|
|
250
|
+
);
|
|
251
|
+
return /* @__PURE__ */ e.jsx(
|
|
252
|
+
v,
|
|
253
|
+
{
|
|
254
|
+
ref: r,
|
|
255
|
+
name: a,
|
|
256
|
+
initialValues: u,
|
|
257
|
+
defaultValue: t != null ? u.find((i) => i.value === t) ?? {
|
|
258
|
+
value: t,
|
|
259
|
+
label: t
|
|
260
|
+
} : void 0,
|
|
261
|
+
asTextSearch: !0,
|
|
262
|
+
isCreatable: !0,
|
|
263
|
+
loadAsyncValues: async (i) => {
|
|
264
|
+
if (o == null)
|
|
265
|
+
return [];
|
|
266
|
+
const d = u.filter(
|
|
267
|
+
(p) => p.label.includes(i)
|
|
268
|
+
), m = (await aa([o], i)).filter((p) => p.value.startsWith(i)).map((p) => {
|
|
269
|
+
const _ = p.type === "relationship" || p.value.endsWith(".metadata") ? `${p.value}.` : p.value;
|
|
270
|
+
return {
|
|
271
|
+
value: _,
|
|
272
|
+
label: _
|
|
273
|
+
};
|
|
274
|
+
}), j = i.includes(".metadata") ? [{ label: i, value: i }] : [], h = [...d, ...m, ...j];
|
|
275
|
+
return console.log("results", h), h;
|
|
276
|
+
},
|
|
277
|
+
onSelect: async (i) => {
|
|
278
|
+
$(i) && (l(a, i.value), i.value.toString().endsWith(".") && r.current?.openMenu("first"));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
const ha = [
|
|
284
|
+
"order.billing_address.country_code",
|
|
285
|
+
"order.country_code",
|
|
286
|
+
"order.currency_code",
|
|
287
|
+
"order.customer_email",
|
|
288
|
+
"order.customer.email",
|
|
289
|
+
"order.customer.customer_group.id",
|
|
290
|
+
"order.customer.customer_group.name",
|
|
291
|
+
"order.customer.tags.id",
|
|
292
|
+
"order.customer.tags.name",
|
|
293
|
+
"order.line_items.item_type",
|
|
294
|
+
"order.line_items.line_item_options.sku_option.tags.name",
|
|
295
|
+
"order.line_items.options_amount_cents",
|
|
296
|
+
"order.line_items.quantity",
|
|
297
|
+
"order.line_items.reference",
|
|
298
|
+
"order.line_items.shipment.id",
|
|
299
|
+
"order.line_items.shipment.shipping_method.id",
|
|
300
|
+
"order.line_items.shipment.shipping_method.name",
|
|
301
|
+
"order.line_items.shipment.shipping_method.reference",
|
|
302
|
+
"order.line_items.sku_code",
|
|
303
|
+
"order.line_items.sku.code",
|
|
304
|
+
"order.line_items.sku.id",
|
|
305
|
+
"order.line_items.sku.inventory.quantity",
|
|
306
|
+
"order.line_items.sku.name",
|
|
307
|
+
"order.line_items.sku.shipping_category.id",
|
|
308
|
+
"order.line_items.sku.sku_lists.id",
|
|
309
|
+
"order.line_items.sku.sku_lists.name",
|
|
310
|
+
"order.line_items.sku.tags.name",
|
|
311
|
+
"order.line_items.unit_amount_cents",
|
|
312
|
+
"order.market.code",
|
|
313
|
+
"order.market.id",
|
|
314
|
+
"order.shipments_count",
|
|
315
|
+
"order.shipping_address.country_code",
|
|
316
|
+
"order.subtotal_amount_cents",
|
|
317
|
+
"order.tags.name",
|
|
318
|
+
"order.total_amount_cents",
|
|
319
|
+
"price.jwt_customer.email",
|
|
320
|
+
"price.jwt_customer.tags.name",
|
|
321
|
+
"price.sku.sku_list_items.sku_list.name",
|
|
322
|
+
"price.sku.code",
|
|
323
|
+
"price.sku.tags.name",
|
|
324
|
+
"price.processed_at",
|
|
325
|
+
"price.amount_cents"
|
|
326
|
+
], ya = [
|
|
327
|
+
"order.line_items.line_item_options",
|
|
328
|
+
"order.line_items.shipment",
|
|
329
|
+
"order.line_items.sku_code",
|
|
330
|
+
"order.line_items.sku.code",
|
|
331
|
+
"order.line_items.sku",
|
|
332
|
+
"order.line_items",
|
|
333
|
+
"order.subtotal_amount_cents",
|
|
334
|
+
"order.total_amount_cents",
|
|
335
|
+
"order",
|
|
336
|
+
"price"
|
|
337
|
+
];
|
|
338
|
+
function ga({
|
|
339
|
+
item: t,
|
|
340
|
+
pathPrefix: a
|
|
341
|
+
}) {
|
|
342
|
+
const { setPath: s } = b();
|
|
343
|
+
if (t == null)
|
|
344
|
+
return null;
|
|
345
|
+
switch (t.type) {
|
|
346
|
+
case "buy_x_pay_y":
|
|
347
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
|
|
348
|
+
/* @__PURE__ */ e.jsx(
|
|
349
|
+
g,
|
|
350
|
+
{
|
|
351
|
+
name: `${a}.value.x`,
|
|
352
|
+
type: "number",
|
|
353
|
+
suffix: "X",
|
|
354
|
+
defaultValue: t.value?.x,
|
|
355
|
+
onChange: (l) => {
|
|
356
|
+
s(
|
|
357
|
+
`${a}.value.x`,
|
|
358
|
+
parseInt(l.currentTarget.value, 10)
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
/* @__PURE__ */ e.jsx(
|
|
364
|
+
g,
|
|
365
|
+
{
|
|
366
|
+
name: `${a}.value.y`,
|
|
367
|
+
type: "number",
|
|
368
|
+
suffix: "Y",
|
|
369
|
+
defaultValue: t.value?.y,
|
|
370
|
+
onChange: (l) => {
|
|
371
|
+
s(
|
|
372
|
+
`${a}.value.y`,
|
|
373
|
+
parseInt(l.currentTarget.value, 10)
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
] });
|
|
379
|
+
case "every_x_discount_y":
|
|
380
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
|
|
381
|
+
/* @__PURE__ */ e.jsx(
|
|
382
|
+
g,
|
|
383
|
+
{
|
|
384
|
+
name: `${a}.value.x`,
|
|
385
|
+
type: "number",
|
|
386
|
+
suffix: "X",
|
|
387
|
+
defaultValue: t.value?.x,
|
|
388
|
+
onChange: (l) => {
|
|
389
|
+
s(
|
|
390
|
+
`${a}.value.x`,
|
|
391
|
+
parseInt(l.currentTarget.value, 10)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
),
|
|
396
|
+
/* @__PURE__ */ e.jsx(
|
|
397
|
+
g,
|
|
398
|
+
{
|
|
399
|
+
name: `${a}.value.y`,
|
|
400
|
+
type: "number",
|
|
401
|
+
suffix: "Y",
|
|
402
|
+
defaultValue: t.value?.y,
|
|
403
|
+
onChange: (l) => {
|
|
404
|
+
s(
|
|
405
|
+
`${a}.value.y`,
|
|
406
|
+
parseInt(l.currentTarget.value, 10)
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
] });
|
|
412
|
+
case "fixed_amount":
|
|
413
|
+
case "fixed_price":
|
|
414
|
+
return /* @__PURE__ */ e.jsx("div", { className: "w-36", children: /* @__PURE__ */ e.jsx(
|
|
415
|
+
g,
|
|
416
|
+
{
|
|
417
|
+
name: `${a}.value`,
|
|
418
|
+
type: "number",
|
|
419
|
+
defaultValue: t.value,
|
|
420
|
+
min: 0,
|
|
421
|
+
suffix: "cents",
|
|
422
|
+
onChange: (l) => {
|
|
423
|
+
s(
|
|
424
|
+
`${a}.value`,
|
|
425
|
+
parseInt(l.currentTarget.value, 10)
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
) });
|
|
430
|
+
case "percentage": {
|
|
431
|
+
const l = (t.value * 100).toFixed(2);
|
|
432
|
+
return /* @__PURE__ */ e.jsx("div", { className: "w-24", children: /* @__PURE__ */ e.jsx(
|
|
433
|
+
g,
|
|
434
|
+
{
|
|
435
|
+
name: `${a}.value`,
|
|
436
|
+
type: "number",
|
|
437
|
+
defaultValue: l.endsWith(".00") ? l.slice(0, -3) : l,
|
|
438
|
+
min: 0,
|
|
439
|
+
max: 100,
|
|
440
|
+
suffix: "%",
|
|
441
|
+
onChange: (c) => {
|
|
442
|
+
s(
|
|
443
|
+
`${a}.value`,
|
|
444
|
+
parseFloat(c.currentTarget.value) / 100
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
) });
|
|
449
|
+
}
|
|
450
|
+
default:
|
|
451
|
+
return R();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function ba({
|
|
455
|
+
item: t,
|
|
456
|
+
index: a,
|
|
457
|
+
onDelete: s
|
|
458
|
+
}) {
|
|
459
|
+
const {
|
|
460
|
+
setPath: l,
|
|
461
|
+
state: { selectedRuleIndex: c },
|
|
462
|
+
availableActionTypes: n
|
|
463
|
+
} = b(), r = {
|
|
464
|
+
percentage: "Percentage discount",
|
|
465
|
+
fixed_amount: "Fixed amount",
|
|
466
|
+
fixed_price: "Fixed price",
|
|
467
|
+
buy_x_pay_y: "Buy X, Pay Y",
|
|
468
|
+
every_x_discount_y: "Every X, Discount Y"
|
|
469
|
+
}, o = `rules.${c}.actions.${a}`;
|
|
470
|
+
return /* @__PURE__ */ e.jsx("div", { className: "mb-4 last:mb-0", children: /* @__PURE__ */ e.jsxs("div", { className: "bg-gray-50 rounded-md flex items-center", children: [
|
|
471
|
+
/* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between gap-2 grow p-2", children: [
|
|
472
|
+
/* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
|
|
473
|
+
v,
|
|
474
|
+
{
|
|
475
|
+
name: `${o}.type`,
|
|
476
|
+
defaultValue: t != null ? {
|
|
477
|
+
label: r[t.type],
|
|
478
|
+
value: t.type
|
|
479
|
+
} : void 0,
|
|
480
|
+
initialValues: n.map((u) => ({
|
|
481
|
+
value: u,
|
|
482
|
+
label: r[u]
|
|
483
|
+
})),
|
|
484
|
+
onSelect: (u) => {
|
|
485
|
+
$(u) && l(`${o}.type`, u.value);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
) }),
|
|
489
|
+
/* @__PURE__ */ e.jsx(ga, { item: t, pathPrefix: o }),
|
|
490
|
+
/* @__PURE__ */ e.jsx("div", { className: "text-black font-bold text-sm", children: "ON" }),
|
|
491
|
+
/* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
|
|
492
|
+
ee,
|
|
493
|
+
{
|
|
494
|
+
preset: "action",
|
|
495
|
+
value: t?.selector,
|
|
496
|
+
name: `${o}.selector`
|
|
497
|
+
}
|
|
498
|
+
) })
|
|
499
|
+
] }),
|
|
500
|
+
s != null && /* @__PURE__ */ e.jsx(
|
|
501
|
+
A,
|
|
502
|
+
{
|
|
503
|
+
className: "w-8 border-l border-gray-100 flex items-center justify-center self-stretch",
|
|
504
|
+
dropdownLabel: /* @__PURE__ */ e.jsx(
|
|
505
|
+
"button",
|
|
506
|
+
{
|
|
507
|
+
type: "button",
|
|
508
|
+
className: "flex items-center justify-center self-stretch grow",
|
|
509
|
+
children: /* @__PURE__ */ e.jsx(x, { name: "dotsThreeVertical", size: 16, weight: "bold" })
|
|
510
|
+
}
|
|
511
|
+
),
|
|
512
|
+
dropdownItems: /* @__PURE__ */ e.jsx(
|
|
513
|
+
w,
|
|
514
|
+
{
|
|
515
|
+
label: "Delete",
|
|
516
|
+
onClick: () => {
|
|
517
|
+
l(`${o}`, null), s();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
] }) });
|
|
524
|
+
}
|
|
525
|
+
function xa({
|
|
526
|
+
actions: t
|
|
527
|
+
}) {
|
|
528
|
+
const [a, s] = f(0), {
|
|
529
|
+
setPath: l,
|
|
530
|
+
state: { selectedRuleIndex: c }
|
|
531
|
+
} = b();
|
|
532
|
+
return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
533
|
+
/* @__PURE__ */ e.jsx("div", { children: t?.map((n, r, o) => /* @__PURE__ */ e.jsx(
|
|
534
|
+
ba,
|
|
535
|
+
{
|
|
536
|
+
item: n,
|
|
537
|
+
index: r,
|
|
538
|
+
onDelete: o.length > 1 ? () => {
|
|
539
|
+
s((u) => u + 1);
|
|
540
|
+
} : void 0
|
|
541
|
+
},
|
|
542
|
+
`${c}-${r}-${a}`
|
|
543
|
+
)) }),
|
|
544
|
+
/* @__PURE__ */ e.jsx("div", { className: "mt-6", children: /* @__PURE__ */ e.jsxs(
|
|
545
|
+
N,
|
|
546
|
+
{
|
|
547
|
+
size: "small",
|
|
548
|
+
variant: "secondary",
|
|
549
|
+
alignItems: "center",
|
|
550
|
+
onClick: () => {
|
|
551
|
+
l(
|
|
552
|
+
`rules.${c}.actions.${t?.length ?? 0}`,
|
|
553
|
+
void 0
|
|
554
|
+
);
|
|
555
|
+
},
|
|
556
|
+
children: [
|
|
557
|
+
/* @__PURE__ */ e.jsx(x, { name: "plusCircle" }),
|
|
558
|
+
" Add action"
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
) })
|
|
562
|
+
] });
|
|
563
|
+
}
|
|
564
|
+
function te(t) {
|
|
565
|
+
const [a, s] = f(void 0);
|
|
566
|
+
return T(() => {
|
|
567
|
+
t?.field != null && sa(t.field).then((l) => {
|
|
568
|
+
s(l);
|
|
569
|
+
}).catch((l) => {
|
|
570
|
+
console.error("Error fetching field info:", l);
|
|
571
|
+
});
|
|
572
|
+
}, [t?.field]), { infos: a };
|
|
573
|
+
}
|
|
574
|
+
function ae(t) {
|
|
575
|
+
if (typeof t == "string")
|
|
576
|
+
return k(L(t)) ? "datetime" : "string";
|
|
577
|
+
if (typeof t == "number")
|
|
578
|
+
return "integer";
|
|
579
|
+
if (typeof t == "boolean")
|
|
580
|
+
return "boolean";
|
|
581
|
+
if (Array.isArray(t)) {
|
|
582
|
+
if (typeof t[0] == "string")
|
|
583
|
+
return k(L(t[0])) ? "datetime" : "string";
|
|
584
|
+
if (typeof t[0] == "number")
|
|
585
|
+
return "integer";
|
|
586
|
+
}
|
|
587
|
+
return "string";
|
|
588
|
+
}
|
|
589
|
+
function va({
|
|
590
|
+
item: t,
|
|
591
|
+
pathPrefix: a
|
|
592
|
+
}) {
|
|
593
|
+
const { setPath: s } = b(), { infos: l } = te(t);
|
|
594
|
+
let c = l?.field?.type;
|
|
595
|
+
return c == null && (c = ae(t?.value)), /* @__PURE__ */ e.jsx(
|
|
596
|
+
v,
|
|
597
|
+
{
|
|
598
|
+
name: `${a}.matcher`,
|
|
599
|
+
value: t != null ? {
|
|
600
|
+
label: U.find((n) => n.matcher === t.matcher && (c != null && n.fieldTypes.includes(c) || c == null))?.label ?? (t.matcher != null ? `⚠️ ${t.matcher}` : ""),
|
|
601
|
+
value: t.matcher
|
|
602
|
+
} : void 0,
|
|
603
|
+
initialValues: U.filter(({ fieldTypes: n, visible: r }) => r !== !1 && n.includes(c)).map(({ matcher: n, label: r }) => ({ value: n, label: r })),
|
|
604
|
+
onSelect: (n) => {
|
|
605
|
+
$(n) && (s(`${a}.matcher`, n.value), B.includes(
|
|
606
|
+
n.value
|
|
607
|
+
) && s(`${a}.value`, null));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
const U = [
|
|
613
|
+
{
|
|
614
|
+
/** Matches if field value equals provided value
|
|
615
|
+
* @field Integer, String, Datetime, Boolean
|
|
616
|
+
* @value Integer, String, Datetime, Boolean
|
|
617
|
+
*/
|
|
618
|
+
matcher: "eq",
|
|
619
|
+
label: "equals",
|
|
620
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
/** Matches if field value is not equal to provided value
|
|
624
|
+
* @field Integer, String, Datetime, Boolean
|
|
625
|
+
* @value Integer, String, Datetime, Boolean
|
|
626
|
+
*/
|
|
627
|
+
matcher: "not_eq",
|
|
628
|
+
label: "not equals",
|
|
629
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
/** Matches if field value is less than provided value
|
|
633
|
+
* @field Integer, Datetime
|
|
634
|
+
* @value Integer, Datetime
|
|
635
|
+
*/
|
|
636
|
+
matcher: "lt",
|
|
637
|
+
label: "<",
|
|
638
|
+
fieldTypes: ["integer", "datetime"]
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
/** Matches if field value is less than or equal to provided value
|
|
642
|
+
* @field Integer, Datetime
|
|
643
|
+
* @value Integer, Datetime
|
|
644
|
+
*/
|
|
645
|
+
matcher: "lteq",
|
|
646
|
+
label: "≤",
|
|
647
|
+
fieldTypes: ["integer", "datetime"]
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
/** Matches if field value is greater than provided value
|
|
651
|
+
* @field Integer, Datetime
|
|
652
|
+
* @value Integer, Datetime
|
|
653
|
+
*/
|
|
654
|
+
matcher: "gt",
|
|
655
|
+
label: ">",
|
|
656
|
+
fieldTypes: ["integer", "datetime"]
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
/** Matches if field value is greater than or equal to provided value
|
|
660
|
+
* @field Integer, Datetime
|
|
661
|
+
* @value Integer, Datetime
|
|
662
|
+
*/
|
|
663
|
+
matcher: "gteq",
|
|
664
|
+
label: "≥",
|
|
665
|
+
fieldTypes: ["integer", "datetime"]
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
/** Matches if field value is a multiple of provided value
|
|
669
|
+
* @field Integer
|
|
670
|
+
* @value Integer
|
|
671
|
+
*/
|
|
672
|
+
matcher: "multiple",
|
|
673
|
+
label: "is a multiple of",
|
|
674
|
+
fieldTypes: ["integer"]
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
/** Matches if field value matches regex pattern
|
|
678
|
+
* @field String
|
|
679
|
+
* @value String
|
|
680
|
+
*/
|
|
681
|
+
matcher: "matches",
|
|
682
|
+
label: "matches regex",
|
|
683
|
+
fieldTypes: ["string"]
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
/** Matches if field value does not match regex pattern
|
|
687
|
+
* @field String
|
|
688
|
+
* @value String
|
|
689
|
+
*/
|
|
690
|
+
matcher: "does_not_match",
|
|
691
|
+
label: "doesn't match regex",
|
|
692
|
+
fieldTypes: ["string"]
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
/** Matches if field value starts with provided string
|
|
696
|
+
* @field String
|
|
697
|
+
* @value String
|
|
698
|
+
*/
|
|
699
|
+
matcher: "start_with",
|
|
700
|
+
label: "starts with",
|
|
701
|
+
fieldTypes: ["string"]
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
/** Matches if field value does not start with provided string
|
|
705
|
+
* @field String
|
|
706
|
+
* @value String
|
|
707
|
+
*/
|
|
708
|
+
matcher: "not_start_with",
|
|
709
|
+
label: "doesn't start with",
|
|
710
|
+
fieldTypes: ["string"]
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
/** Matches if field value ends with provided string
|
|
714
|
+
* @field String
|
|
715
|
+
* @value String
|
|
716
|
+
*/
|
|
717
|
+
matcher: "end_with",
|
|
718
|
+
label: "ends with",
|
|
719
|
+
fieldTypes: ["string"]
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
/** Matches if field value does not end with provided string
|
|
723
|
+
* @field String
|
|
724
|
+
* @value String
|
|
725
|
+
*/
|
|
726
|
+
matcher: "not_end_with",
|
|
727
|
+
label: "doesn't end with",
|
|
728
|
+
fieldTypes: ["string"]
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
/** Matches if field value is between two values (exclusive)
|
|
732
|
+
* @field Integer, Datetime
|
|
733
|
+
* @value Array
|
|
734
|
+
*/
|
|
735
|
+
matcher: "gt_lt",
|
|
736
|
+
label: "> and <",
|
|
737
|
+
fieldTypes: ["integer"]
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
/** Matches if field value is between two values (inclusive start, exclusive end)
|
|
741
|
+
* @field Integer, Datetime
|
|
742
|
+
* @value Array
|
|
743
|
+
*/
|
|
744
|
+
matcher: "gteq_lt",
|
|
745
|
+
label: "≥ and <",
|
|
746
|
+
fieldTypes: ["integer"]
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
/** Matches if field value is greater than first and less than or equal to second
|
|
750
|
+
* @field Integer, Datetime
|
|
751
|
+
* @value Array
|
|
752
|
+
*/
|
|
753
|
+
matcher: "gt_lteq",
|
|
754
|
+
label: "> and ≤",
|
|
755
|
+
fieldTypes: ["integer"]
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
/** Matches if field value is between two values (inclusive)
|
|
759
|
+
* @field Integer, Datetime
|
|
760
|
+
* @value Array
|
|
761
|
+
*/
|
|
762
|
+
matcher: "gteq_lteq",
|
|
763
|
+
label: "≥ and ≤",
|
|
764
|
+
fieldTypes: ["integer"]
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
/** Matches if field value is between two values (exclusive)
|
|
768
|
+
* @field Integer, Datetime
|
|
769
|
+
* @value Array
|
|
770
|
+
*/
|
|
771
|
+
matcher: "gt_lt",
|
|
772
|
+
label: "date range",
|
|
773
|
+
visible: !1,
|
|
774
|
+
fieldTypes: ["datetime"]
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
/** Matches if field value is between two values (inclusive start, exclusive end)
|
|
778
|
+
* @field Integer, Datetime
|
|
779
|
+
* @value Array
|
|
780
|
+
*/
|
|
781
|
+
matcher: "gteq_lt",
|
|
782
|
+
label: "date range",
|
|
783
|
+
visible: !1,
|
|
784
|
+
fieldTypes: ["datetime"]
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
/** Matches if field value is greater than first and less than or equal to second
|
|
788
|
+
* @field Integer, Datetime
|
|
789
|
+
* @value Array
|
|
790
|
+
*/
|
|
791
|
+
matcher: "gt_lteq",
|
|
792
|
+
label: "date range",
|
|
793
|
+
visible: !1,
|
|
794
|
+
fieldTypes: ["datetime"]
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
/** Matches if field value is between two values (inclusive)
|
|
798
|
+
* @field Integer, Datetime
|
|
799
|
+
* @value Array
|
|
800
|
+
*/
|
|
801
|
+
matcher: "gteq_lteq",
|
|
802
|
+
label: "date range",
|
|
803
|
+
visible: !0,
|
|
804
|
+
fieldTypes: ["datetime"]
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
/** Matches if field value is in provided array
|
|
808
|
+
* @field Integer, String, Datetime
|
|
809
|
+
* @value Array
|
|
810
|
+
*/
|
|
811
|
+
matcher: "is_in",
|
|
812
|
+
label: "is one of",
|
|
813
|
+
fieldTypes: ["integer", "string", "datetime"]
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
/** Matches if field value is not in provided array
|
|
817
|
+
* @field Integer, String, Datetime
|
|
818
|
+
* @value Array
|
|
819
|
+
*/
|
|
820
|
+
matcher: "is_not_in",
|
|
821
|
+
label: "is not one of",
|
|
822
|
+
fieldTypes: ["integer", "string", "datetime"]
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
/** Matches objects within arrays that meet specified requirements
|
|
826
|
+
* @field Array
|
|
827
|
+
* @value Object
|
|
828
|
+
*/
|
|
829
|
+
matcher: "array_match",
|
|
830
|
+
label: "is",
|
|
831
|
+
fieldTypes: ["integer", "string", "datetime"]
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
/** Matches if field value is null or empty string */
|
|
835
|
+
matcher: "blank",
|
|
836
|
+
label: "is blank",
|
|
837
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
/** Matches if field value is null */
|
|
841
|
+
matcher: "null",
|
|
842
|
+
label: "is null",
|
|
843
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
/** Matches if field value is not null */
|
|
847
|
+
matcher: "not_null",
|
|
848
|
+
label: "is not null",
|
|
849
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
/** Matches if field value is not null */
|
|
853
|
+
matcher: "present",
|
|
854
|
+
label: "is present",
|
|
855
|
+
fieldTypes: ["integer", "string", "datetime", "boolean"]
|
|
856
|
+
}
|
|
857
|
+
], J = {
|
|
858
|
+
in_and: {
|
|
859
|
+
label: "all of"
|
|
860
|
+
},
|
|
861
|
+
in_or: {
|
|
862
|
+
label: "at least one of"
|
|
863
|
+
},
|
|
864
|
+
not_in_and: {
|
|
865
|
+
label: "not any of"
|
|
866
|
+
},
|
|
867
|
+
not_in_or: {
|
|
868
|
+
label: "not at least one of"
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
function ja({
|
|
872
|
+
value: t,
|
|
873
|
+
pathPrefix: a
|
|
874
|
+
}) {
|
|
875
|
+
return (typeof t != "object" || Array.isArray(t) || t === null) && (t = {
|
|
876
|
+
in_and: []
|
|
877
|
+
}), /* @__PURE__ */ e.jsx("div", { children: Object.entries(t).map(([s, l], c) => /* @__PURE__ */ e.jsx(
|
|
878
|
+
_a,
|
|
879
|
+
{
|
|
880
|
+
pathPrefix: a,
|
|
881
|
+
defaultValue: l,
|
|
882
|
+
initialMatcher: s
|
|
883
|
+
},
|
|
884
|
+
`${a}.${// biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
|
|
885
|
+
c}`
|
|
886
|
+
)) });
|
|
887
|
+
}
|
|
888
|
+
function _a({
|
|
889
|
+
initialMatcher: t,
|
|
890
|
+
defaultValue: a,
|
|
891
|
+
pathPrefix: s
|
|
892
|
+
}) {
|
|
893
|
+
const [l, c] = f(t), [n, r] = f(t), [o, u] = f(a), { setPath: i } = b();
|
|
894
|
+
return T(() => {
|
|
895
|
+
l !== n && (i(`${s}.${l}`, null), c(n)), i(`${s}.${n}`, o);
|
|
896
|
+
}, [n, o, i]), /* @__PURE__ */ e.jsxs("div", { className: "flex gap-2 last-of-type:mt-2", children: [
|
|
897
|
+
/* @__PURE__ */ e.jsx("div", { className: "shrink-0", children: /* @__PURE__ */ e.jsx(
|
|
898
|
+
v,
|
|
899
|
+
{
|
|
900
|
+
defaultValue: [
|
|
901
|
+
{ value: n, label: J[n].label }
|
|
902
|
+
],
|
|
903
|
+
initialValues: Object.entries(J).map(
|
|
904
|
+
([d, { label: m }]) => ({
|
|
905
|
+
value: d,
|
|
906
|
+
label: m
|
|
907
|
+
})
|
|
908
|
+
),
|
|
909
|
+
onSelect: (d) => {
|
|
910
|
+
$(d) && r(d.value);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
) }),
|
|
914
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow", children: /* @__PURE__ */ e.jsx(
|
|
915
|
+
v,
|
|
916
|
+
{
|
|
917
|
+
isMulti: !0,
|
|
918
|
+
isCreatable: !0,
|
|
919
|
+
defaultValue: (Array.isArray(o) ? o : []).map((d) => ({
|
|
920
|
+
value: d,
|
|
921
|
+
label: d.toString()
|
|
922
|
+
})),
|
|
923
|
+
initialValues: [],
|
|
924
|
+
onSelect: (d) => {
|
|
925
|
+
Y(d) && u(
|
|
926
|
+
d.map(
|
|
927
|
+
(m) => typeof m.value == "boolean" ? m.value.toString() : m.value
|
|
928
|
+
)
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
) })
|
|
933
|
+
] });
|
|
934
|
+
}
|
|
935
|
+
function Ta({
|
|
936
|
+
value: t,
|
|
937
|
+
onChange: a
|
|
938
|
+
}) {
|
|
939
|
+
const [s, l] = f(
|
|
940
|
+
Array.isArray(t) && typeof t[0] == "number" ? t[0] : null
|
|
941
|
+
), [c, n] = f(
|
|
942
|
+
Array.isArray(t) && typeof t[1] == "number" ? t[1] : null
|
|
943
|
+
);
|
|
944
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-4", children: [
|
|
945
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow", children: /* @__PURE__ */ e.jsx(
|
|
946
|
+
g,
|
|
947
|
+
{
|
|
948
|
+
type: "number",
|
|
949
|
+
placeholder: "Min",
|
|
950
|
+
value: s ?? "",
|
|
951
|
+
onChange: (r) => {
|
|
952
|
+
const o = parseInt(r.currentTarget.value, 10);
|
|
953
|
+
l(Number.isNaN(o) ? null : o), a([Number.isNaN(o) ? null : o, c]);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
) }),
|
|
957
|
+
/* @__PURE__ */ e.jsx("span", { className: "text-gray-300", children: "to" }),
|
|
958
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow", children: /* @__PURE__ */ e.jsx(
|
|
959
|
+
g,
|
|
960
|
+
{
|
|
961
|
+
type: "number",
|
|
962
|
+
placeholder: "Max",
|
|
963
|
+
value: c ?? "",
|
|
964
|
+
onChange: (r) => {
|
|
965
|
+
const o = parseInt(r.currentTarget.value, 10);
|
|
966
|
+
n(Number.isNaN(o) ? null : o), a([s, Number.isNaN(o) ? null : o]);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
) })
|
|
970
|
+
] });
|
|
971
|
+
}
|
|
972
|
+
function Na({
|
|
973
|
+
value: t,
|
|
974
|
+
onChange: a
|
|
975
|
+
}) {
|
|
976
|
+
const [s, l] = f(
|
|
977
|
+
Array.isArray(t) && typeof t[0] == "string" ? t[0] : null
|
|
978
|
+
), [c, n] = f(
|
|
979
|
+
Array.isArray(t) && typeof t[1] == "string" ? t[1] : null
|
|
980
|
+
);
|
|
981
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-4", children: [
|
|
982
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow", children: /* @__PURE__ */ e.jsx(
|
|
983
|
+
g,
|
|
984
|
+
{
|
|
985
|
+
type: "text",
|
|
986
|
+
placeholder: "Min",
|
|
987
|
+
value: s ?? "",
|
|
988
|
+
onChange: (r) => {
|
|
989
|
+
const o = r.currentTarget.value;
|
|
990
|
+
l(o), a([o, c]);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
) }),
|
|
994
|
+
/* @__PURE__ */ e.jsx("span", { className: "text-gray-300", children: "to" }),
|
|
995
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow", children: /* @__PURE__ */ e.jsx(
|
|
996
|
+
g,
|
|
997
|
+
{
|
|
998
|
+
type: "text",
|
|
999
|
+
placeholder: "Max",
|
|
1000
|
+
value: c ?? "",
|
|
1001
|
+
onChange: (r) => {
|
|
1002
|
+
const o = r.currentTarget.value;
|
|
1003
|
+
n(o), a([s, o]);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
) })
|
|
1007
|
+
] });
|
|
1008
|
+
}
|
|
1009
|
+
function wa({
|
|
1010
|
+
item: t,
|
|
1011
|
+
pathPrefix: a
|
|
1012
|
+
}) {
|
|
1013
|
+
const { setPath: s } = b(), { infos: l } = te(t), { user: c } = X(), n = `${a}.value`;
|
|
1014
|
+
if (t == null || B.includes(
|
|
1015
|
+
t.matcher
|
|
1016
|
+
))
|
|
1017
|
+
return null;
|
|
1018
|
+
const r = t;
|
|
1019
|
+
let o = l?.field?.type;
|
|
1020
|
+
o == null && (o = ae(r.value)), (typeof r.value == "string" && /^{{.*}}$/.test(r.value) || Array.isArray(r.value) && r.value.some(
|
|
1021
|
+
(i) => typeof i == "string" && /^{{.*}}$/.test(i)
|
|
1022
|
+
)) && (o = "string");
|
|
1023
|
+
let u = null;
|
|
1024
|
+
switch (o) {
|
|
1025
|
+
case "datetime": {
|
|
1026
|
+
u = "date";
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
case "boolean": {
|
|
1030
|
+
u = "boolean";
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
case "string": {
|
|
1034
|
+
u = "text";
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
case "integer":
|
|
1038
|
+
case "float": {
|
|
1039
|
+
u = "number";
|
|
1040
|
+
break;
|
|
1041
|
+
}
|
|
1042
|
+
case "array":
|
|
1043
|
+
case "json":
|
|
1044
|
+
case "object":
|
|
1045
|
+
break;
|
|
1046
|
+
default: {
|
|
1047
|
+
u = "text";
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
switch (r.matcher) {
|
|
1052
|
+
case "eq":
|
|
1053
|
+
case "not_eq":
|
|
1054
|
+
case "lt":
|
|
1055
|
+
case "lteq":
|
|
1056
|
+
case "gt":
|
|
1057
|
+
case "gteq":
|
|
1058
|
+
case "multiple":
|
|
1059
|
+
case "start_with":
|
|
1060
|
+
case "not_start_with":
|
|
1061
|
+
case "end_with":
|
|
1062
|
+
case "not_end_with":
|
|
1063
|
+
break;
|
|
1064
|
+
case "matches":
|
|
1065
|
+
case "does_not_match":
|
|
1066
|
+
break;
|
|
1067
|
+
case "gt_lt":
|
|
1068
|
+
case "gteq_lt":
|
|
1069
|
+
case "gt_lteq":
|
|
1070
|
+
case "gteq_lteq": {
|
|
1071
|
+
u === "number" && (u = "numberRange"), u === "text" && (u = "textRange"), u === "date" && (u = "dateRange");
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
case "is_in":
|
|
1075
|
+
case "is_not_in": {
|
|
1076
|
+
u = "tag";
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
case "array_match": {
|
|
1080
|
+
u = "arrayMatch";
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
default: {
|
|
1084
|
+
R(r.matcher);
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
switch (u) {
|
|
1089
|
+
case "date": {
|
|
1090
|
+
const i = F(
|
|
1091
|
+
typeof r.value == "string" ? r.value : ""
|
|
1092
|
+
);
|
|
1093
|
+
return /* @__PURE__ */ e.jsx(
|
|
1094
|
+
ra,
|
|
1095
|
+
{
|
|
1096
|
+
value: k(i) ? i : void 0,
|
|
1097
|
+
showTimeSelect: !0,
|
|
1098
|
+
placeholder: "Enter value",
|
|
1099
|
+
onChange: (d) => {
|
|
1100
|
+
s(n, d?.toJSON());
|
|
1101
|
+
},
|
|
1102
|
+
timezone: c?.timezone
|
|
1103
|
+
}
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
case "dateRange": {
|
|
1107
|
+
const i = Array.isArray(r.value) ? r.value.map((d) => {
|
|
1108
|
+
const m = F(typeof d == "string" ? d : "");
|
|
1109
|
+
return k(m) ? m : null;
|
|
1110
|
+
}) : [null, null];
|
|
1111
|
+
return /* @__PURE__ */ e.jsx(
|
|
1112
|
+
na,
|
|
1113
|
+
{
|
|
1114
|
+
value: i,
|
|
1115
|
+
showTimeSelect: !0,
|
|
1116
|
+
onChange: (d) => {
|
|
1117
|
+
s(
|
|
1118
|
+
`${a}.value`,
|
|
1119
|
+
d.map((m) => m?.toJSON() ?? null)
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
case "numberRange":
|
|
1126
|
+
return /* @__PURE__ */ e.jsx(
|
|
1127
|
+
Ta,
|
|
1128
|
+
{
|
|
1129
|
+
value: r.value,
|
|
1130
|
+
onChange: (i) => {
|
|
1131
|
+
s(n, i);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
case "textRange":
|
|
1136
|
+
return /* @__PURE__ */ e.jsx(
|
|
1137
|
+
Na,
|
|
1138
|
+
{
|
|
1139
|
+
value: r.value,
|
|
1140
|
+
onChange: (i) => {
|
|
1141
|
+
s(n, i);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
);
|
|
1145
|
+
case "arrayMatch":
|
|
1146
|
+
return /* @__PURE__ */ e.jsx(
|
|
1147
|
+
ja,
|
|
1148
|
+
{
|
|
1149
|
+
value: r.value,
|
|
1150
|
+
pathPrefix: `${a}.value`
|
|
1151
|
+
}
|
|
1152
|
+
);
|
|
1153
|
+
case "tag":
|
|
1154
|
+
return /* @__PURE__ */ e.jsx(
|
|
1155
|
+
v,
|
|
1156
|
+
{
|
|
1157
|
+
isMulti: !0,
|
|
1158
|
+
isClearable: !1,
|
|
1159
|
+
isCreatable: !0,
|
|
1160
|
+
defaultValue: Array.isArray(r.value) ? r.value.map((i) => ({
|
|
1161
|
+
label: i.toString(),
|
|
1162
|
+
value: i
|
|
1163
|
+
})) : [],
|
|
1164
|
+
initialValues: [],
|
|
1165
|
+
onSelect: (i) => {
|
|
1166
|
+
Y(i) && s(
|
|
1167
|
+
`${a}.value`,
|
|
1168
|
+
i.map((d) => {
|
|
1169
|
+
if (o === "integer") {
|
|
1170
|
+
const m = parseInt(d.value.toString(), 10);
|
|
1171
|
+
return Number.isNaN(m) ? null : m;
|
|
1172
|
+
}
|
|
1173
|
+
return d.value;
|
|
1174
|
+
}).filter((d) => d != null)
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1179
|
+
case "number":
|
|
1180
|
+
return /* @__PURE__ */ e.jsx(
|
|
1181
|
+
g,
|
|
1182
|
+
{
|
|
1183
|
+
name: `${a}.value`,
|
|
1184
|
+
type: "number",
|
|
1185
|
+
defaultValue: typeof r.value == "number" ? r.value : "",
|
|
1186
|
+
placeholder: "Enter value",
|
|
1187
|
+
onChange: (i) => {
|
|
1188
|
+
s(
|
|
1189
|
+
`${a}.value`,
|
|
1190
|
+
parseInt(i.currentTarget.value, 10)
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
);
|
|
1195
|
+
case "boolean":
|
|
1196
|
+
return /* @__PURE__ */ e.jsx(
|
|
1197
|
+
v,
|
|
1198
|
+
{
|
|
1199
|
+
name: `${a}.value`,
|
|
1200
|
+
defaultValue: typeof r.value == "boolean" ? {
|
|
1201
|
+
label: r.value ? "Yes" : "No",
|
|
1202
|
+
value: r.value
|
|
1203
|
+
} : void 0,
|
|
1204
|
+
initialValues: [
|
|
1205
|
+
{ label: "Yes", value: !0 },
|
|
1206
|
+
{ label: "No", value: !1 }
|
|
1207
|
+
],
|
|
1208
|
+
onSelect: (i) => {
|
|
1209
|
+
$(i) && s(n, i.value);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
);
|
|
1213
|
+
case "text":
|
|
1214
|
+
case null:
|
|
1215
|
+
return /* @__PURE__ */ e.jsx(
|
|
1216
|
+
g,
|
|
1217
|
+
{
|
|
1218
|
+
name: `${a}.value`,
|
|
1219
|
+
type: "text",
|
|
1220
|
+
defaultValue: typeof r.value == "string" ? r.value : JSON.stringify(r.value),
|
|
1221
|
+
placeholder: "Enter value",
|
|
1222
|
+
onChange: (i) => {
|
|
1223
|
+
s(n, i.currentTarget.value);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
);
|
|
1227
|
+
default:
|
|
1228
|
+
return R();
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
function $a({
|
|
1232
|
+
item: t,
|
|
1233
|
+
nestingLevel: a,
|
|
1234
|
+
pathPrefix: s,
|
|
1235
|
+
onDelete: l
|
|
1236
|
+
}) {
|
|
1237
|
+
const { setPath: c } = b(), n = [];
|
|
1238
|
+
return a < 2 && (n[0] ??= [], n[0].push(
|
|
1239
|
+
/* @__PURE__ */ e.jsx(
|
|
1240
|
+
w,
|
|
1241
|
+
{
|
|
1242
|
+
label: "Nest conditions",
|
|
1243
|
+
onClick: () => {
|
|
1244
|
+
c(
|
|
1245
|
+
`${s}.nested.conditions.${(t?.nested?.conditions ?? []).length}`,
|
|
1246
|
+
void 0
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
)
|
|
1251
|
+
)), l != null && (n[1] ??= [], n[1].push(
|
|
1252
|
+
/* @__PURE__ */ e.jsx(
|
|
1253
|
+
w,
|
|
1254
|
+
{
|
|
1255
|
+
label: "Delete",
|
|
1256
|
+
onClick: () => {
|
|
1257
|
+
c(`${s}`, null), l();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
)
|
|
1261
|
+
)), /* @__PURE__ */ e.jsxs("div", { className: "bg-gray-50 rounded-md flex items-center", children: [
|
|
1262
|
+
/* @__PURE__ */ e.jsx("div", { className: "flex items-center justify-between gap-2 grow p-2", children: /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2 grow", children: [
|
|
1263
|
+
/* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1264
|
+
/* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
|
|
1265
|
+
ee,
|
|
1266
|
+
{
|
|
1267
|
+
preset: "condition",
|
|
1268
|
+
value: t?.field,
|
|
1269
|
+
name: `${s}.field`
|
|
1270
|
+
}
|
|
1271
|
+
) }),
|
|
1272
|
+
/* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(va, { item: t, pathPrefix: s }) })
|
|
1273
|
+
] }),
|
|
1274
|
+
/* @__PURE__ */ e.jsx(wa, { item: t, pathPrefix: s })
|
|
1275
|
+
] }) }),
|
|
1276
|
+
n.length > 0 && /* @__PURE__ */ e.jsx(
|
|
1277
|
+
A,
|
|
1278
|
+
{
|
|
1279
|
+
className: "w-8 border-l border-gray-100 flex items-center justify-center self-stretch",
|
|
1280
|
+
dropdownLabel: /* @__PURE__ */ e.jsx(
|
|
1281
|
+
"button",
|
|
1282
|
+
{
|
|
1283
|
+
type: "button",
|
|
1284
|
+
className: "flex items-center justify-center self-stretch grow",
|
|
1285
|
+
children: /* @__PURE__ */ e.jsx(x, { name: "dotsThreeVertical", size: 16, weight: "bold" })
|
|
1286
|
+
}
|
|
1287
|
+
),
|
|
1288
|
+
dropdownItems: n.map((r, o, u) => (
|
|
1289
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
|
|
1290
|
+
/* @__PURE__ */ e.jsxs(O.Fragment, { children: [
|
|
1291
|
+
r.map((i, d) => (
|
|
1292
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
|
|
1293
|
+
/* @__PURE__ */ e.jsx(O.Fragment, { children: i }, d)
|
|
1294
|
+
)),
|
|
1295
|
+
o < u.length - 1 && /* @__PURE__ */ e.jsx(H, {})
|
|
1296
|
+
] }, o)
|
|
1297
|
+
))
|
|
1298
|
+
}
|
|
1299
|
+
)
|
|
1300
|
+
] });
|
|
1301
|
+
}
|
|
1302
|
+
function se({
|
|
1303
|
+
item: t,
|
|
1304
|
+
children: a,
|
|
1305
|
+
nestingLevel: s = 0,
|
|
1306
|
+
pathPrefix: l
|
|
1307
|
+
}) {
|
|
1308
|
+
const {
|
|
1309
|
+
state: { selectedRuleIndex: c }
|
|
1310
|
+
} = b(), n = t?.conditions_logic?.toLowerCase() ?? "and", { setPath: r } = b(), [o, u] = f(0), i = s > 0;
|
|
1311
|
+
return /* @__PURE__ */ e.jsxs(
|
|
1312
|
+
"div",
|
|
1313
|
+
{
|
|
1314
|
+
className: I("query-group", {
|
|
1315
|
+
"p-4 border border-gray-200 rounded-md": i
|
|
1316
|
+
}),
|
|
1317
|
+
children: [
|
|
1318
|
+
a,
|
|
1319
|
+
t != null && (t.conditions ?? []).length > 0 && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
1320
|
+
/* @__PURE__ */ e.jsxs(
|
|
1321
|
+
"select",
|
|
1322
|
+
{
|
|
1323
|
+
onChange: (d) => {
|
|
1324
|
+
r(
|
|
1325
|
+
`${l}.conditions_logic`,
|
|
1326
|
+
d.currentTarget.value
|
|
1327
|
+
);
|
|
1328
|
+
},
|
|
1329
|
+
defaultValue: n,
|
|
1330
|
+
className: "pl-4 pr-8 py-2 font-bold focus:ring-0 focus:outline-hidden appearance-none bg-gray-50 border border-gray-200 rounded-md text-sm leading-4",
|
|
1331
|
+
children: [
|
|
1332
|
+
/* @__PURE__ */ e.jsxs("option", { value: "and", children: [
|
|
1333
|
+
i ? "Nested in " : "",
|
|
1334
|
+
"AND"
|
|
1335
|
+
] }),
|
|
1336
|
+
/* @__PURE__ */ e.jsxs("option", { value: "or", children: [
|
|
1337
|
+
i ? "Nested in " : "",
|
|
1338
|
+
"OR"
|
|
1339
|
+
] })
|
|
1340
|
+
]
|
|
1341
|
+
}
|
|
1342
|
+
),
|
|
1343
|
+
/* @__PURE__ */ e.jsx("div", { className: "border-l border-gray-200 ml-3 pt-3", children: t?.conditions?.map((d, m, j) => {
|
|
1344
|
+
const h = m === j.length - 1;
|
|
1345
|
+
return /* @__PURE__ */ e.jsxs(
|
|
1346
|
+
"div",
|
|
1347
|
+
{
|
|
1348
|
+
className: "flex items-center mb-4 last:mb-0 relative",
|
|
1349
|
+
children: [
|
|
1350
|
+
/* @__PURE__ */ e.jsx(Ca, { rounded: h }),
|
|
1351
|
+
/* @__PURE__ */ e.jsx("div", { className: "ml-4 w-full", children: /* @__PURE__ */ e.jsx(
|
|
1352
|
+
se,
|
|
1353
|
+
{
|
|
1354
|
+
item: d?.nested ?? void 0,
|
|
1355
|
+
nestingLevel: d?.nested != null ? s + 1 : 0,
|
|
1356
|
+
pathPrefix: `${l}.conditions.${m}.nested`,
|
|
1357
|
+
children: /* @__PURE__ */ e.jsx(
|
|
1358
|
+
"div",
|
|
1359
|
+
{
|
|
1360
|
+
className: I({
|
|
1361
|
+
"mb-4": d?.nested != null
|
|
1362
|
+
}),
|
|
1363
|
+
children: /* @__PURE__ */ e.jsx(
|
|
1364
|
+
$a,
|
|
1365
|
+
{
|
|
1366
|
+
item: d,
|
|
1367
|
+
nestingLevel: s,
|
|
1368
|
+
pathPrefix: `${l}.conditions.${m}`,
|
|
1369
|
+
onDelete: j.length > 1 || s > 0 ? () => {
|
|
1370
|
+
u((p) => p + 1);
|
|
1371
|
+
} : void 0
|
|
1372
|
+
}
|
|
1373
|
+
)
|
|
1374
|
+
}
|
|
1375
|
+
)
|
|
1376
|
+
}
|
|
1377
|
+
) })
|
|
1378
|
+
]
|
|
1379
|
+
},
|
|
1380
|
+
`${c}-${m}-${o}`
|
|
1381
|
+
);
|
|
1382
|
+
}) })
|
|
1383
|
+
] })
|
|
1384
|
+
]
|
|
1385
|
+
}
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
function Ca({
|
|
1389
|
+
rounded: t = !1
|
|
1390
|
+
}) {
|
|
1391
|
+
return t ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
1392
|
+
/* @__PURE__ */ e.jsx("div", { className: "absolute -left-px top-1/2 w-px h-1/2 bg-white" }),
|
|
1393
|
+
/* @__PURE__ */ e.jsx("div", { className: "absolute -left-px top-1/2 -translate-y-1/2 w-3.5 h-3.5 border-l border-b rounded-es-sm bg-white border-gray-200" })
|
|
1394
|
+
] }) : /* @__PURE__ */ e.jsx("div", { className: "absolute left-0 top-1/2 -translate-y-1/2 w-3.5 h-px bg-gray-200" });
|
|
1395
|
+
}
|
|
1396
|
+
function ka() {
|
|
1397
|
+
const {
|
|
1398
|
+
setPath: t,
|
|
1399
|
+
state: { value: a, selectedRuleIndex: s }
|
|
1400
|
+
} = b(), [l, c] = f(
|
|
1401
|
+
a.rules?.[s]?.name ?? ""
|
|
1402
|
+
);
|
|
1403
|
+
return T(() => {
|
|
1404
|
+
c(a.rules?.[s]?.name ?? "");
|
|
1405
|
+
}, [s]), // <Input
|
|
1406
|
+
// value={value.rules?.[selectedRuleIndex]?.name}
|
|
1407
|
+
// onChange={(event) => {
|
|
1408
|
+
// const target = event.currentTarget
|
|
1409
|
+
// const value = target.value.replace(/[\n\s]+/g, " ").trim()
|
|
1410
|
+
// setPath(`rules.${selectedRuleIndex}.name`, value)
|
|
1411
|
+
// }}
|
|
1412
|
+
// className="bg-transparent border-0 shadow-none field-sizing-content"
|
|
1413
|
+
// />
|
|
1414
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: This <div> is used with contentEditable
|
|
1415
|
+
/* @__PURE__ */ e.jsx(
|
|
1416
|
+
"div",
|
|
1417
|
+
{
|
|
1418
|
+
contentEditable: "plaintext-only",
|
|
1419
|
+
suppressContentEditableWarning: !0,
|
|
1420
|
+
onInput: (n) => {
|
|
1421
|
+
const o = n.currentTarget.innerText.replace(/[\n\s]+/g, " ").trim();
|
|
1422
|
+
t(`rules.${s}.name`, o);
|
|
1423
|
+
},
|
|
1424
|
+
onKeyDown: (n) => {
|
|
1425
|
+
n.key === "Enter" && (n.preventDefault(), n.currentTarget.blur());
|
|
1426
|
+
},
|
|
1427
|
+
onBlur: (n) => {
|
|
1428
|
+
const r = n.currentTarget;
|
|
1429
|
+
r.innerText = r.innerText.replace(/[\n\s]+/g, " ").trim();
|
|
1430
|
+
},
|
|
1431
|
+
children: l
|
|
1432
|
+
},
|
|
1433
|
+
s
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
const W = {
|
|
1437
|
+
rules: []
|
|
1438
|
+
}, E = (t) => {
|
|
1439
|
+
try {
|
|
1440
|
+
return JSON.parse(t ?? JSON.stringify(W));
|
|
1441
|
+
} catch {
|
|
1442
|
+
return W;
|
|
1443
|
+
}
|
|
1444
|
+
}, Ea = (t) => {
|
|
1445
|
+
try {
|
|
1446
|
+
return JSON.parse(t ?? "{}"), !0;
|
|
1447
|
+
} catch {
|
|
1448
|
+
return !1;
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
function qa(t) {
|
|
1452
|
+
const {
|
|
1453
|
+
settings: { domain: a }
|
|
1454
|
+
} = X(), [s, l] = f([]), [c, n] = f(
|
|
1455
|
+
E(t.value ?? t.defaultValue)
|
|
1456
|
+
);
|
|
1457
|
+
return T(
|
|
1458
|
+
function() {
|
|
1459
|
+
c.rules?.length === 0 && n(E(t.value));
|
|
1460
|
+
},
|
|
1461
|
+
[t.value]
|
|
1462
|
+
), T(
|
|
1463
|
+
function() {
|
|
1464
|
+
la(t.schemaType, a).then((o) => {
|
|
1465
|
+
const i = y.object({
|
|
1466
|
+
properties: y.object({
|
|
1467
|
+
rules: y.object({
|
|
1468
|
+
items: y.object({
|
|
1469
|
+
properties: y.object({
|
|
1470
|
+
actions: y.object({
|
|
1471
|
+
items: y.object({
|
|
1472
|
+
anyOf: y.array(
|
|
1473
|
+
y.object({
|
|
1474
|
+
properties: y.object({
|
|
1475
|
+
type: y.object({
|
|
1476
|
+
enum: y.string().array()
|
|
1477
|
+
})
|
|
1478
|
+
})
|
|
1479
|
+
})
|
|
1480
|
+
)
|
|
1481
|
+
})
|
|
1482
|
+
})
|
|
1483
|
+
})
|
|
1484
|
+
})
|
|
1485
|
+
})
|
|
1486
|
+
})
|
|
1487
|
+
}).parse(o).properties.rules.items.properties.actions.items.anyOf.flatMap(
|
|
1488
|
+
(d) => d.properties.type.enum
|
|
1489
|
+
);
|
|
1490
|
+
l([...new Set(i)]);
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
[a]
|
|
1494
|
+
), /* @__PURE__ */ e.jsx(
|
|
1495
|
+
fa,
|
|
1496
|
+
{
|
|
1497
|
+
initialValue: {
|
|
1498
|
+
value: { rules: c.rules },
|
|
1499
|
+
availableActionTypes: s,
|
|
1500
|
+
schemaType: t.schemaType
|
|
1501
|
+
},
|
|
1502
|
+
children: /* @__PURE__ */ e.jsx(Sa, { ...t })
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
function Sa(t) {
|
|
1507
|
+
const {
|
|
1508
|
+
state: { value: a, selectedRuleIndex: s },
|
|
1509
|
+
setSelectedRuleIndex: l,
|
|
1510
|
+
setValue: c,
|
|
1511
|
+
setPath: n
|
|
1512
|
+
} = b(), [r, o] = f(
|
|
1513
|
+
t.defaultCodeEditorVisible ?? !1
|
|
1514
|
+
), u = a.rules?.[s], i = G(null), [d, m] = f(0);
|
|
1515
|
+
T(
|
|
1516
|
+
function() {
|
|
1517
|
+
V(E(i.current?.getValue()), a) || i.current?.setValue(JSON.stringify(a, null, 2)), t.onChange?.(a);
|
|
1518
|
+
},
|
|
1519
|
+
[a]
|
|
1520
|
+
);
|
|
1521
|
+
const j = C(
|
|
1522
|
+
(h) => {
|
|
1523
|
+
const p = E(h);
|
|
1524
|
+
i.current?.hasTextFocus() && Ea(h) && !V(p, a) && (c(p), m((_) => _ + 1));
|
|
1525
|
+
},
|
|
1526
|
+
[a]
|
|
1527
|
+
);
|
|
1528
|
+
return /* @__PURE__ */ e.jsx(
|
|
1529
|
+
ia,
|
|
1530
|
+
{
|
|
1531
|
+
hint: t.hint,
|
|
1532
|
+
feedback: t.feedback,
|
|
1533
|
+
className: "h-full [&>div:first-of-type]:h-full",
|
|
1534
|
+
children: /* @__PURE__ */ e.jsxs("section", { className: "flex h-full", children: [
|
|
1535
|
+
/* @__PURE__ */ e.jsxs(
|
|
1536
|
+
"div",
|
|
1537
|
+
{
|
|
1538
|
+
className: `shrink-0 basis-3/5 overflow-x-auto relative flex flex-col ${r ? "" : "grow"}`,
|
|
1539
|
+
children: [
|
|
1540
|
+
/* @__PURE__ */ e.jsxs("header", { className: "w-full bg-white border-b border-gray-200 px-4 flex text-[13px] gap-4 text-gray-400 font-semibold items-center", children: [
|
|
1541
|
+
/* @__PURE__ */ e.jsxs("div", { className: "flex items-center flex-wrap basis-full", children: [
|
|
1542
|
+
a.rules?.map((h, p, _) => {
|
|
1543
|
+
const ne = `#${(p + 1).toString().padStart(2, "0")}`;
|
|
1544
|
+
return /* @__PURE__ */ e.jsxs(
|
|
1545
|
+
"div",
|
|
1546
|
+
{
|
|
1547
|
+
className: "flex items-center py-3 pl-4 pr-2 border-r basis-[88px] justify-center",
|
|
1548
|
+
children: [
|
|
1549
|
+
/* @__PURE__ */ e.jsx(
|
|
1550
|
+
"button",
|
|
1551
|
+
{
|
|
1552
|
+
type: "button",
|
|
1553
|
+
className: I("font-bold mr-2", {
|
|
1554
|
+
"text-black": s === p
|
|
1555
|
+
}),
|
|
1556
|
+
onClick: () => {
|
|
1557
|
+
l(p);
|
|
1558
|
+
},
|
|
1559
|
+
children: ne
|
|
1560
|
+
}
|
|
1561
|
+
),
|
|
1562
|
+
/* @__PURE__ */ e.jsx(
|
|
1563
|
+
A,
|
|
1564
|
+
{
|
|
1565
|
+
menuPosition: p === 0 ? "bottom-left" : "bottom-right",
|
|
1566
|
+
dropdownLabel: /* @__PURE__ */ e.jsx(N, { variant: "circle", children: /* @__PURE__ */ e.jsx(x, { name: "dotsThreeVertical", size: 16 }) }),
|
|
1567
|
+
dropdownItems: /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
1568
|
+
/* @__PURE__ */ e.jsx(
|
|
1569
|
+
w,
|
|
1570
|
+
{
|
|
1571
|
+
onClick: () => {
|
|
1572
|
+
const Z = a.rules?.length ?? 0;
|
|
1573
|
+
n(`rules.${Z}`, {
|
|
1574
|
+
...h,
|
|
1575
|
+
name: `${h.name} (copy)`
|
|
1576
|
+
}), l(Z);
|
|
1577
|
+
},
|
|
1578
|
+
label: "Duplicate"
|
|
1579
|
+
}
|
|
1580
|
+
),
|
|
1581
|
+
/* @__PURE__ */ e.jsx(H, {}),
|
|
1582
|
+
/* @__PURE__ */ e.jsx(
|
|
1583
|
+
w,
|
|
1584
|
+
{
|
|
1585
|
+
disabled: _.length === 1,
|
|
1586
|
+
onClick: () => {
|
|
1587
|
+
n(`rules.${p}`, null), s >= p && l(s - 1);
|
|
1588
|
+
},
|
|
1589
|
+
label: "Delete"
|
|
1590
|
+
}
|
|
1591
|
+
)
|
|
1592
|
+
] })
|
|
1593
|
+
}
|
|
1594
|
+
)
|
|
1595
|
+
]
|
|
1596
|
+
},
|
|
1597
|
+
`${p}-${h.id}`
|
|
1598
|
+
);
|
|
1599
|
+
}),
|
|
1600
|
+
/* @__PURE__ */ e.jsx("div", { className: "min-h-[49px] flex items-center", children: /* @__PURE__ */ e.jsx(
|
|
1601
|
+
N,
|
|
1602
|
+
{
|
|
1603
|
+
variant: "circle",
|
|
1604
|
+
className: "mx-4",
|
|
1605
|
+
onClick: () => {
|
|
1606
|
+
n(`rules.${a.rules?.length ?? 0}`, {
|
|
1607
|
+
name: "Rule name",
|
|
1608
|
+
actions: [null],
|
|
1609
|
+
conditions: [null]
|
|
1610
|
+
}), l(a.rules?.length ?? 0);
|
|
1611
|
+
},
|
|
1612
|
+
children: /* @__PURE__ */ e.jsx(x, { name: "plus", size: 16, className: "shrink-0" })
|
|
1613
|
+
}
|
|
1614
|
+
) })
|
|
1615
|
+
] }),
|
|
1616
|
+
/* @__PURE__ */ e.jsx("div", { className: "grow flex justify-end", children: /* @__PURE__ */ e.jsx(
|
|
1617
|
+
N,
|
|
1618
|
+
{
|
|
1619
|
+
variant: "circle",
|
|
1620
|
+
onClick: () => {
|
|
1621
|
+
o(!r);
|
|
1622
|
+
},
|
|
1623
|
+
children: /* @__PURE__ */ e.jsx(x, { name: "sidebarSimple", size: 16 })
|
|
1624
|
+
}
|
|
1625
|
+
) })
|
|
1626
|
+
] }),
|
|
1627
|
+
/* @__PURE__ */ e.jsx(Ra, { children: u && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
1628
|
+
/* @__PURE__ */ e.jsxs("div", { className: "mb-8 flex items-center gap-2", children: [
|
|
1629
|
+
/* @__PURE__ */ e.jsx(ka, {}),
|
|
1630
|
+
/* @__PURE__ */ e.jsx(x, { name: "pencilSimple", size: 16, className: "shrink-0" })
|
|
1631
|
+
] }),
|
|
1632
|
+
/* @__PURE__ */ e.jsx(K, { title: "Actions", icon: "lightning", children: /* @__PURE__ */ e.jsx(xa, { actions: u?.actions }) }),
|
|
1633
|
+
/* @__PURE__ */ e.jsx(Va, { children: "when" }),
|
|
1634
|
+
/* @__PURE__ */ e.jsxs(K, { title: "Conditions", icon: "treeView", children: [
|
|
1635
|
+
/* @__PURE__ */ e.jsx(
|
|
1636
|
+
se,
|
|
1637
|
+
{
|
|
1638
|
+
item: u,
|
|
1639
|
+
pathPrefix: `rules.${s}`
|
|
1640
|
+
}
|
|
1641
|
+
),
|
|
1642
|
+
/* @__PURE__ */ e.jsx("div", { className: "mt-6", children: /* @__PURE__ */ e.jsxs(
|
|
1643
|
+
N,
|
|
1644
|
+
{
|
|
1645
|
+
size: "small",
|
|
1646
|
+
variant: "secondary",
|
|
1647
|
+
alignItems: "center",
|
|
1648
|
+
onClick: () => {
|
|
1649
|
+
n(
|
|
1650
|
+
`rules.${s}.conditions.${u?.conditions?.length ?? 0}`,
|
|
1651
|
+
void 0
|
|
1652
|
+
);
|
|
1653
|
+
},
|
|
1654
|
+
children: [
|
|
1655
|
+
/* @__PURE__ */ e.jsx(x, { name: "plusCircle" }),
|
|
1656
|
+
" Add condition"
|
|
1657
|
+
]
|
|
1658
|
+
}
|
|
1659
|
+
) })
|
|
1660
|
+
] })
|
|
1661
|
+
] }) })
|
|
1662
|
+
]
|
|
1663
|
+
},
|
|
1664
|
+
d
|
|
1665
|
+
),
|
|
1666
|
+
r && /* @__PURE__ */ e.jsx("div", { className: "shrink-0 basis-2/5", children: /* @__PURE__ */ e.jsx(
|
|
1667
|
+
oa,
|
|
1668
|
+
{
|
|
1669
|
+
ref: i,
|
|
1670
|
+
name: t.id ?? t.name,
|
|
1671
|
+
height: "100%",
|
|
1672
|
+
language: "json",
|
|
1673
|
+
jsonSchema: t.schemaType,
|
|
1674
|
+
defaultValue: JSON.stringify(a, null, 2),
|
|
1675
|
+
noRounding: !0,
|
|
1676
|
+
onChange: j
|
|
1677
|
+
}
|
|
1678
|
+
) })
|
|
1679
|
+
] })
|
|
1680
|
+
}
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
function Va({ children: t }) {
|
|
1684
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "text-gray-500 flex items-center justify-center flex-col", children: [
|
|
1685
|
+
/* @__PURE__ */ e.jsx("div", { className: "h-6 w-[2px] bg-gray-200" }),
|
|
1686
|
+
/* @__PURE__ */ e.jsx("span", { className: "font-bold my-1 bg-gray-200 px-3 relative uppercase rounded h-[25px] items-center flex text-sm", children: t }),
|
|
1687
|
+
/* @__PURE__ */ e.jsx("div", { className: "h-6 w-[2px] bg-gray-200" })
|
|
1688
|
+
] });
|
|
1689
|
+
}
|
|
1690
|
+
function K({
|
|
1691
|
+
children: t,
|
|
1692
|
+
title: a,
|
|
1693
|
+
icon: s
|
|
1694
|
+
}) {
|
|
1695
|
+
return /* @__PURE__ */ e.jsxs("div", { className: "rounded-md bg-white shadow-xs", children: [
|
|
1696
|
+
/* @__PURE__ */ e.jsxs("div", { className: "flex items-center space-x-4 py-4 border-b border-gray-100", children: [
|
|
1697
|
+
/* @__PURE__ */ e.jsx("div", { className: "w-8 h-8 -ml-4 bg-white rounded-full border border-gray-200 flex items-center justify-center shadow-xs shadow-primary-200", children: /* @__PURE__ */ e.jsx(x, { name: s }) }),
|
|
1698
|
+
/* @__PURE__ */ e.jsx("h2", { className: "text-lg font-semibold", children: a })
|
|
1699
|
+
] }),
|
|
1700
|
+
/* @__PURE__ */ e.jsx("div", { className: "p-6", children: t })
|
|
1701
|
+
] });
|
|
1702
|
+
}
|
|
1703
|
+
function Ra({
|
|
1704
|
+
children: t
|
|
1705
|
+
}) {
|
|
1706
|
+
return /* @__PURE__ */ e.jsx("div", { className: "h-full w-full bg-gray-50 p-8 bg-[radial-gradient(#d6d6d6_1px,transparent_1px)] bg-size-[16px_16px] overflow-auto", children: /* @__PURE__ */ e.jsx("div", { className: "max-w-[900px] mx-auto", children: t }) });
|
|
1707
|
+
}
|
|
1708
|
+
export {
|
|
1709
|
+
qa as RuleEngine
|
|
1710
|
+
};
|