@capytale/iframe-react 1.1.6 → 1.1.8

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.es.js CHANGED
@@ -1,47 +1,759 @@
1
- import { jsx as h, jsxs as j, Fragment as M } from "react/jsx-runtime";
2
- import v, { useCallback as S, useEffect as l, useMemo as w } from "react";
3
- import { getSocket as I } from "@capytale/app-agent";
4
- const k = (t) => {
1
+ import { jsx as Q, jsxs as gt, Fragment as mt } from "react/jsx-runtime";
2
+ import D, { useCallback as T, useEffect as w, useMemo as U } from "react";
3
+ const et = Symbol("Comlink.proxy"), pt = Symbol("Comlink.endpoint"), yt = Symbol("Comlink.releaseProxy"), q = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), nt = (t) => typeof t == "object" && t !== null || typeof t == "function", vt = {
4
+ canHandle: (t) => nt(t) && t[et],
5
+ serialize(t) {
6
+ const { port1: e, port2: n } = new MessageChannel();
7
+ return _(t, e), [n, [n]];
8
+ },
9
+ deserialize(t) {
10
+ return t.start(), st(t);
11
+ }
12
+ }, Ct = {
13
+ canHandle: (t) => nt(t) && L in t,
14
+ serialize({ value: t }) {
15
+ let e;
16
+ return t instanceof Error ? e = {
17
+ isError: !0,
18
+ value: {
19
+ message: t.message,
20
+ name: t.name,
21
+ stack: t.stack
22
+ }
23
+ } : e = { isError: !1, value: t }, [e, []];
24
+ },
25
+ deserialize(t) {
26
+ throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
27
+ }
28
+ }, ot = /* @__PURE__ */ new Map([
29
+ ["proxy", vt],
30
+ ["throw", Ct]
31
+ ]);
32
+ function St(t, e) {
33
+ for (const n of t)
34
+ if (e === n || n === "*" || n instanceof RegExp && n.test(e))
35
+ return !0;
36
+ return !1;
37
+ }
38
+ function _(t, e = globalThis, n = ["*"]) {
39
+ e.addEventListener("message", function s(o) {
40
+ if (!o || !o.data)
41
+ return;
42
+ if (!St(n, o.origin)) {
43
+ console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
44
+ return;
45
+ }
46
+ const { id: r, type: g, path: c } = Object.assign({ path: [] }, o.data), f = (o.data.argumentList || []).map(J);
47
+ let d;
48
+ try {
49
+ const u = c.slice(0, -1).reduce((y, C) => y[C], t), m = c.reduce((y, C) => y[C], t);
50
+ switch (g) {
51
+ case "GET":
52
+ d = m;
53
+ break;
54
+ case "SET":
55
+ u[c.slice(-1)[0]] = J(o.data.value), d = !0;
56
+ break;
57
+ case "APPLY":
58
+ d = m.apply(u, f);
59
+ break;
60
+ case "CONSTRUCT":
61
+ {
62
+ const y = new m(...f);
63
+ d = ct(y);
64
+ }
65
+ break;
66
+ case "ENDPOINT":
67
+ {
68
+ const { port1: y, port2: C } = new MessageChannel();
69
+ _(t, C), d = Et(y, [y]);
70
+ }
71
+ break;
72
+ case "RELEASE":
73
+ d = void 0;
74
+ break;
75
+ default:
76
+ return;
77
+ }
78
+ } catch (u) {
79
+ d = { value: u, [L]: 0 };
80
+ }
81
+ Promise.resolve(d).catch((u) => ({ value: u, [L]: 0 })).then((u) => {
82
+ const [m, y] = O(u);
83
+ e.postMessage(Object.assign(Object.assign({}, m), { id: r }), y), g === "RELEASE" && (e.removeEventListener("message", s), rt(e), q in t && typeof t[q] == "function" && t[q]());
84
+ }).catch((u) => {
85
+ const [m, y] = O({
86
+ value: new TypeError("Unserializable return value"),
87
+ [L]: 0
88
+ });
89
+ e.postMessage(Object.assign(Object.assign({}, m), { id: r }), y);
90
+ });
91
+ }), e.start && e.start();
92
+ }
93
+ function wt(t) {
94
+ return t.constructor.name === "MessagePort";
95
+ }
96
+ function rt(t) {
97
+ wt(t) && t.close();
98
+ }
99
+ function st(t, e) {
100
+ const n = /* @__PURE__ */ new Map();
101
+ return t.addEventListener("message", function(o) {
102
+ const { data: r } = o;
103
+ if (!r || !r.id)
104
+ return;
105
+ const g = n.get(r.id);
106
+ if (g)
107
+ try {
108
+ g(r);
109
+ } finally {
110
+ n.delete(r.id);
111
+ }
112
+ }), z(t, n, [], e);
113
+ }
114
+ function P(t) {
115
+ if (t)
116
+ throw new Error("Proxy has been released and is not useable");
117
+ }
118
+ function it(t) {
119
+ return R(t, /* @__PURE__ */ new Map(), {
120
+ type: "RELEASE"
121
+ }).then(() => {
122
+ rt(t);
123
+ });
124
+ }
125
+ const j = /* @__PURE__ */ new WeakMap(), $ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
126
+ const e = (j.get(t) || 0) - 1;
127
+ j.set(t, e), e === 0 && it(t);
128
+ });
129
+ function ht(t, e) {
130
+ const n = (j.get(e) || 0) + 1;
131
+ j.set(e, n), $ && $.register(t, e, t);
132
+ }
133
+ function At(t) {
134
+ $ && $.unregister(t);
135
+ }
136
+ function z(t, e, n = [], s = function() {
137
+ }) {
138
+ let o = !1;
139
+ const r = new Proxy(s, {
140
+ get(g, c) {
141
+ if (P(o), c === yt)
142
+ return () => {
143
+ At(r), it(t), e.clear(), o = !0;
144
+ };
145
+ if (c === "then") {
146
+ if (n.length === 0)
147
+ return { then: () => r };
148
+ const f = R(t, e, {
149
+ type: "GET",
150
+ path: n.map((d) => d.toString())
151
+ }).then(J);
152
+ return f.then.bind(f);
153
+ }
154
+ return z(t, e, [...n, c]);
155
+ },
156
+ set(g, c, f) {
157
+ P(o);
158
+ const [d, u] = O(f);
159
+ return R(t, e, {
160
+ type: "SET",
161
+ path: [...n, c].map((m) => m.toString()),
162
+ value: d
163
+ }, u).then(J);
164
+ },
165
+ apply(g, c, f) {
166
+ P(o);
167
+ const d = n[n.length - 1];
168
+ if (d === pt)
169
+ return R(t, e, {
170
+ type: "ENDPOINT"
171
+ }).then(J);
172
+ if (d === "bind")
173
+ return z(t, e, n.slice(0, -1));
174
+ const [u, m] = Y(f);
175
+ return R(t, e, {
176
+ type: "APPLY",
177
+ path: n.map((y) => y.toString()),
178
+ argumentList: u
179
+ }, m).then(J);
180
+ },
181
+ construct(g, c) {
182
+ P(o);
183
+ const [f, d] = Y(c);
184
+ return R(t, e, {
185
+ type: "CONSTRUCT",
186
+ path: n.map((u) => u.toString()),
187
+ argumentList: f
188
+ }, d).then(J);
189
+ }
190
+ });
191
+ return ht(r, t), r;
192
+ }
193
+ function bt(t) {
194
+ return Array.prototype.concat.apply([], t);
195
+ }
196
+ function Y(t) {
197
+ const e = t.map(O);
198
+ return [e.map((n) => n[0]), bt(e.map((n) => n[1]))];
199
+ }
200
+ const at = /* @__PURE__ */ new WeakMap();
201
+ function Et(t, e) {
202
+ return at.set(t, e), t;
203
+ }
204
+ function ct(t) {
205
+ return Object.assign(t, { [et]: !0 });
206
+ }
207
+ function kt(t, e = globalThis, n = "*") {
208
+ return {
209
+ postMessage: (s, o) => t.postMessage(s, n, o),
210
+ addEventListener: e.addEventListener.bind(e),
211
+ removeEventListener: e.removeEventListener.bind(e)
212
+ };
213
+ }
214
+ function O(t) {
215
+ for (const [e, n] of ot)
216
+ if (n.canHandle(t)) {
217
+ const [s, o] = n.serialize(t);
218
+ return [
219
+ {
220
+ type: "HANDLER",
221
+ name: e,
222
+ value: s
223
+ },
224
+ o
225
+ ];
226
+ }
227
+ return [
228
+ {
229
+ type: "RAW",
230
+ value: t
231
+ },
232
+ at.get(t) || []
233
+ ];
234
+ }
235
+ function J(t) {
236
+ switch (t.type) {
237
+ case "HANDLER":
238
+ return ot.get(t.name).deserialize(t.value);
239
+ case "RAW":
240
+ return t.value;
241
+ }
242
+ }
243
+ function R(t, e, n, s) {
244
+ return new Promise((o) => {
245
+ const r = Jt();
246
+ e.set(r, o), t.start && t.start(), t.postMessage(Object.assign({ id: r }, n), s);
247
+ });
248
+ }
249
+ function Jt() {
250
+ return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
251
+ }
252
+ function Ft(t, e) {
253
+ return t.length === 0 ? e : `[${t}] ${e}`;
254
+ }
255
+ function xt(t, e) {
256
+ let n = !1, s, o, r;
257
+ function g(u) {
258
+ return Ft(t, u);
259
+ }
260
+ let c, f = !1;
261
+ if (window.parent === window)
262
+ console.warn(g("Contract link is not supported in standalone mode")), c = {
263
+ ready() {
264
+ return Promise.resolve();
265
+ },
266
+ declare() {
267
+ return Promise.resolve();
268
+ },
269
+ done() {
270
+ return Promise.resolve();
271
+ },
272
+ provide(u, m, y) {
273
+ return Promise.resolve();
274
+ }
275
+ };
276
+ else {
277
+ const u = kt(window.parent, void 0, e);
278
+ _({
279
+ declare(m) {
280
+ if (s == null) throw new Error(g("No handler for declare"));
281
+ s(m);
282
+ },
283
+ done() {
284
+ if (o == null) throw new Error(g("No handler for done"));
285
+ o();
286
+ },
287
+ provide(m, y, C) {
288
+ if (r == null) throw new Error(g("No handler for provide"));
289
+ r(m, y, C);
290
+ }
291
+ }, u), c = st(u), f = !0;
292
+ }
293
+ const d = () => {
294
+ if (!n) {
295
+ if (s == null || o == null || r == null) return;
296
+ n = !0, c.ready();
297
+ }
298
+ };
299
+ return {
300
+ declare: (u) => c.declare(u),
301
+ done: () => c.done(),
302
+ provide: (u, m, y) => c.provide(u, m, ct(y)),
303
+ get name() {
304
+ return t;
305
+ },
306
+ get isReady() {
307
+ return f;
308
+ },
309
+ set onDeclare(u) {
310
+ s = u, d();
311
+ },
312
+ set onDone(u) {
313
+ o = u, d();
314
+ },
315
+ set onProvide(u) {
316
+ r = u, d();
317
+ }
318
+ };
319
+ }
320
+ function Rt(t) {
321
+ return function(e) {
322
+ let n, s = !1, o = !1, r, g, c = !1, f = !1, d, u, m, y;
323
+ function C() {
324
+ if (r != null && r !== 0 && g != null)
325
+ return g;
326
+ }
327
+ function E(i) {
328
+ if (r != null && g != null && !(i > r))
329
+ return g;
330
+ }
331
+ function A() {
332
+ return m ?? (f ? m = Promise.resolve() : m = new Promise((i, l) => {
333
+ y = i;
334
+ }));
335
+ }
336
+ function F() {
337
+ return d === void 0 && (d = {
338
+ get name() {
339
+ return e;
340
+ },
341
+ get version() {
342
+ return r;
343
+ },
344
+ get i() {
345
+ return C();
346
+ },
347
+ v: (i) => E(i)
348
+ }), d;
349
+ }
350
+ function V() {
351
+ return u === void 0 && (u = {
352
+ get name() {
353
+ return e;
354
+ },
355
+ get version() {
356
+ return f ? r : void 0;
357
+ },
358
+ get i() {
359
+ return f ? C() : void 0;
360
+ },
361
+ v: (i) => f ? E(i) : void 0,
362
+ get promise() {
363
+ return r === 0 ? Promise.reject(t("Remote interface not provided")) : A().then(() => {
364
+ if (r === 0) throw new Error(t("Remote interface not provided"));
365
+ return F();
366
+ });
367
+ }
368
+ }), u;
369
+ }
370
+ function k() {
371
+ y != null && (y(), y = void 0);
372
+ }
373
+ return {
374
+ get name() {
375
+ return e;
376
+ },
377
+ get localVersion() {
378
+ if (n != null)
379
+ return n;
380
+ },
381
+ set localVersion(i) {
382
+ if (n != null && n !== i) throw new Error(t("A different local version is already set"));
383
+ n = i;
384
+ },
385
+ get localVersionSent() {
386
+ return s;
387
+ },
388
+ set localVersionSent(i) {
389
+ if (!i && s) throw new Error(t("Local version already notified"));
390
+ s = i, i && n === 0 && (o = !0);
391
+ },
392
+ get localInterfaceSent() {
393
+ return o;
394
+ },
395
+ set localInterfaceSent(i) {
396
+ if (n == null) throw new Error(t("Local version not set"));
397
+ if (!i && o) throw new Error(t("Local interface already sent."));
398
+ o = i;
399
+ },
400
+ get remoteVersion() {
401
+ if (r != null)
402
+ return r;
403
+ },
404
+ set remoteVersion(i) {
405
+ if (r != null && r !== i) throw new Error(t("A different remote version is already set for " + e + `(${r} -> ${i})`));
406
+ r = i, i === 0 && (c = !0);
407
+ },
408
+ get remoteVersionReceived() {
409
+ return r != null;
410
+ },
411
+ setRemoteInterface: (i) => {
412
+ if (r == null) throw new Error(t("Remote version not set"));
413
+ if (r === 0) {
414
+ console.warn(t("Remote version is 0, remote interface is ignored."));
415
+ return;
416
+ }
417
+ if (c) throw new Error(t("Interface already provided."));
418
+ g = i, c = !0;
419
+ },
420
+ get remoteInterfaceReceived() {
421
+ return c;
422
+ },
423
+ depGroup: void 0,
424
+ get isActivable() {
425
+ return c && o;
426
+ },
427
+ get isActivated() {
428
+ return f;
429
+ },
430
+ activate() {
431
+ if (!f) {
432
+ if (!c) throw new Error(t("Remote interface not provided."));
433
+ if (!o) throw new Error(t("Local interface not sent"));
434
+ f = !0, k();
435
+ }
436
+ },
437
+ getRemote: () => F(),
438
+ getLazyRemote: () => V(),
439
+ get activationPromise() {
440
+ return A();
441
+ }
442
+ };
443
+ };
444
+ }
445
+ function Tt(t) {
446
+ return function(e, n, s, o) {
447
+ let r = s, g = !1, c = !1;
448
+ function f() {
449
+ return e.every((d) => d.remoteVersionReceived && d.localVersionSent) && n.every((d) => d.remoteVersionReceived);
450
+ }
451
+ return {
452
+ get isDeclared() {
453
+ return c;
454
+ },
455
+ set isDeclared(d) {
456
+ if (!d && c)
457
+ throw new Error(t("Factory already declared"));
458
+ c = d;
459
+ },
460
+ get isReady() {
461
+ return f();
462
+ },
463
+ get isDone() {
464
+ return g;
465
+ },
466
+ get args() {
467
+ return e;
468
+ },
469
+ get deps() {
470
+ return n;
471
+ },
472
+ invoke() {
473
+ if (g)
474
+ throw new Error(t("Factory already invoked"));
475
+ if (!f())
476
+ throw new Error(t("Factory is not ready"));
477
+ let d;
478
+ o ? d = e.map((y) => y.getRemote()) : d = e[0].getRemote();
479
+ let u;
480
+ const m = n.length > 0 ? n.map((y) => y.getRemote()) : null;
481
+ try {
482
+ u = m == null ? r(d) : r(d, m);
483
+ } catch (y) {
484
+ throw new Error(t("error in factory:"), { cause: y });
485
+ }
486
+ if (o || (u = [u]), u.length != e.length)
487
+ throw new Error(t("Invalid factory result"));
488
+ return g = !0, r = null, u;
489
+ }
490
+ };
491
+ };
492
+ }
493
+ function Vt(t) {
494
+ return function(e, n, s, o) {
495
+ let r = n, g = !1;
496
+ function c() {
497
+ return e.every((f) => f.isActivated);
498
+ }
499
+ return {
500
+ get isReady() {
501
+ return c();
502
+ },
503
+ get isDone() {
504
+ return g;
505
+ },
506
+ get args() {
507
+ return e;
508
+ },
509
+ invoke() {
510
+ if (g || !c()) {
511
+ const u = new Error(t(g ? "callback already invoked" : "callback parameters are not ready"));
512
+ throw o?.[1](u), u;
513
+ }
514
+ const f = s ? e.map((u) => u.getRemote()) : e[0].getRemote();
515
+ let d;
516
+ try {
517
+ d = r(f);
518
+ } catch (u) {
519
+ o == null ? console.error(t("error in callback:"), u) : o[1](u);
520
+ } finally {
521
+ g = !0;
522
+ }
523
+ o?.[0](d);
524
+ }
525
+ };
526
+ };
527
+ }
528
+ function lt(t, e) {
529
+ return t == null || t.length === 0 ? e : `[${t}] ${e}`;
530
+ }
531
+ function Dt(t) {
532
+ function e(i) {
533
+ return lt(t.name, i);
534
+ }
535
+ const n = Vt(e), s = Rt(e), o = Tt(e), r = {}, g = [];
536
+ let c = [], f;
537
+ const d = () => (f == null ? f = 0 : f++, f);
538
+ function u(i) {
539
+ let l = r[i];
540
+ return l == null && (l = s(i), l.localVersion == null && (A && (l.localVersion = 0), F && (l.localVersionSent = !0)), l.remoteVersion == null && V && (l.remoteVersion = 0), r[i] = l), l;
541
+ }
542
+ function m(i) {
543
+ return i.map(u);
544
+ }
545
+ function y(...i) {
546
+ const l = d(), p = Array(l).fill(!1);
547
+ i.forEach((v) => {
548
+ v.forEach((S) => {
549
+ S.depGroup != null && (p[S.depGroup] = !0), S.depGroup = l;
550
+ });
551
+ }), Object.values(r).forEach((v) => {
552
+ v.depGroup != null && v.depGroup !== l && p[v.depGroup] && (v.depGroup = l);
553
+ });
554
+ }
555
+ t.onDeclare = (i) => {
556
+ const l = m(i.map((p) => p.name));
557
+ for (let p = 0; p < i.length; p++)
558
+ i[p].version != null && (l[p].remoteVersion = i[p].version);
559
+ y(l), k();
560
+ }, t.onDone = () => {
561
+ V || (V = !0, Object.values(r).forEach((i) => {
562
+ i.remoteVersion == null && (i.remoteVersion = 0);
563
+ }), k());
564
+ }, t.onProvide = (i, l, p) => {
565
+ let v = r[i];
566
+ if (v == null)
567
+ throw new Error(e(`Contract not declared : ${i}`));
568
+ if (v.remoteVersion != l)
569
+ throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${i}" but provided version ${l}.`));
570
+ if (v.remoteInterfaceReceived)
571
+ throw new Error(e(`Remote contract "${i}" is already provided.`));
572
+ v.setRemoteInterface(p), k();
573
+ };
574
+ let C = !1, E = !1, A = !1, F = !1, V = !1;
575
+ async function k() {
576
+ if (E = !0, !C) {
577
+ for (C = !0; E; ) {
578
+ if (E = !1, t.isReady) {
579
+ const i = g.filter((l) => !l.isDeclared);
580
+ if (i.length > 0)
581
+ for (const l of i) {
582
+ const p = Array(l.args.length + l.deps.length);
583
+ l.args.forEach((v, S) => p[S] = v), l.deps.forEach((v, S) => p[S + l.args.length] = v), await t.declare(p.map((v) => ({ name: v.name, version: v.localVersion }))), p.forEach((v) => {
584
+ v.localVersion != null && (v.localVersionSent = !0);
585
+ }), l.isDeclared = !0;
586
+ }
587
+ }
588
+ if (t.isReady && A && g.every((i) => i.isDeclared)) {
589
+ const i = Object.values(r).filter((l) => !l.localVersionSent && l.localVersion != null);
590
+ if (i.length > 0)
591
+ for (const l of i)
592
+ await t.declare([{ name: l.name, version: l.localVersion }]), l.localVersionSent = !0;
593
+ F || (F = !0, await t.done());
594
+ }
595
+ if (t.isReady) {
596
+ const i = g.filter((l) => !l.isDone && l.isReady);
597
+ if (i.length > 0)
598
+ for (const l of i) {
599
+ const p = l.invoke();
600
+ for (let v = 0; v < l.args.length; v++) {
601
+ const S = l.args[v];
602
+ await t.provide(S.name, S.localVersion, p[v]), S.localInterfaceSent = !0;
603
+ }
604
+ }
605
+ }
606
+ if (f != null) {
607
+ const i = Array(f + 1).fill(null);
608
+ for (const l in r) {
609
+ const p = r[l];
610
+ p.depGroup != null && (p.isActivable ? i[p.depGroup] == null && !p.isActivated && (i[p.depGroup] = !0) : i[p.depGroup] = !1);
611
+ }
612
+ if (i.some((l) => l === !0))
613
+ for (const l in r) {
614
+ const p = r[l];
615
+ p.depGroup != null && i[p.depGroup] && p.activate();
616
+ }
617
+ }
618
+ if (t.isReady) {
619
+ const i = c;
620
+ c = [];
621
+ const l = [];
622
+ for (const p of i)
623
+ !p.isDone && p.isReady ? p.invoke() : l.push(p);
624
+ l.push(...c), c = l;
625
+ }
626
+ }
627
+ C = !1;
628
+ }
629
+ }
630
+ return {
631
+ get(i) {
632
+ return u(i);
633
+ },
634
+ declareFactory: (i, l, p, v) => {
635
+ if (A) throw new Error(e("Cannot declare a factory after done has been set to true."));
636
+ const S = m(i.map((b) => b.name));
637
+ {
638
+ const b = S.filter((N) => N.localVersion != null);
639
+ if (b.length > 0)
640
+ throw new Error(e("Cannot declare a factory for already implemented contracts : " + b.map((N) => N.name).join(", ")));
641
+ }
642
+ for (let b = 0; b < i.length; b++)
643
+ S[b].localVersion = i[b].version;
644
+ const x = m(l);
645
+ y(S, x);
646
+ const ft = o(S, x, p, v);
647
+ g.push(ft), k();
648
+ },
649
+ declareCallback(i, l, p, v) {
650
+ const S = m(i), x = n(S, l, p, v);
651
+ !C && c.length === 0 && x.isReady ? x.invoke() : (c.push(x), k());
652
+ },
653
+ get done() {
654
+ return A;
655
+ },
656
+ set done(i) {
657
+ if (A) {
658
+ if (!i) throw new Error(e("Cannot set done to false after it has been set to true."));
659
+ } else
660
+ i && (A = !0, Object.values(r).forEach((l) => {
661
+ l.localVersion == null && (l.localVersion = 0);
662
+ }), k());
663
+ }
664
+ };
665
+ }
666
+ const Pt = /^\d+$/;
667
+ function Mt(t) {
668
+ const [e, n, s] = t.split(":", 3);
669
+ if (n == null || s != null || !Pt.test(n)) return null;
670
+ const o = parseInt(n);
671
+ return isNaN(o) || o === 0 ? null : { name: e, version: o };
672
+ }
673
+ function Gt(t) {
674
+ const e = Dt(t);
675
+ function n(s) {
676
+ return lt(t.name, s);
677
+ }
678
+ return {
679
+ plug(s, o, r = void 0) {
680
+ if (e.done) throw new Error(n("Cannot plug after plugsDone."));
681
+ r == null && (r = o, o = []);
682
+ let g = !0;
683
+ Array.isArray(s) || (s = [s], g = !1);
684
+ const c = s.map((f) => {
685
+ const d = Mt(f);
686
+ if (d == null)
687
+ throw new Error(n("Invalid contract id : " + f));
688
+ return d;
689
+ });
690
+ e.declareFactory(c, o, r, g);
691
+ },
692
+ plugsDone() {
693
+ e.done = !0;
694
+ },
695
+ use(s, o) {
696
+ let r = !0;
697
+ Array.isArray(s) || (s = [s], r = !1), e.declareCallback(s, o, r);
698
+ },
699
+ exec(s, o) {
700
+ let r = !0;
701
+ return Array.isArray(s) || (s = [s], r = !1), new Promise((...g) => {
702
+ e.declareCallback(s, o, r, g);
703
+ });
704
+ },
705
+ get(s) {
706
+ return s.map((o) => e.get(o).getLazyRemote());
707
+ }
708
+ };
709
+ }
710
+ const ut = "app-agent";
711
+ let B;
712
+ function It(t) {
713
+ return B != null || (B = Gt(xt(ut, t))), B;
714
+ }
715
+ console.log(`[${ut}@1.0.12] loaded`);
716
+ const K = (t) => {
5
717
  let e;
6
- const o = /* @__PURE__ */ new Set(), s = (C, p) => {
7
- const d = typeof C == "function" ? C(e) : C;
8
- if (!Object.is(d, e)) {
9
- const J = e;
10
- e = p ?? (typeof d != "object" || d === null) ? d : Object.assign({}, e, d), o.forEach((m) => m(e, J));
11
- }
12
- }, i = () => e, a = { setState: s, getState: i, getInitialState: () => r, subscribe: (C) => (o.add(C), () => o.delete(C)) }, r = e = t(s, i, a);
13
- return a;
14
- }, L = (t) => t ? k(t) : k, $ = (t) => t;
15
- function q(t, e = $) {
16
- const o = v.useSyncExternalStore(
718
+ const n = /* @__PURE__ */ new Set(), s = (d, u) => {
719
+ const m = typeof d == "function" ? d(e) : d;
720
+ if (!Object.is(m, e)) {
721
+ const y = e;
722
+ e = u ?? (typeof m != "object" || m === null) ? m : Object.assign({}, e, m), n.forEach((C) => C(e, y));
723
+ }
724
+ }, o = () => e, c = { setState: s, getState: o, getInitialState: () => f, subscribe: (d) => (n.add(d), () => n.delete(d)) }, f = e = t(s, o, c);
725
+ return c;
726
+ }, Lt = (t) => t ? K(t) : K, jt = (t) => t;
727
+ function $t(t, e = jt) {
728
+ const n = D.useSyncExternalStore(
17
729
  t.subscribe,
18
- v.useCallback(() => e(t.getState()), [t, e]),
19
- v.useCallback(() => e(t.getInitialState()), [t, e])
730
+ D.useCallback(() => e(t.getState()), [t, e]),
731
+ D.useCallback(() => e(t.getInitialState()), [t, e])
20
732
  );
21
- return v.useDebugValue(o), o;
22
- }
23
- const x = (t) => {
24
- const e = L(t), o = (s) => q(e, s);
25
- return Object.assign(o, e), o;
26
- }, E = (t) => t ? x(t) : x, B = (t) => (e, o, s) => {
27
- const i = s.subscribe;
28
- return s.subscribe = (u, a, r) => {
29
- let C = u;
30
- if (a) {
31
- const p = r?.equalityFn || Object.is;
32
- let d = u(s.getState());
33
- C = (J) => {
34
- const m = u(J);
35
- if (!p(d, m)) {
36
- const G = d;
37
- a(d = m, G);
733
+ return D.useDebugValue(n), n;
734
+ }
735
+ const X = (t) => {
736
+ const e = Lt(t), n = (s) => $t(e, s);
737
+ return Object.assign(n, e), n;
738
+ }, dt = (t) => t ? X(t) : X, Ot = (t) => (e, n, s) => {
739
+ const o = s.subscribe;
740
+ return s.subscribe = (g, c, f) => {
741
+ let d = g;
742
+ if (c) {
743
+ const u = f?.equalityFn || Object.is;
744
+ let m = g(s.getState());
745
+ d = (y) => {
746
+ const C = g(y);
747
+ if (!u(m, C)) {
748
+ const E = m;
749
+ c(m = C, E);
38
750
  }
39
- }, r?.fireImmediately && a(d, d);
751
+ }, f?.fireImmediately && c(m, m);
40
752
  }
41
- return i(C);
42
- }, t(e, o, s);
43
- }, P = B, n = E()(
44
- P((t) => ({
753
+ return o(d);
754
+ }, t(e, n, s);
755
+ }, Nt = Ot, a = dt()(
756
+ Nt((t) => ({
45
757
  ready: !1,
46
758
  workflow: "current",
47
759
  mode: "assignment",
@@ -109,8 +821,8 @@ const x = (t) => {
109
821
  incDirtyCount: () => t((e) => ({ isDirtyCount: e.isDirtyCount + 1 }))
110
822
  }))
111
823
  );
112
- let T = !1;
113
- const R = [
824
+ let Z = !1;
825
+ const qt = [
114
826
  "meta-player-events:1",
115
827
  "meta-player-ui:1",
116
828
  "mode:1",
@@ -124,10 +836,10 @@ const R = [
124
836
  "simple-content-eval(json):1",
125
837
  "separate-contents(json):1",
126
838
  "separate-dual-contents(json):1"
127
- ], D = {
839
+ ], tt = {
128
840
  "mode:1": {
129
841
  setMode: (t) => {
130
- n.setState({ mode: t });
842
+ a.setState({ mode: t });
131
843
  }
132
844
  },
133
845
  "reload:1": {
@@ -138,63 +850,63 @@ const R = [
138
850
  "theme:1": {
139
851
  setTheme: (t) => {
140
852
  if (t === null) {
141
- n.setState({ theme: null });
853
+ a.setState({ theme: null });
142
854
  return;
143
855
  }
144
856
  if (t !== "light" && t !== "dark") {
145
- console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`), n.setState({ theme: null });
857
+ console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`), a.setState({ theme: null });
146
858
  return;
147
859
  }
148
- n.setState({ theme: t });
860
+ a.setState({ theme: t });
149
861
  }
150
862
  },
151
863
  "workflow:1": {
152
864
  setWorkflow: (t) => {
153
- n.setState({ workflow: t });
865
+ a.setState({ workflow: t });
154
866
  }
155
867
  },
156
868
  "simple-content(text):1": {
157
869
  contentSaved: () => {
158
- n.setState((t) => ({
870
+ a.setState((t) => ({
159
871
  afterSaveCount: t.afterSaveCount + 1
160
872
  }));
161
873
  },
162
- getContent: () => n.getState().getTextContentFunction(),
874
+ getContent: () => a.getState().getTextContentFunction(),
163
875
  loadContent: (t) => {
164
- n.setState({ loadedTextContent: t });
876
+ a.setState({ loadedTextContent: t });
165
877
  }
166
878
  },
167
879
  "simple-content(json):1": {
168
880
  contentSaved: () => {
169
- n.setState((t) => ({
881
+ a.setState((t) => ({
170
882
  afterSaveCount: t.afterSaveCount + 1
171
883
  }));
172
884
  },
173
- getContent: () => n.getState().getJsonContentFunction(),
885
+ getContent: () => a.getState().getJsonContentFunction(),
174
886
  loadContent: (t) => {
175
- n.setState({ loadedJsonContent: t });
887
+ a.setState({ loadedJsonContent: t });
176
888
  }
177
889
  },
178
890
  "simple-binary-data(text):1": {
179
891
  contentSaved: () => {
180
- n.setState((t) => ({
892
+ a.setState((t) => ({
181
893
  afterSaveCount: t.afterSaveCount + 1
182
894
  }));
183
895
  },
184
- getContent: () => n.getState().getTextContentFunction(),
896
+ getContent: () => a.getState().getTextContentFunction(),
185
897
  loadContent: (t) => {
186
- n.setState({ loadedTextContent: t });
898
+ a.setState({ loadedTextContent: t });
187
899
  }
188
900
  },
189
901
  "simple-content-eval(text):1": {
190
902
  contentSaved: () => {
191
- n.setState((t) => ({
903
+ a.setState((t) => ({
192
904
  afterSaveCount: t.afterSaveCount + 1
193
905
  }));
194
906
  },
195
- getContent: () => n.getState().getTextContentFunction(),
907
+ getContent: () => a.getState().getTextContentFunction(),
196
908
  loadContent: (t) => {
197
- n.setState({ loadedTextContent: t });
909
+ a.setState({ loadedTextContent: t });
198
910
  },
199
911
  getAssignmentContent: () => {
200
912
  throw new Error(
@@ -204,13 +916,13 @@ const R = [
204
916
  },
205
917
  "simple-content-eval(json):1": {
206
918
  contentSaved: () => {
207
- n.setState((t) => ({
919
+ a.setState((t) => ({
208
920
  afterSaveCount: t.afterSaveCount + 1
209
921
  }));
210
922
  },
211
- getContent: () => n.getState().getJsonContentFunction(),
923
+ getContent: () => a.getState().getJsonContentFunction(),
212
924
  loadContent: (t) => {
213
- n.setState({ loadedJsonContent: t });
925
+ a.setState({ loadedJsonContent: t });
214
926
  },
215
927
  getAssignmentContent: () => {
216
928
  throw new Error(
@@ -220,13 +932,13 @@ const R = [
220
932
  },
221
933
  "simple-content-eval(json):2": {
222
934
  contentSaved: () => {
223
- n.setState((t) => ({
935
+ a.setState((t) => ({
224
936
  afterSaveCount: t.afterSaveCount + 1
225
937
  }));
226
938
  },
227
- getContent: () => n.getState().getJsonContentFunction(),
939
+ getContent: () => a.getState().getJsonContentFunction(),
228
940
  loadContent: (t) => {
229
- n.setState({ loadedJsonContent: t });
941
+ a.setState({ loadedJsonContent: t });
230
942
  },
231
943
  getAssignmentContent: () => {
232
944
  throw new Error(
@@ -236,13 +948,13 @@ const R = [
236
948
  },
237
949
  "simple-content-eval(text):2": {
238
950
  contentSaved: () => {
239
- n.setState((t) => ({
951
+ a.setState((t) => ({
240
952
  afterSaveCount: t.afterSaveCount + 1
241
953
  }));
242
954
  },
243
- getContent: () => n.getState().getTextContentFunction(),
955
+ getContent: () => a.getState().getTextContentFunction(),
244
956
  loadContent: (t) => {
245
- n.setState({ loadedTextContent: t });
957
+ a.setState({ loadedTextContent: t });
246
958
  },
247
959
  getAssignmentContent: () => {
248
960
  throw new Error(
@@ -252,40 +964,40 @@ const R = [
252
964
  },
253
965
  "separate-contents(json):1": {
254
966
  contentSaved: () => {
255
- n.setState((t) => ({
967
+ a.setState((t) => ({
256
968
  afterSaveCount: t.afterSaveCount + 1
257
969
  }));
258
970
  },
259
971
  loadContent: (t, e) => {
260
- n.setState({
972
+ a.setState({
261
973
  loadedJsonActivityContent: t,
262
974
  loadedJsonAssignmentContent: e
263
975
  });
264
976
  },
265
- getActivityContent: () => n.getState().getJsonActivityContentFunction(),
266
- getAssignmentContent: () => n.getState().getJsonAssignmentContentFunction()
977
+ getActivityContent: () => a.getState().getJsonActivityContentFunction(),
978
+ getAssignmentContent: () => a.getState().getJsonAssignmentContentFunction()
267
979
  },
268
980
  "separate-dual-contents(json):1": {
269
981
  contentSaved: () => {
270
- n.setState((t) => ({
982
+ a.setState((t) => ({
271
983
  afterSaveCount: t.afterSaveCount + 1
272
984
  }));
273
985
  },
274
986
  loadContent: ({
275
987
  activityContent: t,
276
988
  assignmentContent: e,
277
- activityBinaryData: o,
989
+ activityBinaryData: n,
278
990
  assignmentBinaryData: s
279
991
  }) => {
280
- n.setState({
992
+ a.setState({
281
993
  loadedJsonActivityContent: t,
282
994
  loadedJsonAssignmentContent: e,
283
- loadedJsonActivityBinaryData: o,
995
+ loadedJsonActivityBinaryData: n,
284
996
  loadedJsonAssignmentBinaryData: s
285
997
  });
286
998
  },
287
- getActivityContentAndData: () => n.getState().getJsonActivitySplitContentFunction(),
288
- getAssignmentContentAndData: () => n.getState().getJsonAssignmentSplitContentFunction()
999
+ getActivityContentAndData: () => a.getState().getJsonActivitySplitContentFunction(),
1000
+ getAssignmentContentAndData: () => a.getState().getJsonAssignmentSplitContentFunction()
289
1001
  },
290
1002
  "meta-player-anti-cheat:1": {
291
1003
  lock: () => {
@@ -296,24 +1008,24 @@ const R = [
296
1008
  "meta-player-ui:1": {
297
1009
  executeAction(t) {
298
1010
  if (t.startsWith("qa")) {
299
- const o = n.getState().quickActions[t];
300
- o ? o() : console.error(`Quick action not found: ${t}`);
1011
+ const n = a.getState().quickActions[t];
1012
+ n ? n() : console.error(`Quick action not found: ${t}`);
301
1013
  } else {
302
- const o = n.getState().sidebarActions[t];
303
- o ? o() : console.error(`Sidebar action not found: ${t}`);
1014
+ const n = a.getState().sidebarActions[t];
1015
+ n ? n() : console.error(`Sidebar action not found: ${t}`);
304
1016
  }
305
1017
  },
306
1018
  executeFileUpload(t, e) {
307
1019
  if (t.startsWith("qa")) {
308
- const s = n.getState().quickActions[t];
1020
+ const s = a.getState().quickActions[t];
309
1021
  s ? s(e) : console.error(`Quick action not found: ${t}`);
310
1022
  } else {
311
- const s = n.getState().sidebarActions[t];
1023
+ const s = a.getState().sidebarActions[t];
312
1024
  s ? s(e) : console.error(`Sidebar action not found: ${t}`);
313
1025
  }
314
1026
  },
315
1027
  updateSettings(t) {
316
- const e = n.getState().activitySettingsCallback;
1028
+ const e = a.getState().activitySettingsCallback;
317
1029
  e ? e(t) : console.warn(
318
1030
  "activitySettingsCallback is not set. Changes:",
319
1031
  t
@@ -322,33 +1034,33 @@ const R = [
322
1034
  },
323
1035
  "meta-player-events:1": {
324
1036
  handleEvent(t) {
325
- t === "all-loaded" && n.setState({ ready: !0 });
1037
+ t === "all-loaded" && a.setState({ ready: !0 });
326
1038
  }
327
1039
  }
328
- }, g = I();
329
- function O(t) {
330
- if (T) {
1040
+ }, h = It();
1041
+ function Bt(t) {
1042
+ if (Z) {
331
1043
  console.warn("Contracts have already been plugged. Skipping.");
332
1044
  return;
333
1045
  }
334
- T = !0;
1046
+ Z = !0;
335
1047
  for (const e of t) {
336
- if (!R.includes(e)) {
1048
+ if (!qt.includes(e)) {
337
1049
  console.warn(
338
1050
  `Contract ${e} is not implemented in Capytale. Skipping plug.`
339
1051
  );
340
1052
  continue;
341
1053
  }
342
- if (!(e in D)) {
1054
+ if (!(e in tt)) {
343
1055
  console.warn(
344
1056
  `Contract handler for ${e} is not defined. Skipping plug.`
345
1057
  );
346
1058
  continue;
347
1059
  }
348
- const o = D[e];
349
- g.plug([e], ([]) => [o]);
1060
+ const n = tt[e];
1061
+ h.plug([e], ([]) => [n]);
350
1062
  }
351
- g.plugsDone();
1063
+ h.plugsDone();
352
1064
  for (const e of [
353
1065
  "simple-content(text):1",
354
1066
  "simple-content(json):1",
@@ -360,262 +1072,262 @@ function O(t) {
360
1072
  ])
361
1073
  if (console.log(`Contract ${e} is being subscribed to content changes.`), t.includes(e)) {
362
1074
  console.log(`Subscribing to content changes for contract ${e}`);
363
- const o = e.split(":")[0];
364
- g.use([o], ([s]) => {
365
- n.subscribe(
366
- (i) => i.isDirtyCount,
1075
+ const n = e.split(":")[0];
1076
+ h.use([n], ([s]) => {
1077
+ a.subscribe(
1078
+ (o) => o.isDirtyCount,
367
1079
  () => {
368
1080
  s.i?.contentChanged(), console.log(
369
- `Content changed for contract ${o}`
1081
+ `Content changed for contract ${n}`
370
1082
  );
371
1083
  }
372
1084
  );
373
1085
  });
374
1086
  }
375
1087
  }
376
- const tt = () => n((t) => {
1088
+ const ee = () => a((t) => {
377
1089
  if (t.mode === null)
378
1090
  throw new Error("Mode is not set. Have you used contract 'mode'?");
379
1091
  return t.mode;
380
- }), et = () => n((t) => {
1092
+ }), ne = () => a((t) => {
381
1093
  if (t.workflow === null)
382
1094
  throw new Error(
383
1095
  "Workflow is not set. Have you used contract 'workflow'?"
384
1096
  );
385
1097
  return t.workflow;
386
- }), nt = () => n((t) => {
1098
+ }), oe = () => a((t) => {
387
1099
  if (t.theme === null)
388
1100
  throw new Error("Theme is not set. Have you used contract 'theme'?");
389
1101
  return t.theme;
390
- }), ot = () => n((t) => t.incSaveCount), st = () => n((t) => t.incDirtyCount), it = () => n((t) => t.loadedTextContent), at = () => n((t) => t.loadedJsonContent), ct = () => n((t) => t.loadedJsonActivityContent), rt = () => n((t) => t.loadedJsonAssignmentContent), lt = () => n((t) => t.loadedJsonActivityBinaryData), ut = () => n((t) => t.loadedJsonAssignmentBinaryData), dt = () => S(() => n.getState().loadedTextContent, []), gt = () => S(() => n.getState().loadedJsonContent, []), Ct = () => S(() => n.getState().loadedJsonActivityContent, []), St = () => S(() => n.getState().loadedJsonAssignmentContent, []), pt = () => S(
1102
+ }), re = () => a((t) => t.incSaveCount), se = () => a((t) => t.incDirtyCount), ie = () => a((t) => t.loadedTextContent), ae = () => a((t) => t.loadedJsonContent), ce = () => a((t) => t.loadedJsonActivityContent), le = () => a((t) => t.loadedJsonAssignmentContent), ue = () => a((t) => t.loadedJsonActivityBinaryData), de = () => a((t) => t.loadedJsonAssignmentBinaryData), fe = () => T(() => a.getState().loadedTextContent, []), ge = () => T(() => a.getState().loadedJsonContent, []), me = () => T(() => a.getState().loadedJsonActivityContent, []), pe = () => T(() => a.getState().loadedJsonAssignmentContent, []), ye = () => T(
391
1103
  () => ({
392
- content: n.getState().loadedJsonActivityContent,
393
- binaryData: n.getState().loadedJsonActivityBinaryData
1104
+ content: a.getState().loadedJsonActivityContent,
1105
+ binaryData: a.getState().loadedJsonActivityBinaryData
394
1106
  }),
395
1107
  []
396
- ), mt = () => S(
1108
+ ), ve = () => T(
397
1109
  () => ({
398
- content: n.getState().loadedJsonAssignmentContent,
399
- binaryData: n.getState().loadedJsonAssignmentBinaryData
1110
+ content: a.getState().loadedJsonAssignmentContent,
1111
+ binaryData: a.getState().loadedJsonAssignmentBinaryData
400
1112
  }),
401
1113
  []
402
- ), vt = (t) => {
403
- const e = n(
404
- (o) => o.setGetTextContentFunction
1114
+ ), Ce = (t) => {
1115
+ const e = a(
1116
+ (n) => n.setGetTextContentFunction
405
1117
  );
406
- l(() => {
1118
+ w(() => {
407
1119
  e(t);
408
1120
  }, [t, e]);
409
- }, yt = (t) => {
410
- const e = n(
411
- (o) => o.setGetJsonContentFunction
1121
+ }, Se = (t) => {
1122
+ const e = a(
1123
+ (n) => n.setGetJsonContentFunction
412
1124
  );
413
- l(() => {
1125
+ w(() => {
414
1126
  e(t);
415
1127
  }, [t, e]);
416
- }, ft = (t) => {
417
- const e = n(
418
- (o) => o.setGetJsonActivityContentFunction
1128
+ }, we = (t) => {
1129
+ const e = a(
1130
+ (n) => n.setGetJsonActivityContentFunction
419
1131
  );
420
- l(() => {
1132
+ w(() => {
421
1133
  e(t);
422
1134
  }, [t, e]);
423
- }, At = (t) => {
424
- const e = n(
425
- (o) => o.setGetJsonAssignmentContentFunction
1135
+ }, he = (t) => {
1136
+ const e = a(
1137
+ (n) => n.setGetJsonAssignmentContentFunction
426
1138
  );
427
- l(() => {
1139
+ w(() => {
428
1140
  e(t);
429
1141
  }, [t, e]);
430
- }, Jt = (t) => {
431
- const e = n(
432
- (o) => o.setGetJsonActivitySplitContentFunction
1142
+ }, Ae = (t) => {
1143
+ const e = a(
1144
+ (n) => n.setGetJsonActivitySplitContentFunction
433
1145
  );
434
- l(() => {
1146
+ w(() => {
435
1147
  e(t);
436
1148
  }, [t, e]);
437
- }, Ft = (t) => {
438
- const e = n(
439
- (o) => o.setGetJsonAssignmentSplitContentFunction
1149
+ }, be = (t) => {
1150
+ const e = a(
1151
+ (n) => n.setGetJsonAssignmentSplitContentFunction
440
1152
  );
441
- l(() => {
1153
+ w(() => {
442
1154
  e(t);
443
1155
  }, [t, e]);
444
- }, bt = (t) => {
445
- const e = n((o) => o.afterSaveCount);
446
- l(() => {
1156
+ }, Ee = (t) => {
1157
+ const e = a((n) => n.afterSaveCount);
1158
+ w(() => {
447
1159
  e > 0 && t();
448
1160
  }, [e]);
449
- }, wt = () => (t, e) => {
450
- g.use(["meta-player-ui"], ([o]) => {
451
- if (o.version === 0) {
1161
+ }, ke = () => (t, e) => {
1162
+ h.use(["meta-player-ui"], ([n]) => {
1163
+ if (n.version === 0) {
452
1164
  console.error(
453
1165
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
454
1166
  );
455
1167
  return;
456
1168
  }
457
- o.i?.previewTextFile(t, e);
1169
+ n.i?.previewTextFile(t, e);
458
1170
  });
459
- }, ht = () => (t, e) => {
460
- g.use(["meta-player-ui"], ([o]) => {
461
- if (o.version === 0) {
1171
+ }, Je = () => (t, e) => {
1172
+ h.use(["meta-player-ui"], ([n]) => {
1173
+ if (n.version === 0) {
462
1174
  console.error(
463
1175
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
464
1176
  );
465
1177
  return;
466
1178
  }
467
- o.i?.previewImageFile(t, e);
1179
+ n.i?.previewImageFile(t, e);
468
1180
  });
469
1181
  };
470
- let y = 0, F = 0;
471
- const kt = (t, e) => {
472
- const o = w(t, e), s = n((i) => i.setSidebarActions);
473
- l(() => (y++, y > 1 && console.error(
1182
+ let M = 0, W = 0;
1183
+ const Fe = (t, e) => {
1184
+ const n = U(t, e), s = a((o) => o.setSidebarActions);
1185
+ w(() => (M++, M > 1 && console.error(
474
1186
  "Capytale iframe React: Multiple sidebar actions registered: ",
475
- y
1187
+ M
476
1188
  ), () => {
477
- y--;
478
- }), []), l(() => (g.use(["meta-player-ui"], ([i]) => {
479
- if (i.version === 0) {
1189
+ M--;
1190
+ }), []), w(() => (h.use(["meta-player-ui"], ([o]) => {
1191
+ if (o.version === 0) {
480
1192
  console.error(
481
1193
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
482
1194
  );
483
1195
  return;
484
1196
  }
485
- F++;
486
- const c = o.map((a, r) => ({
487
- type: a.type,
488
- title: a.title,
489
- icon: a.icon,
490
- id: `sa-${F}-${r}`,
491
- ...a.type === "file-upload" ? { accept: a.accept } : {}
492
- })), u = {};
493
- o.forEach((a, r) => {
494
- u[`sa-${F}-${r}`] = a.action;
495
- }), i.i?.setSidebarActionButtons(c), s(u);
1197
+ W++;
1198
+ const r = n.map((c, f) => ({
1199
+ type: c.type,
1200
+ title: c.title,
1201
+ icon: c.icon,
1202
+ id: `sa-${W}-${f}`,
1203
+ ...c.type === "file-upload" ? { accept: c.accept } : {}
1204
+ })), g = {};
1205
+ n.forEach((c, f) => {
1206
+ g[`sa-${W}-${f}`] = c.action;
1207
+ }), o.i?.setSidebarActionButtons(r), s(g);
496
1208
  }), () => {
497
- s({}), g.use(["meta-player-ui"], ([i]) => {
498
- if (i.version === 0) {
1209
+ s({}), h.use(["meta-player-ui"], ([o]) => {
1210
+ if (o.version === 0) {
499
1211
  console.error(
500
1212
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
501
1213
  );
502
1214
  return;
503
1215
  }
504
- i.i?.setSidebarActionButtons([]);
1216
+ o.i?.setSidebarActionButtons([]);
505
1217
  });
506
- }), [o]);
1218
+ }), [n]);
507
1219
  };
508
- let f = 0, b = 0;
509
- const xt = (t, e) => {
510
- const o = w(t, e), s = n((i) => i.setQuickActions);
511
- l(() => (f++, f > 1 && console.error(
1220
+ let G = 0, H = 0;
1221
+ const xe = (t, e) => {
1222
+ const n = U(t, e), s = a((o) => o.setQuickActions);
1223
+ w(() => (G++, G > 1 && console.error(
512
1224
  "Capytale iframe React: Multiple quick actions registered: ",
513
- f
1225
+ G
514
1226
  ), () => {
515
- f--;
516
- }), []), l(() => (g.use(["meta-player-ui"], ([i]) => {
517
- if (i.version === 0) {
1227
+ G--;
1228
+ }), []), w(() => (h.use(["meta-player-ui"], ([o]) => {
1229
+ if (o.version === 0) {
518
1230
  console.error(
519
1231
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
520
1232
  );
521
1233
  return;
522
1234
  }
523
- b++;
524
- const c = o.map((a, r) => ({
525
- type: a.type,
526
- title: a.title,
527
- icon: a.icon,
528
- id: `qa-${b}-${r}`,
529
- ...a.type === "file-upload" ? { accept: a.accept } : {}
530
- })), u = {};
531
- o.forEach((a, r) => {
532
- u[`qa-${b}-${r}`] = a.action;
533
- }), i.i?.setQuickActionButtons(c), s(u);
1235
+ H++;
1236
+ const r = n.map((c, f) => ({
1237
+ type: c.type,
1238
+ title: c.title,
1239
+ icon: c.icon,
1240
+ id: `qa-${H}-${f}`,
1241
+ ...c.type === "file-upload" ? { accept: c.accept } : {}
1242
+ })), g = {};
1243
+ n.forEach((c, f) => {
1244
+ g[`qa-${H}-${f}`] = c.action;
1245
+ }), o.i?.setQuickActionButtons(r), s(g);
534
1246
  }), () => {
535
- s({}), g.use(["meta-player-ui"], ([i]) => {
536
- if (i.version === 0) {
1247
+ s({}), h.use(["meta-player-ui"], ([o]) => {
1248
+ if (o.version === 0) {
537
1249
  console.error(
538
1250
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
539
1251
  );
540
1252
  return;
541
1253
  }
542
- i.i?.setQuickActionButtons([]);
1254
+ o.i?.setQuickActionButtons([]);
543
1255
  });
544
- }), [o]);
1256
+ }), [n]);
545
1257
  };
546
- let A = 0;
547
- const V = (t, e, o) => {
548
- const s = w(t, o), i = n(
549
- (c) => c.setActivitySettingsCallback
1258
+ let I = 0;
1259
+ const Wt = (t, e, n) => {
1260
+ const s = U(t, n), o = a(
1261
+ (r) => r.setActivitySettingsCallback
550
1262
  );
551
- l(() => (console.log("Mounting useSettings"), A++, A > 1 && console.error(
1263
+ w(() => (console.log("Mounting useSettings"), I++, I > 1 && console.error(
552
1264
  "Capytale iframe React: Multiple settings registered: ",
553
- A
1265
+ I
554
1266
  ), () => {
555
- console.log("Unmounting useSettings"), A--;
556
- }), []), l(() => (g.use(["meta-player-ui"], ([c]) => {
557
- if (c.version === 0) {
1267
+ console.log("Unmounting useSettings"), I--;
1268
+ }), []), w(() => (h.use(["meta-player-ui"], ([r]) => {
1269
+ if (r.version === 0) {
558
1270
  console.error(
559
1271
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
560
1272
  );
561
1273
  return;
562
1274
  }
563
- console.log("Updating settings UI in MetaPlayer", s), c.i?.setSettingsUI(s);
564
- }), i(
1275
+ console.log("Updating settings UI in MetaPlayer", s), r.i?.setSettingsUI(s);
1276
+ }), o(
565
1277
  e
566
1278
  ), () => {
567
- i(null);
1279
+ o(null);
568
1280
  }), [s]);
569
- }, Tt = () => (e) => {
570
- g.use(["meta-player-ui"], ([o]) => {
571
- if (o.version === 0) {
1281
+ }, Re = () => (e) => {
1282
+ h.use(["meta-player-ui"], ([n]) => {
1283
+ if (n.version === 0) {
572
1284
  console.error(
573
1285
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
574
1286
  );
575
1287
  return;
576
1288
  }
577
- o.i?.showToast(e);
1289
+ n.i?.showToast(e);
578
1290
  });
579
1291
  };
580
- function W(t) {
1292
+ function Ht(t) {
581
1293
  const e = {};
582
- for (const o of t.fields)
583
- e[o.name] = o.defaultValue;
1294
+ for (const n of t.fields)
1295
+ e[n.name] = n.defaultValue;
584
1296
  return e;
585
1297
  }
586
- function Q(t) {
1298
+ function zt(t) {
587
1299
  return { [t.name]: t.defaultValues };
588
1300
  }
589
- function U(t) {
1301
+ function Ut(t) {
590
1302
  return { [t.name]: t.defaultValue };
591
1303
  }
592
- function H(t) {
1304
+ function _t(t) {
593
1305
  switch (t.type) {
594
1306
  case "form":
595
- return W(t);
1307
+ return Ht(t);
596
1308
  case "checkboxes":
597
1309
  case "switches":
598
- return Q(t);
1310
+ return zt(t);
599
1311
  case "radio":
600
- return U(t);
1312
+ return Ut(t);
601
1313
  default:
602
1314
  return {};
603
1315
  }
604
1316
  }
605
- function N(t) {
1317
+ function Qt(t) {
606
1318
  const e = {};
607
- for (const o of t)
608
- Object.assign(e, H(o));
1319
+ for (const n of t)
1320
+ Object.assign(e, _t(n));
609
1321
  return e;
610
1322
  }
611
- function Dt(t) {
612
- const o = E()((s) => ({
613
- ...N(t)
1323
+ function Te(t) {
1324
+ const n = dt()((s) => ({
1325
+ ...Qt(t)
614
1326
  }));
615
- return o.activitySettings = t, o;
1327
+ return n.activitySettings = t, n;
616
1328
  }
617
- function _(t) {
618
- V(
1329
+ function Yt(t) {
1330
+ Wt(
619
1331
  () => t.activitySettings,
620
1332
  (e) => {
621
1333
  t.setState(e);
@@ -623,64 +1335,64 @@ function _(t) {
623
1335
  []
624
1336
  );
625
1337
  }
626
- function z({
1338
+ function Kt({
627
1339
  store: t
628
1340
  }) {
629
- return _(t), null;
1341
+ return Yt(t), null;
630
1342
  }
631
- const K = [
1343
+ const Xt = [
632
1344
  "meta-player-events:1",
633
1345
  "mode:1",
634
1346
  "workflow:1"
635
1347
  ];
636
- function Et({
1348
+ function Ve({
637
1349
  children: t,
638
1350
  contracts: e,
639
- loadOnlyWhenReady: o = !0,
1351
+ loadOnlyWhenReady: n = !0,
640
1352
  activitySettingsStore: s
641
1353
  }) {
642
- const i = n((c) => c.ready);
643
- return l(() => {
644
- const c = [...e];
645
- for (const u of K)
646
- c.includes(u) || c.push(u);
647
- O(c);
648
- }, []), o && !i ? /* @__PURE__ */ h("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ j(M, { children: [
649
- s && /* @__PURE__ */ h(z, { store: s }),
1354
+ const o = a((r) => r.ready);
1355
+ return w(() => {
1356
+ const r = [...e];
1357
+ for (const g of Xt)
1358
+ r.includes(g) || r.push(g);
1359
+ Bt(r);
1360
+ }, []), n && !o ? /* @__PURE__ */ Q("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ gt(mt, { children: [
1361
+ s && /* @__PURE__ */ Q(Kt, { store: s }),
650
1362
  t
651
1363
  ] });
652
1364
  }
653
1365
  export {
654
- Et as Capytale,
655
- Dt as createActivitySettingsStore,
656
- bt as useAfterSaveAction,
657
- Ct as useGetLoadedJsonActivityContent,
658
- pt as useGetLoadedJsonActivitySplitContent,
659
- St as useGetLoadedJsonAssignmentContent,
660
- mt as useGetLoadedJsonAssignmentSplitContent,
661
- gt as useGetLoadedJsonContent,
662
- dt as useGetLoadedTextContent,
663
- ft as useJsonActivityContentSaveFunction,
664
- Jt as useJsonActivitySplitContentSaveFunction,
665
- At as useJsonAssignmentContentSaveFunction,
666
- Ft as useJsonAssignmentSplitContentSaveFunction,
667
- yt as useJsonContentSaveFunction,
668
- lt as useLoadedJsonActivityBinaryData,
669
- ct as useLoadedJsonActivityContent,
670
- ut as useLoadedJsonAssignmentBinaryData,
671
- rt as useLoadedJsonAssignmentContent,
672
- at as useLoadedJsonContent,
673
- it as useLoadedTextContent,
674
- tt as useMode,
675
- st as useNotifyIsDirty,
676
- ht as usePreviewImageFile,
677
- wt as usePreviewTextFile,
678
- xt as useQuickActions,
679
- ot as useRequestSave,
680
- V as useSettings,
681
- Tt as useShowToast,
682
- kt as useSidebarActions,
683
- vt as useTextContentSaveFunction,
684
- nt as useTheme,
685
- et as useWorkflow
1366
+ Ve as Capytale,
1367
+ Te as createActivitySettingsStore,
1368
+ Ee as useAfterSaveAction,
1369
+ me as useGetLoadedJsonActivityContent,
1370
+ ye as useGetLoadedJsonActivitySplitContent,
1371
+ pe as useGetLoadedJsonAssignmentContent,
1372
+ ve as useGetLoadedJsonAssignmentSplitContent,
1373
+ ge as useGetLoadedJsonContent,
1374
+ fe as useGetLoadedTextContent,
1375
+ we as useJsonActivityContentSaveFunction,
1376
+ Ae as useJsonActivitySplitContentSaveFunction,
1377
+ he as useJsonAssignmentContentSaveFunction,
1378
+ be as useJsonAssignmentSplitContentSaveFunction,
1379
+ Se as useJsonContentSaveFunction,
1380
+ ue as useLoadedJsonActivityBinaryData,
1381
+ ce as useLoadedJsonActivityContent,
1382
+ de as useLoadedJsonAssignmentBinaryData,
1383
+ le as useLoadedJsonAssignmentContent,
1384
+ ae as useLoadedJsonContent,
1385
+ ie as useLoadedTextContent,
1386
+ ee as useMode,
1387
+ se as useNotifyIsDirty,
1388
+ Je as usePreviewImageFile,
1389
+ ke as usePreviewTextFile,
1390
+ xe as useQuickActions,
1391
+ re as useRequestSave,
1392
+ Wt as useSettings,
1393
+ Re as useShowToast,
1394
+ Fe as useSidebarActions,
1395
+ Ce as useTextContentSaveFunction,
1396
+ oe as useTheme,
1397
+ ne as useWorkflow
686
1398
  };