@commercelayer/app-elements 6.1.2 → 6.2.1

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