@viamedici-spc/configurator-react 0.1.0-alpha0018

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1329 @@
1
+ import { match as Je } from "ts-pattern";
2
+ import { deepEqual as me } from "fast-equals";
3
+ import { createContext as F, useContext as V, useMemo as m, useEffect as ce } from "react";
4
+ import { jsx as z, Fragment as Le } from "react/jsx-runtime";
5
+ import { createMachine as ne, assign as d, sendParent as he, spawn as le, forwardTo as B, send as Xe } from "xstate";
6
+ import { log as C, pure as Ye, stop as fe } from "xstate/lib/actions";
7
+ import { useMachine as Qe } from "@xstate/react";
8
+ var Ze = globalThis && globalThis.__spreadArray || function(e, n, t) {
9
+ if (t || arguments.length === 2)
10
+ for (var i = 0, o = n.length, s; i < o; i++)
11
+ (s || !(i in n)) && (s || (s = Array.prototype.slice.call(n, 0, i)), s[i] = n[i]);
12
+ return e.concat(s || Array.prototype.slice.call(n));
13
+ };
14
+ function O(e) {
15
+ return e;
16
+ }
17
+ function Ce(e) {
18
+ return function() {
19
+ return e;
20
+ };
21
+ }
22
+ var en = /* @__PURE__ */ Ce(null), ye = /* @__PURE__ */ Ce(void 0), nn = ye;
23
+ function Se(e, n, t, i, o, s, a, g, u) {
24
+ switch (arguments.length) {
25
+ case 1:
26
+ return e;
27
+ case 2:
28
+ return function() {
29
+ return n(e.apply(this, arguments));
30
+ };
31
+ case 3:
32
+ return function() {
33
+ return t(n(e.apply(this, arguments)));
34
+ };
35
+ case 4:
36
+ return function() {
37
+ return i(t(n(e.apply(this, arguments))));
38
+ };
39
+ case 5:
40
+ return function() {
41
+ return o(i(t(n(e.apply(this, arguments)))));
42
+ };
43
+ case 6:
44
+ return function() {
45
+ return s(o(i(t(n(e.apply(this, arguments))))));
46
+ };
47
+ case 7:
48
+ return function() {
49
+ return a(s(o(i(t(n(e.apply(this, arguments)))))));
50
+ };
51
+ case 8:
52
+ return function() {
53
+ return g(a(s(o(i(t(n(e.apply(this, arguments))))))));
54
+ };
55
+ case 9:
56
+ return function() {
57
+ return u(g(a(s(o(i(t(n(e.apply(this, arguments)))))))));
58
+ };
59
+ }
60
+ }
61
+ function r(e, n, t, i, o, s, a, g, u) {
62
+ switch (arguments.length) {
63
+ case 1:
64
+ return e;
65
+ case 2:
66
+ return n(e);
67
+ case 3:
68
+ return t(n(e));
69
+ case 4:
70
+ return i(t(n(e)));
71
+ case 5:
72
+ return o(i(t(n(e))));
73
+ case 6:
74
+ return s(o(i(t(n(e)))));
75
+ case 7:
76
+ return a(s(o(i(t(n(e))))));
77
+ case 8:
78
+ return g(a(s(o(i(t(n(e)))))));
79
+ case 9:
80
+ return u(g(a(s(o(i(t(n(e))))))));
81
+ default: {
82
+ for (var h = arguments[0], x = 1; x < arguments.length; x++)
83
+ h = arguments[x](h);
84
+ return h;
85
+ }
86
+ }
87
+ }
88
+ var te = function(e, n) {
89
+ var t = typeof e == "number" ? function(i) {
90
+ return i.length >= e;
91
+ } : e;
92
+ return function() {
93
+ var i = Array.from(arguments);
94
+ return t(arguments) ? n.apply(this, i) : function(o) {
95
+ return n.apply(void 0, Ze([o], i, !1));
96
+ };
97
+ };
98
+ };
99
+ globalThis && globalThis.__spreadArray;
100
+ var ve = function(e) {
101
+ return e._tag === "Some";
102
+ }, Ee = { _tag: "None" }, Ae = function(e) {
103
+ return { _tag: "Some", value: e };
104
+ }, tn = function(e) {
105
+ return e.length > 0;
106
+ }, on = [], sn = Object.prototype.hasOwnProperty;
107
+ function rn(e) {
108
+ return function(n, t) {
109
+ return e.chain(n, function(i) {
110
+ return e.map(t(i), function() {
111
+ return i;
112
+ });
113
+ });
114
+ };
115
+ }
116
+ var v = function(e) {
117
+ return {
118
+ equals: function(n, t) {
119
+ return n === t || e(n, t);
120
+ }
121
+ };
122
+ }, S = function(e) {
123
+ return v(function(n, t) {
124
+ for (var i in e)
125
+ if (!e[i].equals(n[i], t[i]))
126
+ return !1;
127
+ return !0;
128
+ });
129
+ }, be = {
130
+ equals: function(e, n) {
131
+ return e === n;
132
+ }
133
+ };
134
+ be.equals;
135
+ var y = Ee, P = Ae;
136
+ function H(e) {
137
+ return function(n) {
138
+ return e(n) ? P(n) : y;
139
+ };
140
+ }
141
+ var an = function(e, n) {
142
+ return r(e, A(n));
143
+ }, un = function(e, n) {
144
+ return r(e, fn(n));
145
+ }, cn = "Option", ln = function(e) {
146
+ return {
147
+ equals: function(n, t) {
148
+ return n === t || (E(n) ? E(t) : E(t) ? !1 : e.equals(n.value, t.value));
149
+ }
150
+ };
151
+ }, A = function(e) {
152
+ return function(n) {
153
+ return E(n) ? y : P(e(n.value));
154
+ };
155
+ }, fn = function(e) {
156
+ return function(n) {
157
+ return E(n) || E(e) ? y : P(n.value(e.value));
158
+ };
159
+ }, Pe = /* @__PURE__ */ te(2, function(e, n) {
160
+ return E(e) ? y : n(e.value);
161
+ }), gn = {
162
+ URI: cn,
163
+ map: an,
164
+ ap: un,
165
+ chain: Pe
166
+ }, I = function(e) {
167
+ return function(n) {
168
+ return E(n) ? y : e(n.value) ? n : y;
169
+ };
170
+ }, E = function(e) {
171
+ return e._tag === "None";
172
+ }, dn = function(e, n) {
173
+ return function(t) {
174
+ return E(t) ? e() : n(t.value);
175
+ };
176
+ }, ie = dn, pn = function(e) {
177
+ return function(n) {
178
+ return E(n) ? e() : n.value;
179
+ };
180
+ }, U = pn, mn = /* @__PURE__ */ te(2, rn(gn)), l = function(e) {
181
+ return e == null ? y : P(e);
182
+ }, W = /* @__PURE__ */ ie(en, O), D = /* @__PURE__ */ ie(ye, O), hn = Pe, Cn = mn, oe = {
183
+ equals: function(e, n) {
184
+ return e === n;
185
+ }
186
+ }, yn = {
187
+ equals: oe.equals,
188
+ compare: function(e, n) {
189
+ return e < n ? -1 : e > n ? 1 : 0;
190
+ }
191
+ };
192
+ oe.equals, yn.compare;
193
+ globalThis && globalThis.__spreadArray;
194
+ var Sn = on, vn = tn;
195
+ globalThis && globalThis.__spreadArray;
196
+ var En = function(e) {
197
+ return e.length === 0;
198
+ }, Ie = vn, An = function(e) {
199
+ return function(n) {
200
+ if (En(n))
201
+ return In;
202
+ for (var t = [], i = 0; i < n.length; i++)
203
+ t.push.apply(t, e(i, n[i]));
204
+ return t;
205
+ };
206
+ };
207
+ function qe(e) {
208
+ return function(n) {
209
+ for (var t = 0; t < n.length; t++)
210
+ if (e(n[t]))
211
+ return Ae(n[t]);
212
+ return Ee;
213
+ };
214
+ }
215
+ var bn = function(e, n, t) {
216
+ for (var i = [], o = Math.min(e.length, n.length), s = 0; s < o; s++)
217
+ i[s] = t(e[s], n[s]);
218
+ return i;
219
+ };
220
+ function Me(e, n) {
221
+ return n === void 0 ? function(t) {
222
+ return Me(t, e);
223
+ } : bn(e, n, function(t, i) {
224
+ return [t, i];
225
+ });
226
+ }
227
+ var we = /* @__PURE__ */ te(2, function(e, n) {
228
+ return r(e, An(function(t, i) {
229
+ return n(i, t);
230
+ }));
231
+ }), xe = /* @__PURE__ */ we(O), b = function(e) {
232
+ return function(n) {
233
+ return n.map(function(t) {
234
+ return e(t);
235
+ });
236
+ };
237
+ }, p = function(e) {
238
+ return function(n) {
239
+ return n.filter(e);
240
+ };
241
+ }, Pn = function(e) {
242
+ return function(n) {
243
+ for (var t = [], i = 0; i < n.length; i++) {
244
+ var o = e(i, n[i]);
245
+ ve(o) && t.push(o.value);
246
+ }
247
+ return t;
248
+ };
249
+ }, w = function(e) {
250
+ return Pn(function(n, t) {
251
+ return e(t);
252
+ });
253
+ }, Y = /* @__PURE__ */ w(O), K = function(e) {
254
+ return v(function(n, t) {
255
+ return n.length === t.length && n.every(function(i, o) {
256
+ return e.equals(i, t[o]);
257
+ });
258
+ });
259
+ }, In = Sn;
260
+ function qn(e) {
261
+ return function(n) {
262
+ return n.every(e);
263
+ };
264
+ }
265
+ var Mn = we, c = {
266
+ equals: function(e, n) {
267
+ return e === n;
268
+ }
269
+ };
270
+ c.equals;
271
+ var Re = {
272
+ equals: function(e, n) {
273
+ return e === n;
274
+ }
275
+ };
276
+ Re.equals;
277
+ function Ue(e) {
278
+ return function(n, t) {
279
+ if (t === void 0) {
280
+ var i = Ue(e);
281
+ return function(s) {
282
+ return i(s, n);
283
+ };
284
+ }
285
+ for (var o in n)
286
+ if (!sn.call(t, o) || !e.equals(n[o], t[o]))
287
+ return !1;
288
+ return !0;
289
+ };
290
+ }
291
+ function De(e) {
292
+ var n = Ue(e);
293
+ return v(function(t, i) {
294
+ return n(t)(i) && n(i)(t);
295
+ });
296
+ }
297
+ function se(e) {
298
+ return {
299
+ equals(n, t) {
300
+ return n == null && t == null ? !0 : n == null || t === null || t === void 0 ? !1 : e.equals(n, t);
301
+ }
302
+ };
303
+ }
304
+ function $(e) {
305
+ return {
306
+ equals(n, t) {
307
+ const i = r(l(n), U(() => [])), o = r(l(t), U(() => []));
308
+ return K(e).equals(i, o);
309
+ }
310
+ };
311
+ }
312
+ const N = S({
313
+ localId: c,
314
+ componentPath: $(c),
315
+ sharedConfigurationModelId: se(c)
316
+ }), wn = S({
317
+ localId: c,
318
+ configurationModelId: c
319
+ }), xn = v((e, n) => Je({ x: e, y: n }).with({
320
+ x: {
321
+ type: "Choice"
322
+ /* Choice */
323
+ },
324
+ y: {
325
+ type: "Choice"
326
+ /* Choice */
327
+ }
328
+ }, (t) => Rn.equals(t.x, t.y)).with({
329
+ x: {
330
+ type: "Component"
331
+ /* Component */
332
+ },
333
+ y: {
334
+ type: "Component"
335
+ /* Component */
336
+ }
337
+ }, (t) => Un.equals(t.x, t.y)).with({
338
+ x: {
339
+ type: "Numeric"
340
+ /* Numeric */
341
+ },
342
+ y: {
343
+ type: "Numeric"
344
+ /* Numeric */
345
+ }
346
+ }, (t) => Dn.equals(t.x, t.y)).with({
347
+ x: {
348
+ type: "Boolean"
349
+ /* Boolean */
350
+ },
351
+ y: {
352
+ type: "Boolean"
353
+ /* Boolean */
354
+ }
355
+ }, (t) => Nn.equals(t.x, t.y)).otherwise(() => !1)), Rn = S({
356
+ type: c,
357
+ attributeId: N,
358
+ state: c,
359
+ choiceValueId: c
360
+ }), Un = S({
361
+ type: c,
362
+ attributeId: N,
363
+ state: c
364
+ }), Dn = S({
365
+ type: c,
366
+ attributeId: N,
367
+ state: oe
368
+ }), Nn = S({
369
+ type: c,
370
+ attributeId: N,
371
+ state: Re
372
+ });
373
+ var q = /* @__PURE__ */ ((e) => (e.whyIsNotSatisfied = "why-is-not-satisfied", e.whyIsStateNotPossible = "why-is-state-not-possible", e))(q || {}), M = /* @__PURE__ */ ((e) => (e.choiceValue = "choice-value", e.component = "component", e.boolean = "boolean", e.numeric = "numeric", e.configuration = "configuration", e.attribute = "attribute", e))(M || {}), f = /* @__PURE__ */ ((e) => (e.Boolean = "Boolean", e.Numeric = "Numeric", e.Choice = "Choice", e.Component = "Component", e))(f || {}), G = /* @__PURE__ */ ((e) => (e.Implicit = "Implicit", e.Explicit = "Explicit", e))(G || {});
374
+ const ge = S({
375
+ localId: c,
376
+ componentPath: $(c),
377
+ sharedConfigurationModel: se(c)
378
+ }), _n = ln(K(S({
379
+ attributeId: ge,
380
+ decisions: $(ge)
381
+ })));
382
+ S({
383
+ configurationModelSource: v((e, n) => me(e, n)),
384
+ decisionsToRespect: _n,
385
+ usageRuleParameters: De(c)
386
+ });
387
+ S({
388
+ localId: c,
389
+ componentPath: $(c),
390
+ sharedConfigurationModelId: se(c)
391
+ });
392
+ function Tn(e, n) {
393
+ return r(
394
+ e.values,
395
+ w((t) => r(
396
+ t.decision,
397
+ l,
398
+ I((i) => i.kind === n)
399
+ ))
400
+ );
401
+ }
402
+ function kn(e) {
403
+ return r(
404
+ e.decision,
405
+ l,
406
+ I((n) => n.kind === G.Explicit),
407
+ W
408
+ );
409
+ }
410
+ function zn(e) {
411
+ return r(
412
+ e.decision,
413
+ l,
414
+ I((n) => n.kind === G.Explicit),
415
+ W
416
+ );
417
+ }
418
+ function On(e) {
419
+ return r(
420
+ e.decision,
421
+ l,
422
+ W
423
+ );
424
+ }
425
+ const Ne = (e) => e.type === f.Boolean, _e = (e) => e.type === f.Choice, Te = (e) => e.type === f.Numeric, ke = (e) => e.type === f.Component, $n = $(c);
426
+ function jn(e, n, t) {
427
+ var i;
428
+ const o = ((i = n.componentPath) == null ? void 0 : i.length) ?? 0;
429
+ return r(e, p((s) => {
430
+ var a;
431
+ const g = ((a = s.id.componentPath) == null ? void 0 : a.length) ?? 0;
432
+ return t ? o > g ? !1 : r(
433
+ s.id.componentPath ?? [],
434
+ Me(n.componentPath ?? []),
435
+ qn(([u, h]) => u === h)
436
+ ) : $n.equals(s.id.componentPath, n.componentPath);
437
+ }));
438
+ }
439
+ function Bn(e, n, t) {
440
+ return [];
441
+ }
442
+ function Fn(e) {
443
+ return r(e, p((n) => {
444
+ const t = r(
445
+ n.id.componentPath,
446
+ l,
447
+ A((o) => o.length === 0),
448
+ U(() => !0)
449
+ ), i = r(
450
+ n.id.sharedConfigurationModelId,
451
+ l,
452
+ ie(() => !0, () => !1)
453
+ );
454
+ return t && i;
455
+ }));
456
+ }
457
+ function Vn(e, n) {
458
+ return r(
459
+ ze(e),
460
+ b((t) => Tn(t, n)),
461
+ xe,
462
+ w((t) => l(t))
463
+ );
464
+ }
465
+ function Hn(e, n) {
466
+ return r(
467
+ $e(e),
468
+ p((t) => {
469
+ var i;
470
+ return ((i = t.decision) == null ? void 0 : i.kind) === n;
471
+ }),
472
+ b((t) => kn(t)),
473
+ w((t) => l(t))
474
+ );
475
+ }
476
+ function Wn(e, n) {
477
+ return r(
478
+ je(e),
479
+ p((t) => {
480
+ var i;
481
+ return ((i = t.decision) == null ? void 0 : i.kind) === n;
482
+ }),
483
+ b((t) => zn(t)),
484
+ w((t) => l(t))
485
+ );
486
+ }
487
+ function Kn(e, n) {
488
+ return r(
489
+ Oe(e),
490
+ p((t) => {
491
+ var i;
492
+ return ((i = t.decision) == null ? void 0 : i.kind) === n;
493
+ }),
494
+ b((t) => On(t)),
495
+ w((t) => l(t))
496
+ );
497
+ }
498
+ function ze(e) {
499
+ return r(
500
+ e.attributes,
501
+ p(_e)
502
+ );
503
+ }
504
+ function Oe(e) {
505
+ return r(
506
+ e.attributes,
507
+ p(ke)
508
+ );
509
+ }
510
+ function $e(e) {
511
+ return r(
512
+ e.attributes,
513
+ p(Te)
514
+ );
515
+ }
516
+ function je(e) {
517
+ return r(
518
+ e.attributes,
519
+ p(Ne)
520
+ );
521
+ }
522
+ function Gn(e, n) {
523
+ return r(
524
+ j(e, n),
525
+ D
526
+ );
527
+ }
528
+ function Jn(e, n) {
529
+ return r(
530
+ Be(e, n),
531
+ D
532
+ );
533
+ }
534
+ function Ln(e, n, t) {
535
+ return r(
536
+ Be(e, n),
537
+ A((i) => i.values),
538
+ hn(Se(qe((i) => i.id === t))),
539
+ D
540
+ );
541
+ }
542
+ function Xn(e, n) {
543
+ return r(
544
+ j(e, n),
545
+ I(Te),
546
+ D
547
+ );
548
+ }
549
+ function Yn(e, n) {
550
+ return r(
551
+ j(e, n),
552
+ I(Ne),
553
+ D
554
+ );
555
+ }
556
+ function Qn(e, n) {
557
+ return r(
558
+ j(e, n),
559
+ I(ke),
560
+ D
561
+ );
562
+ }
563
+ function j(e, n) {
564
+ return r(
565
+ e.attributes,
566
+ qe((t) => N.equals(t.id, n))
567
+ );
568
+ }
569
+ function Be(e, n) {
570
+ return r(
571
+ j(e, n),
572
+ I(_e)
573
+ );
574
+ }
575
+ const _ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
576
+ __proto__: null,
577
+ filterAttributesOfComponent: jn,
578
+ filterAttributesOfRoot: Fn,
579
+ filterAttributesOfShared: Bn,
580
+ getAttribute: Gn,
581
+ getBooleanAttribute: Yn,
582
+ getBooleanAttributes: je,
583
+ getBooleanDecisions: Wn,
584
+ getChoiceAttribute: Jn,
585
+ getChoiceAttributes: ze,
586
+ getChoiceDecisions: Vn,
587
+ getChoiceValue: Ln,
588
+ getComponentAttribute: Qn,
589
+ getComponentAttributes: Oe,
590
+ getComponentDecisions: Kn,
591
+ getNumericAttribute: Xn,
592
+ getNumericAttributes: $e,
593
+ getNumericDecisions: Hn
594
+ }, Symbol.toStringTag, { value: "Module" }));
595
+ q.whyIsNotSatisfied, M.configuration;
596
+ const de = N.equals;
597
+ wn.equals;
598
+ xn.equals;
599
+ function ee(e) {
600
+ return v(
601
+ (n, t) => {
602
+ const i = n == null, o = t == null;
603
+ return i && o || !i && !o && e.equals(n, t);
604
+ }
605
+ );
606
+ }
607
+ const Fe = F(null), Ve = F(null), He = F(null), We = F(null), re = () => V(Fe), T = () => V(We), Ke = "The configuration is not initialized. Consider using the ConfigurationSuspender or unload components manually that make use of any unsafe hook while the configuration is initializing. Check the hooks documentation to see if it is safe to use while the configuration is initializing.";
608
+ function ae(e) {
609
+ if (!e)
610
+ throw new Error(Ke);
611
+ }
612
+ function k(e) {
613
+ if (!e)
614
+ throw new Error(Ke);
615
+ }
616
+ function J() {
617
+ const e = re();
618
+ return ae(e), m(() => ({
619
+ makeDecision: (n) => e.makeDecision(n),
620
+ setManyDecision: (n, t) => e.setMany(n, t)
621
+ }), [e]);
622
+ }
623
+ var L = function(e) {
624
+ return function(n) {
625
+ return ve(e(n));
626
+ };
627
+ };
628
+ const Zn = L((e) => e.type === f.Choice ? P(e) : y), et = L((e) => e.type === f.Numeric ? P(e) : y), nt = L((e) => e.type === f.Boolean ? P(e) : y), tt = L((e) => e.type === f.Component ? P(e) : y);
629
+ function X(e) {
630
+ return e.decision != null && e.decision.kind === G.Explicit;
631
+ }
632
+ function Ge(e) {
633
+ return r(
634
+ e.values,
635
+ p(X),
636
+ b((n) => ({
637
+ type: f.Choice,
638
+ attributeId: e.id,
639
+ choiceValueId: n.id,
640
+ state: null
641
+ }))
642
+ );
643
+ }
644
+ function it(e) {
645
+ return r(
646
+ e,
647
+ H(X),
648
+ A(() => ({
649
+ type: f.Numeric,
650
+ attributeId: e.id,
651
+ state: null
652
+ }))
653
+ );
654
+ }
655
+ function ot(e) {
656
+ return r(
657
+ e,
658
+ H(X),
659
+ A(() => ({
660
+ type: f.Boolean,
661
+ attributeId: e.id,
662
+ state: null
663
+ }))
664
+ );
665
+ }
666
+ function st(e) {
667
+ return r(
668
+ e,
669
+ H(X),
670
+ A(() => ({
671
+ type: f.Component,
672
+ attributeId: e.id,
673
+ state: null
674
+ }))
675
+ );
676
+ }
677
+ function rt(e, n) {
678
+ return r(
679
+ _.filterAttributesOfComponent(n, e, !0),
680
+ (t) => [
681
+ r(
682
+ t,
683
+ p(Zn),
684
+ Mn(Ge)
685
+ ),
686
+ r(
687
+ t,
688
+ p(et),
689
+ b(it),
690
+ Y
691
+ ),
692
+ r(
693
+ t,
694
+ p(nt),
695
+ b(ot),
696
+ Y
697
+ ),
698
+ r(
699
+ t,
700
+ p(tt),
701
+ b(st),
702
+ Y
703
+ )
704
+ ],
705
+ xe
706
+ );
707
+ }
708
+ function It(e, n) {
709
+ const t = T();
710
+ return k(t), m(
711
+ () => r(
712
+ l(e),
713
+ A(Se(
714
+ b((i) => _.getAttribute(t, i)),
715
+ n ?? !1 ? O : w(l)
716
+ )),
717
+ U(() => t.attributes)
718
+ ),
719
+ [e, t, n]
720
+ );
721
+ }
722
+ function qt(e) {
723
+ const n = T(), { makeDecision: t, setManyDecision: i } = J();
724
+ k(n);
725
+ const o = _.getChoiceAttribute(n, e), s = m(() => ({
726
+ // explainConsequence: (choiceValueId: ChoiceValueId, mode?: ExplainMode) => explainChoiceAttributeConsequence(attributeId, choiceValueId, mode),
727
+ // explainConsequences: (mode?: ExplainMode) => explainChoiceAttributeConsequences(attributeId, mode),
728
+ makeDecision: (g, u) => t({
729
+ type: f.Choice,
730
+ attributeId: e,
731
+ choiceValueId: g,
732
+ state: u
733
+ }),
734
+ clearDecisions: r(
735
+ o,
736
+ l,
737
+ A(Ge),
738
+ // Only setMany if there are decisions to clear.
739
+ I(Ie),
740
+ A((g) => () => i(g, { type: "Default" })),
741
+ U(() => () => Promise.resolve())
742
+ )
743
+ // applySolution: applySolution
744
+ }), [e, o, t, i]), a = m(() => ({
745
+ ...s,
746
+ attribute: o
747
+ }), [o, s]);
748
+ if (o)
749
+ return a;
750
+ }
751
+ function Mt(e) {
752
+ const n = T(), { makeDecision: t } = J();
753
+ k(n);
754
+ const i = _.getNumericAttribute(n, e), o = m(() => ({
755
+ makeDecision: (a) => t({
756
+ type: f.Numeric,
757
+ attributeId: e,
758
+ state: a
759
+ })
760
+ }), [e, t]), s = m(() => ({
761
+ ...o,
762
+ attribute: i
763
+ }), [i, o]);
764
+ if (i)
765
+ return s;
766
+ }
767
+ function wt(e) {
768
+ const n = T(), { makeDecision: t } = J();
769
+ k(n);
770
+ const i = _.getBooleanAttribute(n, e), o = m(() => ({
771
+ makeDecision: (a) => t({
772
+ type: f.Boolean,
773
+ attributeId: e,
774
+ state: a
775
+ })
776
+ }), [e, t]), s = m(() => ({
777
+ ...o,
778
+ attribute: i
779
+ }), [i, o]);
780
+ if (i)
781
+ return s;
782
+ }
783
+ function xt(e) {
784
+ const n = T(), { makeDecision: t, setManyDecision: i } = J();
785
+ k(n);
786
+ const o = n.attributes, s = _.getComponentAttribute(n, e), a = m(() => ({
787
+ makeDecision: (u) => t({
788
+ type: f.Component,
789
+ attributeId: e,
790
+ state: u
791
+ }),
792
+ clearSubtree: r(
793
+ rt(e, o),
794
+ // Only setMany if there are decisions to clear.
795
+ H(Ie),
796
+ A((u) => () => i(u, { type: "Default" })),
797
+ U(() => () => Promise.resolve())
798
+ )
799
+ }), [e, t, o, i]), g = m(() => ({
800
+ ...a,
801
+ attribute: s
802
+ }), [s, a]);
803
+ if (s)
804
+ return g;
805
+ }
806
+ const at = v((e, n) => De(c).equals(e ?? {}, n ?? {})), ut = S({
807
+ attributeId: v(de),
808
+ decisions: K(v(de))
809
+ }), ct = v((e, n) => K(ut).equals(e ?? [], n ?? [])), Q = S({
810
+ configurationModelSource: v((e, n) => me(e, n)),
811
+ attributeRelations: ct,
812
+ usageRuleParameters: at
813
+ }), lt = be, Z = ee(lt), ft = () => ne({
814
+ predictableActionArguments: !0,
815
+ preserveActionOrder: !0,
816
+ schema: {
817
+ context: {},
818
+ events: {}
819
+ },
820
+ context: {
821
+ desiredClient: null,
822
+ desiredSessionContext: null,
823
+ actualClient: null,
824
+ session: null,
825
+ sessionCreationError: null,
826
+ sessionUpdateError: null,
827
+ hasEverSuccessfullyCreatedSession: !1
828
+ },
829
+ initial: "ProcessChanges",
830
+ on: {
831
+ ChangeConfigurationClient: {
832
+ actions: ["saveDesiredClient"]
833
+ },
834
+ ChangeSessionContext: {
835
+ actions: ["saveDesiredSessionContext"]
836
+ }
837
+ },
838
+ exit: [
839
+ C("Shutting down", "SessionManagement:"),
840
+ "disposeOldSession"
841
+ ],
842
+ states: {
843
+ ProcessChanges: {
844
+ entry: [
845
+ C("Entering ProcessChanges", "SessionManagement:"),
846
+ R(
847
+ 2
848
+ /* Other */
849
+ )
850
+ ],
851
+ always: [
852
+ { target: "DisposeSession", cond: "shallDisposeSession" },
853
+ { target: "CreateSession", cond: "shallCreateSession" },
854
+ { target: "UpdateSession", cond: "shallUpdateSession" }
855
+ ]
856
+ },
857
+ DisposeSession: {
858
+ entry: [
859
+ C("Entering DisposeSession", "SessionManagement:"),
860
+ R(
861
+ 2
862
+ /* Other */
863
+ )
864
+ ],
865
+ always: {
866
+ actions: ["disposeOldSession"],
867
+ target: "ProcessChanges"
868
+ }
869
+ },
870
+ CreateSession: {
871
+ entry: [
872
+ C("Entering CreateSession", "SessionManagement:"),
873
+ R(
874
+ 0
875
+ /* CreateSession */
876
+ )
877
+ ],
878
+ invoke: {
879
+ id: "getNewSession",
880
+ src: "createSession",
881
+ onDone: {
882
+ actions: ["setSessionCreationResult", "setHasEverSuccessfullyCreatedSession"],
883
+ target: "ProcessChanges"
884
+ },
885
+ onError: {
886
+ actions: "setSessionCreationError",
887
+ target: "SessionCreationFailed"
888
+ }
889
+ }
890
+ },
891
+ SessionCreationFailed: {
892
+ entry: [
893
+ C("Entering SessionCreationFailed", "SessionManagement:"),
894
+ R(
895
+ 2
896
+ /* Other */
897
+ )
898
+ ],
899
+ always: {
900
+ // Immediately process changes if there were changes during session creation attempt
901
+ // This will also be triggered if session context or client changes
902
+ target: "ProcessChanges",
903
+ cond: "shallImmediatelyProcessChangesAfterSessionCreationError"
904
+ },
905
+ exit: [
906
+ C("Exiting SessionCreationFailed", "SessionManagement:"),
907
+ "clearSessionCreationError"
908
+ ],
909
+ on: {
910
+ RetrySessionCreation: {
911
+ target: "ProcessChanges",
912
+ actions: C("Retrying session creation", "SessionManagement:")
913
+ }
914
+ }
915
+ },
916
+ UpdateSession: {
917
+ entry: [
918
+ C("Entering UpdateSession", "SessionManagement:"),
919
+ R(
920
+ 1
921
+ /* UpdateSession */
922
+ )
923
+ ],
924
+ invoke: {
925
+ id: "updateExistingSession",
926
+ src: "updateSession",
927
+ onDone: {
928
+ target: "ProcessChanges"
929
+ },
930
+ onError: {
931
+ actions: "setSessionUpdateError",
932
+ target: "SessionUpdateFailed"
933
+ }
934
+ }
935
+ },
936
+ SessionUpdateFailed: {
937
+ entry: [
938
+ C("Entering SessionUpdateFailed", "SessionManagement:"),
939
+ R(
940
+ 2
941
+ /* Other */
942
+ )
943
+ ],
944
+ always: {
945
+ // Immediately process changes if there were changes during session update attempt
946
+ // This will also be triggered if session context or client changes
947
+ target: "ProcessChanges",
948
+ cond: "shallImmediatelyProcessChangesAfterSessionUpdateError"
949
+ },
950
+ exit: [
951
+ C("Exiting SessionUpdateFailed", "SessionManagement:"),
952
+ "clearSessionUpdateError"
953
+ ],
954
+ on: {
955
+ RetrySessionUpdate: {
956
+ target: "ProcessChanges",
957
+ actions: C("Retrying session update", "SessionManagement:")
958
+ }
959
+ }
960
+ }
961
+ }
962
+ }, {
963
+ actions: {
964
+ saveDesiredClient: d({
965
+ desiredClient: (e, n) => n.client
966
+ }),
967
+ saveDesiredSessionContext: d({
968
+ desiredSessionContext: (e, n) => n.sessionContext
969
+ }),
970
+ disposeOldSession: d((e, n) => (e.session && e.session.close().then(nn).catch((t) => {
971
+ }), {
972
+ session: null,
973
+ actualClient: null
974
+ })),
975
+ setSessionCreationResult: d((e, n) => ({
976
+ session: n.data.session,
977
+ actualClient: n.data.client
978
+ })),
979
+ setSessionCreationError: d((e, n) => ({
980
+ sessionCreationError: n.data
981
+ })),
982
+ clearSessionCreationError: d({ sessionCreationError: () => null }),
983
+ setSessionUpdateError: d((e, n) => ({
984
+ sessionUpdateError: n.data
985
+ })),
986
+ clearSessionUpdateError: d({ sessionUpdateError: () => null }),
987
+ setHasEverSuccessfullyCreatedSession: d({
988
+ hasEverSuccessfullyCreatedSession: () => !0
989
+ })
990
+ },
991
+ services: {
992
+ createSession: (e) => e.desiredClient.createSession(e.desiredSessionContext).then((n) => ({
993
+ session: n,
994
+ client: e.desiredClient
995
+ })).catch((n) => Promise.reject({
996
+ type: n.type,
997
+ client: e.desiredClient,
998
+ sessionContext: e.desiredSessionContext
999
+ })),
1000
+ updateSession: (e) => e.session.setSessionContext(e.desiredSessionContext).catch((n) => Promise.reject({
1001
+ type: n.type,
1002
+ sessionContext: e.desiredSessionContext
1003
+ }))
1004
+ },
1005
+ guards: {
1006
+ shallDisposeSession: (e) => e.session != null && (e.desiredSessionContext == null || e.desiredClient == null || !Z.equals(e.actualClient, e.desiredClient)),
1007
+ shallCreateSession: (e) => e.session == null && e.desiredClient != null && e.desiredSessionContext != null,
1008
+ shallUpdateSession: (e) => e.session != null && !Q.equals(e.session.getSessionContext(), e.desiredSessionContext),
1009
+ shallImmediatelyProcessChangesAfterSessionCreationError: (e) => (
1010
+ // The desired client and the desired session context is not the same that resulted in the error.
1011
+ !Z.equals(e.desiredClient, e.sessionCreationError.client) || !ee(Q).equals(e.desiredSessionContext, e.sessionCreationError.sessionContext)
1012
+ ),
1013
+ shallImmediatelyProcessChangesAfterSessionUpdateError: (e) => (
1014
+ // The desired client was changed
1015
+ !Z.equals(e.desiredClient, e.actualClient) || !ee(Q).equals(e.desiredSessionContext, e.sessionUpdateError.sessionContext)
1016
+ )
1017
+ }
1018
+ });
1019
+ function R(e) {
1020
+ const n = e === 0, t = e === 1;
1021
+ return Ye((i, o) => {
1022
+ const s = {
1023
+ isInitializing: (!i.hasEverSuccessfullyCreatedSession || n) && i.sessionCreationError == null,
1024
+ errorType: i.sessionCreationError && i.sessionCreationError.type
1025
+ }, a = {
1026
+ isUpdating: t && i.sessionUpdateError == null,
1027
+ errorType: i.sessionUpdateError && i.sessionUpdateError.type
1028
+ };
1029
+ return he({
1030
+ type: "SessionManagementStateChanged",
1031
+ sessionInitialization: s,
1032
+ sessionUpdating: a,
1033
+ session: i.session
1034
+ });
1035
+ });
1036
+ }
1037
+ const gt = (e) => (n) => (n({
1038
+ type: "ConfigurationChanged",
1039
+ session: e,
1040
+ configuration: e.getConfiguration()
1041
+ }), e.setOnConfigurationChangedHandler((t) => {
1042
+ n({
1043
+ type: "ConfigurationChanged",
1044
+ session: e,
1045
+ configuration: t
1046
+ });
1047
+ }), () => {
1048
+ e.setOnConfigurationChangedHandler(null);
1049
+ }), dt = () => ne({
1050
+ predictableActionArguments: !0,
1051
+ preserveActionOrder: !0,
1052
+ schema: {
1053
+ context: {},
1054
+ events: {}
1055
+ },
1056
+ context: {
1057
+ session: null
1058
+ },
1059
+ on: {
1060
+ // Forward the configuration data to the parent.
1061
+ ConfigurationChanged: {
1062
+ actions: [
1063
+ he((e, n) => n)
1064
+ ]
1065
+ }
1066
+ },
1067
+ initial: "ProcessChanges",
1068
+ states: {
1069
+ ProcessChanges: {
1070
+ entry: [
1071
+ C("Entering ProcessChanges", "ConfigurationSubscriptionManagement:")
1072
+ ],
1073
+ on: {
1074
+ ChangeSession: {
1075
+ actions: [
1076
+ "saveSession"
1077
+ ]
1078
+ }
1079
+ },
1080
+ always: [
1081
+ {
1082
+ target: "Subscribe",
1083
+ cond: (e, n) => e.session != null
1084
+ }
1085
+ ]
1086
+ },
1087
+ Subscribe: {
1088
+ entry: [
1089
+ C("Entering Subscribe", "ConfigurationSubscriptionManagement:")
1090
+ ],
1091
+ on: {
1092
+ ChangeSession: {
1093
+ target: "ProcessChanges",
1094
+ cond: (e, n) => n.session == null || e.session !== n.session,
1095
+ actions: [
1096
+ "saveSession"
1097
+ ]
1098
+ }
1099
+ },
1100
+ invoke: {
1101
+ id: "configurationSubscriptionActor",
1102
+ src: (e, n) => gt(e.session)
1103
+ }
1104
+ }
1105
+ }
1106
+ }, {
1107
+ actions: {
1108
+ saveSession: d((e, n) => ({
1109
+ session: n.session
1110
+ }))
1111
+ }
1112
+ }), pt = () => {
1113
+ let e, n;
1114
+ return {
1115
+ promise: new Promise((i, o) => {
1116
+ e = i, n = o;
1117
+ }),
1118
+ resolve: e,
1119
+ reject: n
1120
+ };
1121
+ }, pe = () => {
1122
+ const e = pt();
1123
+ return {
1124
+ capsule: { promise: e.promise },
1125
+ resolve: e.resolve,
1126
+ reject: e.reject
1127
+ };
1128
+ }, mt = () => ne({
1129
+ predictableActionArguments: !0,
1130
+ preserveActionOrder: !0,
1131
+ schema: {
1132
+ context: {},
1133
+ events: {}
1134
+ },
1135
+ context: {
1136
+ sessionManagementActor: null,
1137
+ configurationSubscriptionManagementActor: null,
1138
+ sessionInitialization: null,
1139
+ sessionUpdating: null,
1140
+ session: null,
1141
+ configuration: null,
1142
+ isReadyPromise: pe()
1143
+ },
1144
+ entry: [
1145
+ d({
1146
+ sessionManagementActor: () => le(ft()),
1147
+ configurationSubscriptionManagementActor: () => le(dt())
1148
+ })
1149
+ ],
1150
+ exit: [
1151
+ fe((e) => e.sessionManagementActor),
1152
+ fe((e) => e.configurationSubscriptionManagementActor)
1153
+ ],
1154
+ on: {
1155
+ // Forward events for sessionManagement
1156
+ ChangeConfigurationClient: {
1157
+ actions: [
1158
+ B((e) => e.sessionManagementActor)
1159
+ ]
1160
+ },
1161
+ ChangeSessionContext: {
1162
+ actions: [
1163
+ B((e) => e.sessionManagementActor)
1164
+ ]
1165
+ },
1166
+ RetrySessionCreation: {
1167
+ actions: [
1168
+ B((e) => e.sessionManagementActor)
1169
+ ]
1170
+ },
1171
+ RetrySessionUpdate: {
1172
+ actions: [
1173
+ B((e) => e.sessionManagementActor)
1174
+ ]
1175
+ },
1176
+ SessionManagementStateChanged: {
1177
+ actions: [
1178
+ // Assign the received data
1179
+ d((e, n) => ({
1180
+ session: n.session,
1181
+ sessionInitialization: n.sessionInitialization,
1182
+ sessionUpdating: n.sessionUpdating
1183
+ })),
1184
+ // Forward the session to the configuration subscription
1185
+ Xe((e) => ({
1186
+ type: "ChangeSession",
1187
+ session: e.session
1188
+ }), { to: (e) => e.configurationSubscriptionManagementActor }),
1189
+ "calculateReadyState"
1190
+ ]
1191
+ },
1192
+ ConfigurationChanged: {
1193
+ actions: [
1194
+ d((e, n) => ({
1195
+ configuration: {
1196
+ session: n.session,
1197
+ configuration: n.configuration
1198
+ }
1199
+ })),
1200
+ "calculateReadyState"
1201
+ ]
1202
+ }
1203
+ },
1204
+ initial: "Idle",
1205
+ states: {
1206
+ Idle: {}
1207
+ }
1208
+ }, {
1209
+ actions: {
1210
+ calculateReadyState: d((e, n) => {
1211
+ var o;
1212
+ const t = !((o = e.sessionInitialization) != null && o.isInitializing) && e.session != null && e.configuration != null && e.configuration.session === e.session;
1213
+ return e.isReadyPromise && t && (e.isReadyPromise.resolve(), e.isReadyPromise.capsule.promise = null), {
1214
+ isReadyPromise: (() => t ? null : e.isReadyPromise != null ? e.isReadyPromise : pe())()
1215
+ };
1216
+ })
1217
+ }
1218
+ });
1219
+ function ht(e) {
1220
+ var a, g;
1221
+ const [n, t] = Qe(mt, {
1222
+ logger: (...u) => console.log("ConfigurationManagement:", ...u)
1223
+ });
1224
+ ce(() => {
1225
+ t({
1226
+ type: "ChangeConfigurationClient",
1227
+ client: e.configuratorClient
1228
+ }), e.configuratorClient || console.warn("The configurator client is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass a valid client.");
1229
+ }, [e.configuratorClient]), ce(() => {
1230
+ const u = r(
1231
+ l(e.sessionContext),
1232
+ Cn((h) => l(h.configurationModelSource)),
1233
+ W
1234
+ );
1235
+ t({
1236
+ type: "ChangeSessionContext",
1237
+ sessionContext: u
1238
+ }), u || console.warn("The session context is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass valid session context data.");
1239
+ }, [e.sessionContext]);
1240
+ const i = m(
1241
+ () => {
1242
+ var u, h, x, ue;
1243
+ return {
1244
+ isInitializing: ((h = (u = n.context.isReadyPromise) == null ? void 0 : u.capsule) == null ? void 0 : h.promise) != null,
1245
+ isInitializingPromise: (x = n.context.isReadyPromise) == null ? void 0 : x.capsule,
1246
+ error: ((ue = n.context.sessionInitialization) == null ? void 0 : ue.errorType) && {
1247
+ type: n.context.sessionInitialization.errorType,
1248
+ retry: () => t({ type: "RetrySessionCreation" })
1249
+ }
1250
+ };
1251
+ },
1252
+ [n.context.sessionInitialization, n.context.isReadyPromise]
1253
+ ), o = m(
1254
+ () => {
1255
+ var u, h;
1256
+ return {
1257
+ isUpdating: (u = n.context.sessionUpdating) == null ? void 0 : u.isUpdating,
1258
+ error: ((h = n.context.sessionUpdating) == null ? void 0 : h.errorType) && {
1259
+ type: n.context.sessionUpdating.errorType,
1260
+ retry: () => t({ type: "RetrySessionUpdate" })
1261
+ }
1262
+ };
1263
+ },
1264
+ [n.context.sessionUpdating]
1265
+ ), s = ((a = n.context.configuration) == null ? void 0 : a.session) === n.context.session ? (g = n.context.configuration) == null ? void 0 : g.configuration : null;
1266
+ return {
1267
+ configurationInitialization: i,
1268
+ configurationUpdating: o,
1269
+ session: n.context.session,
1270
+ configuration: s
1271
+ };
1272
+ }
1273
+ function Rt(e) {
1274
+ const { configurationInitialization: n, configurationUpdating: t, session: i, configuration: o } = ht({
1275
+ configuratorClient: e.configuratorClient,
1276
+ sessionContext: e
1277
+ });
1278
+ return /* @__PURE__ */ z(Ve.Provider, { value: n, children: /* @__PURE__ */ z(He.Provider, { value: t, children: /* @__PURE__ */ z(Fe.Provider, { value: i, children: /* @__PURE__ */ z(We.Provider, { value: o, children: e.children }) }) }) });
1279
+ }
1280
+ function Ct() {
1281
+ return V(Ve);
1282
+ }
1283
+ function Ut() {
1284
+ return V(He);
1285
+ }
1286
+ function Dt(e) {
1287
+ const { children: n } = e, { isInitializingPromise: t } = Ct();
1288
+ if (t != null && t.promise)
1289
+ throw t.promise;
1290
+ return /* @__PURE__ */ z(Le, { children: n });
1291
+ }
1292
+ function Nt() {
1293
+ const e = re();
1294
+ return ae(e), m(() => ({
1295
+ // explainChoiceAttributeConsequence: (a, v, m) => configurationSession.explain({
1296
+ // type: ExplainType.ChoiceValue,
1297
+ // attributeId: a,
1298
+ // choiceValueId: v,
1299
+ // question: m
1300
+ // } as ExplainChoiceValue),
1301
+ // explainChoiceAttributeConsequences: (a, m) => configurationSession.explain({
1302
+ // type: ExplainType.Choice,
1303
+ // attributeId: a,
1304
+ // question: m
1305
+ // } as ExplainChoice),
1306
+ // applySolution: (s) => configurationSession.applySolution(s)
1307
+ }), [e]);
1308
+ }
1309
+ function _t() {
1310
+ const e = re(), n = T();
1311
+ return ae(e), k(n), m(() => ({
1312
+ configuration: n,
1313
+ restoreConfiguration: (t) => e.restoreConfiguration(t)
1314
+ }), [n, e]);
1315
+ }
1316
+ export {
1317
+ Rt as Configuration,
1318
+ Dt as ConfigurationSuspender,
1319
+ It as useAttributes,
1320
+ wt as useBooleanAttribute,
1321
+ qt as useChoiceAttribute,
1322
+ xt as useComponentAttribute,
1323
+ _t as useConfiguration,
1324
+ Ct as useConfigurationInitialization,
1325
+ Ut as useConfigurationUpdating,
1326
+ J as useDecision,
1327
+ Nt as useExplain,
1328
+ Mt as useNumericAttribute
1329
+ };