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