@chaibuilder/sdk 1.0.13 → 1.0.15

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.
Files changed (168) hide show
  1. package/dist/{AddBlocks-H7BZYHUC.js → AddBlocks-eoo1CzaK.js} +114 -111
  2. package/dist/AddBlocks-jU0NwP_s.cjs +3 -0
  3. package/dist/BrandingOptions-WSCFnWAf.cjs +1 -0
  4. package/dist/{BrandingOptions-PAgY-kvj.js → BrandingOptions-_Og7VUHA.js} +57 -41
  5. package/dist/{CanvasArea-zn2ox-5h.js → CanvasArea-cky_d2Lu.js} +517 -519
  6. package/dist/CanvasArea-hT9uHhkz.cjs +46 -0
  7. package/dist/Class-RZuPYbUS.cjs +1 -0
  8. package/dist/{Class-l7qYbuoN.js → Class-nQk08vqd.js} +204 -124
  9. package/dist/{CurrentPage-6Jp4xAWK.js → CurrentPage--OlBwyNE.js} +58 -40
  10. package/dist/CurrentPage-x6Ez11gP.cjs +1 -0
  11. package/dist/Layers-gEA0qWYP.cjs +1 -0
  12. package/dist/{Layers-WkZ48AUm.js → Layers-uzA3QA-4.js} +158 -141
  13. package/dist/MarkAsGlobalBlock-lYL8cO9x.cjs +1 -0
  14. package/dist/MarkAsGlobalBlock-ySc-D4SB.js +84 -0
  15. package/dist/PagesPanel-5t0bV9T2.cjs +1 -0
  16. package/dist/PagesPanel-tH6c9Mnv.js +70 -0
  17. package/dist/ProjectPanel-NdrR6a8t.cjs +1 -0
  18. package/dist/ProjectPanel-Q2-15-In.js +91 -0
  19. package/dist/Settings-DBiwm1hY.cjs +1 -0
  20. package/dist/{Settings-fH8fZKpm.js → Settings-LOqpvQ_1.js} +411 -408
  21. package/dist/SidePanels-8JWYXGqN.cjs +1 -0
  22. package/dist/{SidePanels-w8ZHKJaR.js → SidePanels-F7ccs2Xf.js} +106 -88
  23. package/dist/{Topbar-hm1D_5sb.js → Topbar-lX9OMPwj.js} +47 -45
  24. package/dist/Topbar-qi5ab8rR.cjs +1 -0
  25. package/dist/UnsplashImages-a2r7b3kB.cjs +1 -0
  26. package/dist/{UnsplashImages-gPcBLjgB.js → UnsplashImages-u_QTABzi.js} +56 -44
  27. package/dist/{UploadImages-_ZyUU66E.js → UploadImages-gV5xDHIu.js} +55 -34
  28. package/dist/UploadImages-jLQgLujd.cjs +1 -0
  29. package/dist/add-page-modal-U5ramelz.js +110 -0
  30. package/dist/add-page-modal-tIt3N8jH.cjs +1 -0
  31. package/dist/confirm-alert-ZQ-sxX0X.js +58 -0
  32. package/dist/confirm-alert-z74-fGOT.cjs +1 -0
  33. package/dist/core.cjs +1 -1
  34. package/dist/core.js +99 -124
  35. package/dist/delete-page-modal-5XuSfQT0.cjs +1 -0
  36. package/dist/delete-page-modal-_E87bVUZ.js +89 -0
  37. package/dist/form-Osm1AmO5.cjs +1 -0
  38. package/dist/{form-dVpOAyRl.js → form-zZJyZuNH.js} +12 -12
  39. package/dist/index-2EHcmZqL.js +2947 -0
  40. package/dist/index-RVm8Txnj.js +1149 -0
  41. package/dist/index-_jFEo7h5.cjs +206 -0
  42. package/dist/index-c8zW_D2V.cjs +1 -0
  43. package/dist/index-cU5eyVRU.js +40872 -0
  44. package/dist/index-fwo4wa7u.cjs +1 -0
  45. package/dist/index-gmZcUXyn.js +25 -0
  46. package/dist/index-m2muA80V.cjs +9 -0
  47. package/dist/{jsx-runtime-JYMCiFoE.cjs → jsx-runtime-WKRPbKtm.cjs} +7 -7
  48. package/dist/{jsx-runtime-Sp0orL4X.js → jsx-runtime-qAwJ85SY.js} +109 -106
  49. package/dist/lib.cjs +2 -1
  50. package/dist/lib.js +1333 -71
  51. package/dist/page-viewer-BSc-5M4B.cjs +1 -0
  52. package/dist/{page-viewer-Y4YiaZ_m.js → page-viewer-nLqIs_9w.js} +62 -44
  53. package/dist/project-general-setting-14MA_cX5.cjs +1 -0
  54. package/dist/{project-general-setting-U4S_KlhU.js → project-general-setting-kXh5myAr.js} +46 -36
  55. package/dist/project-seo-setting-POGPEJZ8.cjs +1 -0
  56. package/dist/project-seo-setting-nT1qo1Bb.js +89 -0
  57. package/dist/render.cjs +1 -1
  58. package/dist/render.js +23 -19
  59. package/dist/server.cjs +1 -1
  60. package/dist/server.js +1 -1
  61. package/dist/single-page-detail-EgQd9TSA.cjs +1 -0
  62. package/dist/{single-page-detail-pAxCy_Pe.js → single-page-detail-fV-A6vJR.js} +90 -80
  63. package/dist/studio.cjs +1 -1
  64. package/dist/studio.js +45 -25
  65. package/dist/ui.cjs +1 -1
  66. package/dist/ui.js +156 -357
  67. package/package.json +1 -1
  68. package/dist/AddBlocks-7ACJv8LW.cjs +0 -3
  69. package/dist/BrandingOptions-5j-XszLM.cjs +0 -1
  70. package/dist/CanvasArea-Dnm-yeus.cjs +0 -46
  71. package/dist/ChaiBuilderEditor-BoE-sArB.cjs +0 -163
  72. package/dist/ChaiBuilderEditor-hEuUONQ3.js +0 -27094
  73. package/dist/Class-_uCzl5v1.cjs +0 -1
  74. package/dist/CurrentPage-YMpqOqx7.cjs +0 -1
  75. package/dist/ImagesPanel-6us7hiLN.cjs +0 -1
  76. package/dist/ImagesPanel-oaHOD-Ex.js +0 -27
  77. package/dist/Layers-EzOZdWvd.cjs +0 -1
  78. package/dist/MODIFIERS-DsEzQ3aH.js +0 -73
  79. package/dist/MODIFIERS-Fx6WAZcw.cjs +0 -1
  80. package/dist/MarkAsGlobalBlock-0HubcRkY.js +0 -77
  81. package/dist/MarkAsGlobalBlock-HmeIyLCP.cjs +0 -1
  82. package/dist/PagesPanel-6JuwBLFQ.js +0 -50
  83. package/dist/PagesPanel-zJq8p1ja.cjs +0 -1
  84. package/dist/ProjectPanel-Zml2F8b9.cjs +0 -1
  85. package/dist/ProjectPanel-cu2QSDW9.js +0 -73
  86. package/dist/Settings-lc9PfnmG.cjs +0 -1
  87. package/dist/SidePanels-VH72zFE2.cjs +0 -1
  88. package/dist/Topbar-vQPo9xSY.cjs +0 -1
  89. package/dist/UnsplashImages-BoBBSi1a.cjs +0 -1
  90. package/dist/UploadImages-T6kW0s3G.cjs +0 -1
  91. package/dist/accordion-oPUeqPCZ.js +0 -42
  92. package/dist/accordion-ynvFtV_p.cjs +0 -1
  93. package/dist/add-page-modal--qZSwJuB.cjs +0 -1
  94. package/dist/add-page-modal-bj7qbZuK.js +0 -99
  95. package/dist/alert-dialog-GNfnpqFB.js +0 -64
  96. package/dist/alert-dialog-Mv0-wAvS.cjs +0 -1
  97. package/dist/command-ThdTuUxt.cjs +0 -1
  98. package/dist/command-VHca6CcN.js +0 -97
  99. package/dist/confirm-alert-8EHe0OOd.cjs +0 -1
  100. package/dist/confirm-alert-b0e_BLhF.js +0 -36
  101. package/dist/context-menu-8dC9uGXj.js +0 -122
  102. package/dist/context-menu-IgLbIuth.cjs +0 -1
  103. package/dist/controls-Ni5kEzLz.js +0 -103
  104. package/dist/controls-W97-POR_.cjs +0 -1
  105. package/dist/controls-enQY7NI8.js +0 -118
  106. package/dist/controls-xUKa23ic.cjs +0 -1
  107. package/dist/delete-page-modal-2LuDLEiP.cjs +0 -1
  108. package/dist/delete-page-modal-cnrR8tWH.js +0 -69
  109. package/dist/dialog-S_QbL1iq.cjs +0 -1
  110. package/dist/dialog-jrw9DF1f.js +0 -65
  111. package/dist/dropdown-menu-S03K_fNs.js +0 -164
  112. package/dist/dropdown-menu-sMXR59cB.cjs +0 -1
  113. package/dist/form-nRAvKPQj.cjs +0 -1
  114. package/dist/functions-nNTuSTsR.js +0 -1106
  115. package/dist/functions-pcUZhFJM.js +0 -12
  116. package/dist/functions-sCuB7nvZ.cjs +0 -2
  117. package/dist/functions-uw7QP2kT.cjs +0 -1
  118. package/dist/html-to-json-P6GpbcQX.cjs +0 -1
  119. package/dist/html-to-json-pdHQfRkN.js +0 -178
  120. package/dist/index-HAue58ea.cjs +0 -1
  121. package/dist/index-T4_wfKl5.js +0 -2256
  122. package/dist/index-X9ZgD09V.cjs +0 -1
  123. package/dist/index-ehKdBRUK.js +0 -18
  124. package/dist/label-KaP7MRrs.js +0 -10
  125. package/dist/label-tFm8HZdb.cjs +0 -1
  126. package/dist/link-6o6n2Tnd.js +0 -204
  127. package/dist/link-ece8dZGH.cjs +0 -1
  128. package/dist/page-viewer-IARz6OSp.cjs +0 -1
  129. package/dist/popover-a84pbVhQ.js +0 -23
  130. package/dist/popover-fKjgcRUx.cjs +0 -1
  131. package/dist/project-general-setting-eSl3t-VH.cjs +0 -1
  132. package/dist/project-seo-setting-Ga9v_ECU.js +0 -67
  133. package/dist/project-seo-setting-rankm1z3.cjs +0 -1
  134. package/dist/scroll-area-FiHvy-TZ.cjs +0 -1
  135. package/dist/scroll-area-ewXbxc3n.js +0 -30
  136. package/dist/select-7bjg-rr9.cjs +0 -1
  137. package/dist/select-POGdEDHT.js +0 -75
  138. package/dist/separator-3Civ-6hb.cjs +0 -1
  139. package/dist/separator-SctTn0Qi.js +0 -18
  140. package/dist/single-page-detail-yPgnu2AI.cjs +0 -1
  141. package/dist/skeleton-CU_FIbg3.js +0 -239
  142. package/dist/skeleton-JHP9zwL2.cjs +0 -1
  143. package/dist/tabs-Gb9v5dVb.js +0 -46
  144. package/dist/tabs-iWeaaVrg.cjs +0 -1
  145. package/dist/textarea-1kZEh7ki.cjs +0 -1
  146. package/dist/textarea-b2QvVhrK.js +0 -73
  147. package/dist/toggle-ASJRAaGP.js +0 -30
  148. package/dist/toggle-ehNIPmme.cjs +0 -1
  149. package/dist/useAddBlock-WJc3OgG8.js +0 -86
  150. package/dist/useAddBlock-dCKRFPRU.cjs +0 -1
  151. package/dist/useAllBlocks-6hvuNuyw.cjs +0 -1
  152. package/dist/useAllBlocks-PQKYvs-e.js +0 -20
  153. package/dist/useChaiExternalData-4K9WxANa.js +0 -6
  154. package/dist/useChaiExternalData-DkyBJ81C.cjs +0 -1
  155. package/dist/useDarkMode-ZKCO_gkt.js +0 -23
  156. package/dist/useDarkMode-dV6FM6l-.cjs +0 -1
  157. package/dist/useFeatureSupport-OLwNgEZb.js +0 -16
  158. package/dist/useFeatureSupport-c9IgPW2t.cjs +0 -1
  159. package/dist/useHiddenBlocks-3MsGOJ1s.js +0 -15
  160. package/dist/useHiddenBlocks-oJuQDmTy.cjs +0 -1
  161. package/dist/useLanguage-NKKKaxVM.cjs +0 -1
  162. package/dist/useLanguage-gVC5rxO5.js +0 -216
  163. package/dist/useMarkAsGlobalBlock-X73Vny8u.js +0 -25
  164. package/dist/useMarkAsGlobalBlock-ebBVGHg4.cjs +0 -1
  165. package/dist/useUiLibraries-4hPOi8DI.js +0 -12
  166. package/dist/useUiLibraries-9FhQCpKo.cjs +0 -1
  167. package/dist/utils-dze1SGvB.js +0 -6
  168. package/dist/utils-qK_SjzzV.cjs +0 -1
@@ -1,2256 +0,0 @@
1
- var ft = (t, e, s) => {
2
- if (!e.has(t))
3
- throw TypeError("Cannot " + s);
4
- };
5
- var n = (t, e, s) => (ft(t, e, "read from private field"), s ? s.call(t) : e.get(t)), l = (t, e, s) => {
6
- if (e.has(t))
7
- throw TypeError("Cannot add the same private member more than once");
8
- e instanceof WeakSet ? e.add(t) : e.set(t, s);
9
- }, o = (t, e, s, r) => (ft(t, e, "write to private field"), r ? r.call(t, s) : e.set(t, s), s);
10
- var it = (t, e, s, r) => ({
11
- set _(i) {
12
- o(t, e, i, s);
13
- },
14
- get _() {
15
- return n(t, e, r);
16
- }
17
- }), y = (t, e, s) => (ft(t, e, "access private method"), s);
18
- import { j as u } from "./jsx-runtime-Sp0orL4X.js";
19
- import * as R from "react";
20
- import de, { lazy as Rt, useCallback as yt, useState as pt, Suspense as xs, useEffect as ws } from "react";
21
- import { u as Cs, C as Os } from "./ChaiBuilderEditor-hEuUONQ3.js";
22
- import "react-i18next";
23
- import { B as ts, u as Ps } from "./skeleton-CU_FIbg3.js";
24
- import { FileTextIcon as js, GearIcon as Ss, EyeClosedIcon as Es, EyeOpenIcon as Fs } from "@radix-ui/react-icons";
25
- import { toast as se, Toaster as As } from "sonner";
26
- import { g as Rs } from "./html-to-json-pdHQfRkN.js";
27
- import { sortBy as Ms, filter as ks, has as qs, set as Us, capitalize as Ds, get as qt, omit as Qs, size as Ut } from "lodash";
28
- import { Loader as Ns, LogOutIcon as Is, Loader2 as Ts } from "lucide-react";
29
- import { A as Ls, a as Ks, b as _s, c as Bs, e as $s, f as Hs, d as zs, h as Gs } from "./alert-dialog-GNfnpqFB.js";
30
- var Ke = class {
31
- constructor() {
32
- this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
33
- }
34
- subscribe(t) {
35
- return this.listeners.add(t), this.onSubscribe(), () => {
36
- this.listeners.delete(t), this.onUnsubscribe();
37
- };
38
- }
39
- hasListeners() {
40
- return this.listeners.size > 0;
41
- }
42
- onSubscribe() {
43
- }
44
- onUnsubscribe() {
45
- }
46
- }, Le = typeof window > "u" || "Deno" in window;
47
- function H() {
48
- }
49
- function Vs(t, e) {
50
- return typeof t == "function" ? t(e) : t;
51
- }
52
- function gt(t) {
53
- return typeof t == "number" && t >= 0 && t !== 1 / 0;
54
- }
55
- function ss(t, e) {
56
- return Math.max(t + (e || 0) - Date.now(), 0);
57
- }
58
- function Dt(t, e) {
59
- const {
60
- type: s = "all",
61
- exact: r,
62
- fetchStatus: i,
63
- predicate: a,
64
- queryKey: c,
65
- stale: d
66
- } = t;
67
- if (c) {
68
- if (r) {
69
- if (e.queryHash !== Mt(c, e.options))
70
- return !1;
71
- } else if (!$e(e.queryKey, c))
72
- return !1;
73
- }
74
- if (s !== "all") {
75
- const p = e.isActive();
76
- if (s === "active" && !p || s === "inactive" && p)
77
- return !1;
78
- }
79
- return !(typeof d == "boolean" && e.isStale() !== d || typeof i < "u" && i !== e.state.fetchStatus || a && !a(e));
80
- }
81
- function Qt(t, e) {
82
- const { exact: s, status: r, predicate: i, mutationKey: a } = t;
83
- if (a) {
84
- if (!e.options.mutationKey)
85
- return !1;
86
- if (s) {
87
- if (Be(e.options.mutationKey) !== Be(a))
88
- return !1;
89
- } else if (!$e(e.options.mutationKey, a))
90
- return !1;
91
- }
92
- return !(r && e.state.status !== r || i && !i(e));
93
- }
94
- function Mt(t, e) {
95
- return ((e == null ? void 0 : e.queryKeyHashFn) || Be)(t);
96
- }
97
- function Be(t) {
98
- return JSON.stringify(
99
- t,
100
- (e, s) => bt(s) ? Object.keys(s).sort().reduce((r, i) => (r[i] = s[i], r), {}) : s
101
- );
102
- }
103
- function $e(t, e) {
104
- return t === e ? !0 : typeof t != typeof e ? !1 : t && e && typeof t == "object" && typeof e == "object" ? !Object.keys(e).some((s) => !$e(t[s], e[s])) : !1;
105
- }
106
- function rs(t, e) {
107
- if (t === e)
108
- return t;
109
- const s = Nt(t) && Nt(e);
110
- if (s || bt(t) && bt(e)) {
111
- const r = s ? t.length : Object.keys(t).length, i = s ? e : Object.keys(e), a = i.length, c = s ? [] : {};
112
- let d = 0;
113
- for (let p = 0; p < a; p++) {
114
- const b = s ? p : i[p];
115
- c[b] = rs(t[b], e[b]), c[b] === t[b] && d++;
116
- }
117
- return r === a && d === r ? t : c;
118
- }
119
- return e;
120
- }
121
- function ut(t, e) {
122
- if (t && !e || e && !t)
123
- return !1;
124
- for (const s in t)
125
- if (t[s] !== e[s])
126
- return !1;
127
- return !0;
128
- }
129
- function Nt(t) {
130
- return Array.isArray(t) && t.length === Object.keys(t).length;
131
- }
132
- function bt(t) {
133
- if (!It(t))
134
- return !1;
135
- const e = t.constructor;
136
- if (typeof e > "u")
137
- return !0;
138
- const s = e.prototype;
139
- return !(!It(s) || !s.hasOwnProperty("isPrototypeOf"));
140
- }
141
- function It(t) {
142
- return Object.prototype.toString.call(t) === "[object Object]";
143
- }
144
- function ns(t) {
145
- return new Promise((e) => {
146
- setTimeout(e, t);
147
- });
148
- }
149
- function Tt(t) {
150
- ns(0).then(t);
151
- }
152
- function vt(t, e, s) {
153
- return typeof s.structuralSharing == "function" ? s.structuralSharing(t, e) : s.structuralSharing !== !1 ? rs(t, e) : e;
154
- }
155
- function Ws(t, e, s = 0) {
156
- const r = [...t, e];
157
- return s && r.length > s ? r.slice(1) : r;
158
- }
159
- function Js(t, e, s = 0) {
160
- const r = [e, ...t];
161
- return s && r.length > s ? r.slice(0, -1) : r;
162
- }
163
- var ye, ne, Pe, Ht, Ys = (Ht = class extends Ke {
164
- constructor() {
165
- super();
166
- l(this, ye, void 0);
167
- l(this, ne, void 0);
168
- l(this, Pe, void 0);
169
- o(this, Pe, (e) => {
170
- if (!Le && window.addEventListener) {
171
- const s = () => e();
172
- return window.addEventListener("visibilitychange", s, !1), () => {
173
- window.removeEventListener("visibilitychange", s);
174
- };
175
- }
176
- });
177
- }
178
- onSubscribe() {
179
- n(this, ne) || this.setEventListener(n(this, Pe));
180
- }
181
- onUnsubscribe() {
182
- var e;
183
- this.hasListeners() || ((e = n(this, ne)) == null || e.call(this), o(this, ne, void 0));
184
- }
185
- setEventListener(e) {
186
- var s;
187
- o(this, Pe, e), (s = n(this, ne)) == null || s.call(this), o(this, ne, e((r) => {
188
- typeof r == "boolean" ? this.setFocused(r) : this.onFocus();
189
- }));
190
- }
191
- setFocused(e) {
192
- n(this, ye) !== e && (o(this, ye, e), this.onFocus());
193
- }
194
- onFocus() {
195
- this.listeners.forEach((e) => {
196
- e();
197
- });
198
- }
199
- isFocused() {
200
- var e;
201
- return typeof n(this, ye) == "boolean" ? n(this, ye) : ((e = globalThis.document) == null ? void 0 : e.visibilityState) !== "hidden";
202
- }
203
- }, ye = new WeakMap(), ne = new WeakMap(), Pe = new WeakMap(), Ht), ct = new Ys(), je, ie, Se, zt, Xs = (zt = class extends Ke {
204
- constructor() {
205
- super();
206
- l(this, je, !0);
207
- l(this, ie, void 0);
208
- l(this, Se, void 0);
209
- o(this, Se, (e) => {
210
- if (!Le && window.addEventListener) {
211
- const s = () => e(!0), r = () => e(!1);
212
- return window.addEventListener("online", s, !1), window.addEventListener("offline", r, !1), () => {
213
- window.removeEventListener("online", s), window.removeEventListener("offline", r);
214
- };
215
- }
216
- });
217
- }
218
- onSubscribe() {
219
- n(this, ie) || this.setEventListener(n(this, Se));
220
- }
221
- onUnsubscribe() {
222
- var e;
223
- this.hasListeners() || ((e = n(this, ie)) == null || e.call(this), o(this, ie, void 0));
224
- }
225
- setEventListener(e) {
226
- var s;
227
- o(this, Se, e), (s = n(this, ie)) == null || s.call(this), o(this, ie, e(this.setOnline.bind(this)));
228
- }
229
- setOnline(e) {
230
- n(this, je) !== e && (o(this, je, e), this.listeners.forEach((r) => {
231
- r(e);
232
- }));
233
- }
234
- isOnline() {
235
- return n(this, je);
236
- }
237
- }, je = new WeakMap(), ie = new WeakMap(), Se = new WeakMap(), zt), lt = new Xs();
238
- function Zs(t) {
239
- return Math.min(1e3 * 2 ** t, 3e4);
240
- }
241
- function dt(t) {
242
- return (t ?? "online") === "online" ? lt.isOnline() : !0;
243
- }
244
- var is = class {
245
- constructor(t) {
246
- this.revert = t == null ? void 0 : t.revert, this.silent = t == null ? void 0 : t.silent;
247
- }
248
- };
249
- function mt(t) {
250
- return t instanceof is;
251
- }
252
- function as(t) {
253
- let e = !1, s = 0, r = !1, i, a, c;
254
- const d = new Promise((f, g) => {
255
- a = f, c = g;
256
- }), p = (f) => {
257
- var g;
258
- r || (m(new is(f)), (g = t.abort) == null || g.call(t));
259
- }, b = () => {
260
- e = !0;
261
- }, h = () => {
262
- e = !1;
263
- }, O = () => !ct.isFocused() || t.networkMode !== "always" && !lt.isOnline(), k = (f) => {
264
- var g;
265
- r || (r = !0, (g = t.onSuccess) == null || g.call(t, f), i == null || i(), a(f));
266
- }, m = (f) => {
267
- var g;
268
- r || (r = !0, (g = t.onError) == null || g.call(t, f), i == null || i(), c(f));
269
- }, v = () => new Promise((f) => {
270
- var g;
271
- i = (w) => {
272
- const x = r || !O();
273
- return x && f(w), x;
274
- }, (g = t.onPause) == null || g.call(t);
275
- }).then(() => {
276
- var f;
277
- i = void 0, r || (f = t.onContinue) == null || f.call(t);
278
- }), j = () => {
279
- if (r)
280
- return;
281
- let f;
282
- try {
283
- f = t.fn();
284
- } catch (g) {
285
- f = Promise.reject(g);
286
- }
287
- Promise.resolve(f).then(k).catch((g) => {
288
- var I;
289
- if (r)
290
- return;
291
- const w = t.retry ?? (Le ? 0 : 3), x = t.retryDelay ?? Zs, F = typeof x == "function" ? x(s, g) : x, D = w === !0 || typeof w == "number" && s < w || typeof w == "function" && w(s, g);
292
- if (e || !D) {
293
- m(g);
294
- return;
295
- }
296
- s++, (I = t.onFail) == null || I.call(t, s, g), ns(F).then(() => {
297
- if (O())
298
- return v();
299
- }).then(() => {
300
- e ? m(g) : j();
301
- });
302
- });
303
- };
304
- return dt(t.networkMode) ? j() : v().then(j), {
305
- promise: d,
306
- cancel: p,
307
- continue: () => (i == null ? void 0 : i()) ? d : Promise.resolve(),
308
- cancelRetry: b,
309
- continueRetry: h
310
- };
311
- }
312
- function er() {
313
- let t = [], e = 0, s = (h) => {
314
- h();
315
- }, r = (h) => {
316
- h();
317
- };
318
- const i = (h) => {
319
- let O;
320
- e++;
321
- try {
322
- O = h();
323
- } finally {
324
- e--, e || d();
325
- }
326
- return O;
327
- }, a = (h) => {
328
- e ? t.push(h) : Tt(() => {
329
- s(h);
330
- });
331
- }, c = (h) => (...O) => {
332
- a(() => {
333
- h(...O);
334
- });
335
- }, d = () => {
336
- const h = t;
337
- t = [], h.length && Tt(() => {
338
- r(() => {
339
- h.forEach((O) => {
340
- s(O);
341
- });
342
- });
343
- });
344
- };
345
- return {
346
- batch: i,
347
- batchCalls: c,
348
- schedule: a,
349
- setNotifyFunction: (h) => {
350
- s = h;
351
- },
352
- setBatchNotifyFunction: (h) => {
353
- r = h;
354
- }
355
- };
356
- }
357
- var E = er(), pe, Gt, os = (Gt = class {
358
- constructor() {
359
- l(this, pe, void 0);
360
- }
361
- destroy() {
362
- this.clearGcTimeout();
363
- }
364
- scheduleGc() {
365
- this.clearGcTimeout(), gt(this.gcTime) && o(this, pe, setTimeout(() => {
366
- this.optionalRemove();
367
- }, this.gcTime));
368
- }
369
- updateGcTime(t) {
370
- this.gcTime = Math.max(
371
- this.gcTime || 0,
372
- t ?? (Le ? 1 / 0 : 5 * 60 * 1e3)
373
- );
374
- }
375
- clearGcTimeout() {
376
- n(this, pe) && (clearTimeout(n(this, pe)), o(this, pe, void 0));
377
- }
378
- }, pe = new WeakMap(), Gt), Ee, Fe, K, ae, _, A, He, me, Ae, at, G, ee, Vt, tr = (Vt = class extends os {
379
- constructor(e) {
380
- super();
381
- l(this, Ae);
382
- l(this, G);
383
- l(this, Ee, void 0);
384
- l(this, Fe, void 0);
385
- l(this, K, void 0);
386
- l(this, ae, void 0);
387
- l(this, _, void 0);
388
- l(this, A, void 0);
389
- l(this, He, void 0);
390
- l(this, me, void 0);
391
- o(this, me, !1), o(this, He, e.defaultOptions), y(this, Ae, at).call(this, e.options), o(this, A, []), o(this, K, e.cache), this.queryKey = e.queryKey, this.queryHash = e.queryHash, o(this, Ee, e.state || sr(this.options)), this.state = n(this, Ee), this.scheduleGc();
392
- }
393
- get meta() {
394
- return this.options.meta;
395
- }
396
- optionalRemove() {
397
- !n(this, A).length && this.state.fetchStatus === "idle" && n(this, K).remove(this);
398
- }
399
- setData(e, s) {
400
- const r = vt(this.state.data, e, this.options);
401
- return y(this, G, ee).call(this, {
402
- data: r,
403
- type: "success",
404
- dataUpdatedAt: s == null ? void 0 : s.updatedAt,
405
- manual: s == null ? void 0 : s.manual
406
- }), r;
407
- }
408
- setState(e, s) {
409
- y(this, G, ee).call(this, { type: "setState", state: e, setStateOptions: s });
410
- }
411
- cancel(e) {
412
- var r;
413
- const s = n(this, ae);
414
- return (r = n(this, _)) == null || r.cancel(e), s ? s.then(H).catch(H) : Promise.resolve();
415
- }
416
- destroy() {
417
- super.destroy(), this.cancel({ silent: !0 });
418
- }
419
- reset() {
420
- this.destroy(), this.setState(n(this, Ee));
421
- }
422
- isActive() {
423
- return n(this, A).some(
424
- (e) => e.options.enabled !== !1
425
- );
426
- }
427
- isDisabled() {
428
- return this.getObserversCount() > 0 && !this.isActive();
429
- }
430
- isStale() {
431
- return this.state.isInvalidated || !this.state.dataUpdatedAt || n(this, A).some((e) => e.getCurrentResult().isStale);
432
- }
433
- isStaleByTime(e = 0) {
434
- return this.state.isInvalidated || !this.state.dataUpdatedAt || !ss(this.state.dataUpdatedAt, e);
435
- }
436
- onFocus() {
437
- var s;
438
- const e = n(this, A).find((r) => r.shouldFetchOnWindowFocus());
439
- e == null || e.refetch({ cancelRefetch: !1 }), (s = n(this, _)) == null || s.continue();
440
- }
441
- onOnline() {
442
- var s;
443
- const e = n(this, A).find((r) => r.shouldFetchOnReconnect());
444
- e == null || e.refetch({ cancelRefetch: !1 }), (s = n(this, _)) == null || s.continue();
445
- }
446
- addObserver(e) {
447
- n(this, A).includes(e) || (n(this, A).push(e), this.clearGcTimeout(), n(this, K).notify({ type: "observerAdded", query: this, observer: e }));
448
- }
449
- removeObserver(e) {
450
- n(this, A).includes(e) && (o(this, A, n(this, A).filter((s) => s !== e)), n(this, A).length || (n(this, _) && (n(this, me) ? n(this, _).cancel({ revert: !0 }) : n(this, _).cancelRetry()), this.scheduleGc()), n(this, K).notify({ type: "observerRemoved", query: this, observer: e }));
451
- }
452
- getObserversCount() {
453
- return n(this, A).length;
454
- }
455
- invalidate() {
456
- this.state.isInvalidated || y(this, G, ee).call(this, { type: "invalidate" });
457
- }
458
- fetch(e, s) {
459
- var b, h, O, k;
460
- if (this.state.fetchStatus !== "idle") {
461
- if (this.state.dataUpdatedAt && (s != null && s.cancelRefetch))
462
- this.cancel({ silent: !0 });
463
- else if (n(this, ae))
464
- return (b = n(this, _)) == null || b.continueRetry(), n(this, ae);
465
- }
466
- if (e && y(this, Ae, at).call(this, e), !this.options.queryFn) {
467
- const m = n(this, A).find((v) => v.options.queryFn);
468
- m && y(this, Ae, at).call(this, m.options);
469
- }
470
- process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
471
- "As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
472
- ));
473
- const r = new AbortController(), i = {
474
- queryKey: this.queryKey,
475
- meta: this.meta
476
- }, a = (m) => {
477
- Object.defineProperty(m, "signal", {
478
- enumerable: !0,
479
- get: () => (o(this, me, !0), r.signal)
480
- });
481
- };
482
- a(i);
483
- const c = () => this.options.queryFn ? (o(this, me, !1), this.options.persister ? this.options.persister(
484
- this.options.queryFn,
485
- i,
486
- this
487
- ) : this.options.queryFn(
488
- i
489
- )) : Promise.reject(
490
- new Error(`Missing queryFn: '${this.options.queryHash}'`)
491
- ), d = {
492
- fetchOptions: s,
493
- options: this.options,
494
- queryKey: this.queryKey,
495
- state: this.state,
496
- fetchFn: c
497
- };
498
- a(d), (h = this.options.behavior) == null || h.onFetch(
499
- d,
500
- this
501
- ), o(this, Fe, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((O = d.fetchOptions) == null ? void 0 : O.meta)) && y(this, G, ee).call(this, { type: "fetch", meta: (k = d.fetchOptions) == null ? void 0 : k.meta });
502
- const p = (m) => {
503
- var v, j, f, g;
504
- mt(m) && m.silent || y(this, G, ee).call(this, {
505
- type: "error",
506
- error: m
507
- }), mt(m) || ((j = (v = n(this, K).config).onError) == null || j.call(
508
- v,
509
- m,
510
- this
511
- ), (g = (f = n(this, K).config).onSettled) == null || g.call(
512
- f,
513
- this.state.data,
514
- m,
515
- this
516
- )), this.isFetchingOptimistic || this.scheduleGc(), this.isFetchingOptimistic = !1;
517
- };
518
- return o(this, _, as({
519
- fn: d.fetchFn,
520
- abort: r.abort.bind(r),
521
- onSuccess: (m) => {
522
- var v, j, f, g;
523
- if (typeof m > "u") {
524
- process.env.NODE_ENV !== "production" && console.error(
525
- `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
526
- ), p(new Error(`${this.queryHash} data is undefined`));
527
- return;
528
- }
529
- this.setData(m), (j = (v = n(this, K).config).onSuccess) == null || j.call(v, m, this), (g = (f = n(this, K).config).onSettled) == null || g.call(
530
- f,
531
- m,
532
- this.state.error,
533
- this
534
- ), this.isFetchingOptimistic || this.scheduleGc(), this.isFetchingOptimistic = !1;
535
- },
536
- onError: p,
537
- onFail: (m, v) => {
538
- y(this, G, ee).call(this, { type: "failed", failureCount: m, error: v });
539
- },
540
- onPause: () => {
541
- y(this, G, ee).call(this, { type: "pause" });
542
- },
543
- onContinue: () => {
544
- y(this, G, ee).call(this, { type: "continue" });
545
- },
546
- retry: d.options.retry,
547
- retryDelay: d.options.retryDelay,
548
- networkMode: d.options.networkMode
549
- })), o(this, ae, n(this, _).promise), n(this, ae);
550
- }
551
- }, Ee = new WeakMap(), Fe = new WeakMap(), K = new WeakMap(), ae = new WeakMap(), _ = new WeakMap(), A = new WeakMap(), He = new WeakMap(), me = new WeakMap(), Ae = new WeakSet(), at = function(e) {
552
- this.options = { ...n(this, He), ...e }, this.updateGcTime(this.options.gcTime);
553
- }, G = new WeakSet(), ee = function(e) {
554
- const s = (r) => {
555
- switch (e.type) {
556
- case "failed":
557
- return {
558
- ...r,
559
- fetchFailureCount: e.failureCount,
560
- fetchFailureReason: e.error
561
- };
562
- case "pause":
563
- return {
564
- ...r,
565
- fetchStatus: "paused"
566
- };
567
- case "continue":
568
- return {
569
- ...r,
570
- fetchStatus: "fetching"
571
- };
572
- case "fetch":
573
- return {
574
- ...r,
575
- fetchFailureCount: 0,
576
- fetchFailureReason: null,
577
- fetchMeta: e.meta ?? null,
578
- fetchStatus: dt(this.options.networkMode) ? "fetching" : "paused",
579
- ...!r.dataUpdatedAt && {
580
- error: null,
581
- status: "pending"
582
- }
583
- };
584
- case "success":
585
- return {
586
- ...r,
587
- data: e.data,
588
- dataUpdateCount: r.dataUpdateCount + 1,
589
- dataUpdatedAt: e.dataUpdatedAt ?? Date.now(),
590
- error: null,
591
- isInvalidated: !1,
592
- status: "success",
593
- ...!e.manual && {
594
- fetchStatus: "idle",
595
- fetchFailureCount: 0,
596
- fetchFailureReason: null
597
- }
598
- };
599
- case "error":
600
- const i = e.error;
601
- return mt(i) && i.revert && n(this, Fe) ? { ...n(this, Fe), fetchStatus: "idle" } : {
602
- ...r,
603
- error: i,
604
- errorUpdateCount: r.errorUpdateCount + 1,
605
- errorUpdatedAt: Date.now(),
606
- fetchFailureCount: r.fetchFailureCount + 1,
607
- fetchFailureReason: i,
608
- fetchStatus: "idle",
609
- status: "error"
610
- };
611
- case "invalidate":
612
- return {
613
- ...r,
614
- isInvalidated: !0
615
- };
616
- case "setState":
617
- return {
618
- ...r,
619
- ...e.state
620
- };
621
- }
622
- };
623
- this.state = s(this.state), E.batch(() => {
624
- n(this, A).forEach((r) => {
625
- r.onQueryUpdate();
626
- }), n(this, K).notify({ query: this, type: "updated", action: e });
627
- });
628
- }, Vt);
629
- function sr(t) {
630
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = typeof e < "u", r = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
631
- return {
632
- data: e,
633
- dataUpdateCount: 0,
634
- dataUpdatedAt: s ? r ?? Date.now() : 0,
635
- error: null,
636
- errorUpdateCount: 0,
637
- errorUpdatedAt: 0,
638
- fetchFailureCount: 0,
639
- fetchFailureReason: null,
640
- fetchMeta: null,
641
- isInvalidated: !1,
642
- status: s ? "success" : "pending",
643
- fetchStatus: "idle"
644
- };
645
- }
646
- var W, Wt, rr = (Wt = class extends Ke {
647
- constructor(e = {}) {
648
- super();
649
- l(this, W, void 0);
650
- this.config = e, o(this, W, /* @__PURE__ */ new Map());
651
- }
652
- build(e, s, r) {
653
- const i = s.queryKey, a = s.queryHash ?? Mt(i, s);
654
- let c = this.get(a);
655
- return c || (c = new tr({
656
- cache: this,
657
- queryKey: i,
658
- queryHash: a,
659
- options: e.defaultQueryOptions(s),
660
- state: r,
661
- defaultOptions: e.getQueryDefaults(i)
662
- }), this.add(c)), c;
663
- }
664
- add(e) {
665
- n(this, W).has(e.queryHash) || (n(this, W).set(e.queryHash, e), this.notify({
666
- type: "added",
667
- query: e
668
- }));
669
- }
670
- remove(e) {
671
- const s = n(this, W).get(e.queryHash);
672
- s && (e.destroy(), s === e && n(this, W).delete(e.queryHash), this.notify({ type: "removed", query: e }));
673
- }
674
- clear() {
675
- E.batch(() => {
676
- this.getAll().forEach((e) => {
677
- this.remove(e);
678
- });
679
- });
680
- }
681
- get(e) {
682
- return n(this, W).get(e);
683
- }
684
- getAll() {
685
- return [...n(this, W).values()];
686
- }
687
- find(e) {
688
- const s = { exact: !0, ...e };
689
- return this.getAll().find(
690
- (r) => Dt(s, r)
691
- );
692
- }
693
- findAll(e = {}) {
694
- const s = this.getAll();
695
- return Object.keys(e).length > 0 ? s.filter((r) => Dt(e, r)) : s;
696
- }
697
- notify(e) {
698
- E.batch(() => {
699
- this.listeners.forEach((s) => {
700
- s(e);
701
- });
702
- });
703
- }
704
- onFocus() {
705
- E.batch(() => {
706
- this.getAll().forEach((e) => {
707
- e.onFocus();
708
- });
709
- });
710
- }
711
- onOnline() {
712
- E.batch(() => {
713
- this.getAll().forEach((e) => {
714
- e.onOnline();
715
- });
716
- });
717
- }
718
- }, W = new WeakMap(), Wt), J, ze, T, Re, Y, re, Jt, nr = (Jt = class extends os {
719
- constructor(e) {
720
- super();
721
- l(this, Y);
722
- l(this, J, void 0);
723
- l(this, ze, void 0);
724
- l(this, T, void 0);
725
- l(this, Re, void 0);
726
- this.mutationId = e.mutationId, o(this, ze, e.defaultOptions), o(this, T, e.mutationCache), o(this, J, []), this.state = e.state || us(), this.setOptions(e.options), this.scheduleGc();
727
- }
728
- setOptions(e) {
729
- this.options = { ...n(this, ze), ...e }, this.updateGcTime(this.options.gcTime);
730
- }
731
- get meta() {
732
- return this.options.meta;
733
- }
734
- addObserver(e) {
735
- n(this, J).includes(e) || (n(this, J).push(e), this.clearGcTimeout(), n(this, T).notify({
736
- type: "observerAdded",
737
- mutation: this,
738
- observer: e
739
- }));
740
- }
741
- removeObserver(e) {
742
- o(this, J, n(this, J).filter((s) => s !== e)), this.scheduleGc(), n(this, T).notify({
743
- type: "observerRemoved",
744
- mutation: this,
745
- observer: e
746
- });
747
- }
748
- optionalRemove() {
749
- n(this, J).length || (this.state.status === "pending" ? this.scheduleGc() : n(this, T).remove(this));
750
- }
751
- continue() {
752
- var e;
753
- return ((e = n(this, Re)) == null ? void 0 : e.continue()) ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
754
- this.execute(this.state.variables);
755
- }
756
- async execute(e) {
757
- var i, a, c, d, p, b, h, O, k, m, v, j, f, g, w, x, F, D, I, M;
758
- const s = () => (o(this, Re, as({
759
- fn: () => this.options.mutationFn ? this.options.mutationFn(e) : Promise.reject(new Error("No mutationFn found")),
760
- onFail: (P, Z) => {
761
- y(this, Y, re).call(this, { type: "failed", failureCount: P, error: Z });
762
- },
763
- onPause: () => {
764
- y(this, Y, re).call(this, { type: "pause" });
765
- },
766
- onContinue: () => {
767
- y(this, Y, re).call(this, { type: "continue" });
768
- },
769
- retry: this.options.retry ?? 0,
770
- retryDelay: this.options.retryDelay,
771
- networkMode: this.options.networkMode
772
- })), n(this, Re).promise), r = this.state.status === "pending";
773
- try {
774
- if (!r) {
775
- y(this, Y, re).call(this, { type: "pending", variables: e }), await ((a = (i = n(this, T).config).onMutate) == null ? void 0 : a.call(
776
- i,
777
- e,
778
- this
779
- ));
780
- const Z = await ((d = (c = this.options).onMutate) == null ? void 0 : d.call(c, e));
781
- Z !== this.state.context && y(this, Y, re).call(this, {
782
- type: "pending",
783
- context: Z,
784
- variables: e
785
- });
786
- }
787
- const P = await s();
788
- return await ((b = (p = n(this, T).config).onSuccess) == null ? void 0 : b.call(
789
- p,
790
- P,
791
- e,
792
- this.state.context,
793
- this
794
- )), await ((O = (h = this.options).onSuccess) == null ? void 0 : O.call(h, P, e, this.state.context)), await ((m = (k = n(this, T).config).onSettled) == null ? void 0 : m.call(
795
- k,
796
- P,
797
- null,
798
- this.state.variables,
799
- this.state.context,
800
- this
801
- )), await ((j = (v = this.options).onSettled) == null ? void 0 : j.call(v, P, null, e, this.state.context)), y(this, Y, re).call(this, { type: "success", data: P }), P;
802
- } catch (P) {
803
- try {
804
- throw await ((g = (f = n(this, T).config).onError) == null ? void 0 : g.call(
805
- f,
806
- P,
807
- e,
808
- this.state.context,
809
- this
810
- )), await ((x = (w = this.options).onError) == null ? void 0 : x.call(
811
- w,
812
- P,
813
- e,
814
- this.state.context
815
- )), await ((D = (F = n(this, T).config).onSettled) == null ? void 0 : D.call(
816
- F,
817
- void 0,
818
- P,
819
- this.state.variables,
820
- this.state.context,
821
- this
822
- )), await ((M = (I = this.options).onSettled) == null ? void 0 : M.call(
823
- I,
824
- void 0,
825
- P,
826
- e,
827
- this.state.context
828
- )), P;
829
- } finally {
830
- y(this, Y, re).call(this, { type: "error", error: P });
831
- }
832
- }
833
- }
834
- }, J = new WeakMap(), ze = new WeakMap(), T = new WeakMap(), Re = new WeakMap(), Y = new WeakSet(), re = function(e) {
835
- const s = (r) => {
836
- switch (e.type) {
837
- case "failed":
838
- return {
839
- ...r,
840
- failureCount: e.failureCount,
841
- failureReason: e.error
842
- };
843
- case "pause":
844
- return {
845
- ...r,
846
- isPaused: !0
847
- };
848
- case "continue":
849
- return {
850
- ...r,
851
- isPaused: !1
852
- };
853
- case "pending":
854
- return {
855
- ...r,
856
- context: e.context,
857
- data: void 0,
858
- failureCount: 0,
859
- failureReason: null,
860
- error: null,
861
- isPaused: !dt(this.options.networkMode),
862
- status: "pending",
863
- variables: e.variables,
864
- submittedAt: Date.now()
865
- };
866
- case "success":
867
- return {
868
- ...r,
869
- data: e.data,
870
- failureCount: 0,
871
- failureReason: null,
872
- error: null,
873
- status: "success",
874
- isPaused: !1
875
- };
876
- case "error":
877
- return {
878
- ...r,
879
- data: void 0,
880
- error: e.error,
881
- failureCount: r.failureCount + 1,
882
- failureReason: e.error,
883
- isPaused: !1,
884
- status: "error"
885
- };
886
- }
887
- };
888
- this.state = s(this.state), E.batch(() => {
889
- n(this, J).forEach((r) => {
890
- r.onMutationUpdate(e);
891
- }), n(this, T).notify({
892
- mutation: this,
893
- type: "updated",
894
- action: e
895
- });
896
- });
897
- }, Jt);
898
- function us() {
899
- return {
900
- context: void 0,
901
- data: void 0,
902
- error: null,
903
- failureCount: 0,
904
- failureReason: null,
905
- isPaused: !1,
906
- status: "idle",
907
- variables: void 0,
908
- submittedAt: 0
909
- };
910
- }
911
- var B, Ge, ge, Yt, ir = (Yt = class extends Ke {
912
- constructor(e = {}) {
913
- super();
914
- l(this, B, void 0);
915
- l(this, Ge, void 0);
916
- l(this, ge, void 0);
917
- this.config = e, o(this, B, []), o(this, Ge, 0);
918
- }
919
- build(e, s, r) {
920
- const i = new nr({
921
- mutationCache: this,
922
- mutationId: ++it(this, Ge)._,
923
- options: e.defaultMutationOptions(s),
924
- state: r
925
- });
926
- return this.add(i), i;
927
- }
928
- add(e) {
929
- n(this, B).push(e), this.notify({ type: "added", mutation: e });
930
- }
931
- remove(e) {
932
- o(this, B, n(this, B).filter((s) => s !== e)), this.notify({ type: "removed", mutation: e });
933
- }
934
- clear() {
935
- E.batch(() => {
936
- n(this, B).forEach((e) => {
937
- this.remove(e);
938
- });
939
- });
940
- }
941
- getAll() {
942
- return n(this, B);
943
- }
944
- find(e) {
945
- const s = { exact: !0, ...e };
946
- return n(this, B).find(
947
- (r) => Qt(s, r)
948
- );
949
- }
950
- findAll(e = {}) {
951
- return n(this, B).filter(
952
- (s) => Qt(e, s)
953
- );
954
- }
955
- notify(e) {
956
- E.batch(() => {
957
- this.listeners.forEach((s) => {
958
- s(e);
959
- });
960
- });
961
- }
962
- resumePausedMutations() {
963
- return o(this, ge, (n(this, ge) ?? Promise.resolve()).then(() => {
964
- const e = n(this, B).filter((s) => s.state.isPaused);
965
- return E.batch(
966
- () => e.reduce(
967
- (s, r) => s.then(() => r.continue().catch(H)),
968
- Promise.resolve()
969
- )
970
- );
971
- }).then(() => {
972
- o(this, ge, void 0);
973
- })), n(this, ge);
974
- }
975
- }, B = new WeakMap(), Ge = new WeakMap(), ge = new WeakMap(), Yt);
976
- function ar(t) {
977
- return {
978
- onFetch: (e, s) => {
979
- const r = async () => {
980
- var v, j, f, g, w;
981
- const i = e.options, a = (f = (j = (v = e.fetchOptions) == null ? void 0 : v.meta) == null ? void 0 : j.fetchMore) == null ? void 0 : f.direction, c = ((g = e.state.data) == null ? void 0 : g.pages) || [], d = ((w = e.state.data) == null ? void 0 : w.pageParams) || [], p = { pages: [], pageParams: [] };
982
- let b = !1;
983
- const h = (x) => {
984
- Object.defineProperty(x, "signal", {
985
- enumerable: !0,
986
- get: () => (e.signal.aborted ? b = !0 : e.signal.addEventListener("abort", () => {
987
- b = !0;
988
- }), e.signal)
989
- });
990
- }, O = e.options.queryFn || (() => Promise.reject(
991
- new Error(`Missing queryFn: '${e.options.queryHash}'`)
992
- )), k = async (x, F, D) => {
993
- if (b)
994
- return Promise.reject();
995
- if (F == null && x.pages.length)
996
- return Promise.resolve(x);
997
- const I = {
998
- queryKey: e.queryKey,
999
- pageParam: F,
1000
- direction: D ? "backward" : "forward",
1001
- meta: e.options.meta
1002
- };
1003
- h(I);
1004
- const M = await O(
1005
- I
1006
- ), { maxPages: P } = e.options, Z = D ? Js : Ws;
1007
- return {
1008
- pages: Z(x.pages, M, P),
1009
- pageParams: Z(x.pageParams, F, P)
1010
- };
1011
- };
1012
- let m;
1013
- if (a && c.length) {
1014
- const x = a === "backward", F = x ? or : Lt, D = {
1015
- pages: c,
1016
- pageParams: d
1017
- }, I = F(i, D);
1018
- m = await k(D, I, x);
1019
- } else {
1020
- m = await k(
1021
- p,
1022
- d[0] ?? i.initialPageParam
1023
- );
1024
- const x = t ?? c.length;
1025
- for (let F = 1; F < x; F++) {
1026
- const D = Lt(i, m);
1027
- m = await k(m, D);
1028
- }
1029
- }
1030
- return m;
1031
- };
1032
- e.options.persister ? e.fetchFn = () => {
1033
- var i, a;
1034
- return (a = (i = e.options).persister) == null ? void 0 : a.call(
1035
- i,
1036
- r,
1037
- {
1038
- queryKey: e.queryKey,
1039
- meta: e.options.meta,
1040
- signal: e.signal
1041
- },
1042
- s
1043
- );
1044
- } : e.fetchFn = r;
1045
- }
1046
- };
1047
- }
1048
- function Lt(t, { pages: e, pageParams: s }) {
1049
- const r = e.length - 1;
1050
- return t.getNextPageParam(
1051
- e[r],
1052
- e,
1053
- s[r],
1054
- s
1055
- );
1056
- }
1057
- function or(t, { pages: e, pageParams: s }) {
1058
- var r;
1059
- return (r = t.getPreviousPageParam) == null ? void 0 : r.call(
1060
- t,
1061
- e[0],
1062
- e,
1063
- s[0],
1064
- s
1065
- );
1066
- }
1067
- var S, oe, ue, Me, ke, ce, qe, Ue, Xt, ur = (Xt = class {
1068
- constructor(t = {}) {
1069
- l(this, S, void 0);
1070
- l(this, oe, void 0);
1071
- l(this, ue, void 0);
1072
- l(this, Me, void 0);
1073
- l(this, ke, void 0);
1074
- l(this, ce, void 0);
1075
- l(this, qe, void 0);
1076
- l(this, Ue, void 0);
1077
- o(this, S, t.queryCache || new rr()), o(this, oe, t.mutationCache || new ir()), o(this, ue, t.defaultOptions || {}), o(this, Me, /* @__PURE__ */ new Map()), o(this, ke, /* @__PURE__ */ new Map()), o(this, ce, 0);
1078
- }
1079
- mount() {
1080
- it(this, ce)._++, n(this, ce) === 1 && (o(this, qe, ct.subscribe(() => {
1081
- ct.isFocused() && (this.resumePausedMutations(), n(this, S).onFocus());
1082
- })), o(this, Ue, lt.subscribe(() => {
1083
- lt.isOnline() && (this.resumePausedMutations(), n(this, S).onOnline());
1084
- })));
1085
- }
1086
- unmount() {
1087
- var t, e;
1088
- it(this, ce)._--, n(this, ce) === 0 && ((t = n(this, qe)) == null || t.call(this), o(this, qe, void 0), (e = n(this, Ue)) == null || e.call(this), o(this, Ue, void 0));
1089
- }
1090
- isFetching(t) {
1091
- return n(this, S).findAll({ ...t, fetchStatus: "fetching" }).length;
1092
- }
1093
- isMutating(t) {
1094
- return n(this, oe).findAll({ ...t, status: "pending" }).length;
1095
- }
1096
- getQueryData(t) {
1097
- var e;
1098
- return (e = n(this, S).find({ queryKey: t })) == null ? void 0 : e.state.data;
1099
- }
1100
- ensureQueryData(t) {
1101
- const e = this.getQueryData(t.queryKey);
1102
- return e !== void 0 ? Promise.resolve(e) : this.fetchQuery(t);
1103
- }
1104
- getQueriesData(t) {
1105
- return this.getQueryCache().findAll(t).map(({ queryKey: e, state: s }) => {
1106
- const r = s.data;
1107
- return [e, r];
1108
- });
1109
- }
1110
- setQueryData(t, e, s) {
1111
- const r = n(this, S).find({ queryKey: t }), i = r == null ? void 0 : r.state.data, a = Vs(e, i);
1112
- if (typeof a > "u")
1113
- return;
1114
- const c = this.defaultQueryOptions({ queryKey: t });
1115
- return n(this, S).build(this, c).setData(a, { ...s, manual: !0 });
1116
- }
1117
- setQueriesData(t, e, s) {
1118
- return E.batch(
1119
- () => this.getQueryCache().findAll(t).map(({ queryKey: r }) => [
1120
- r,
1121
- this.setQueryData(r, e, s)
1122
- ])
1123
- );
1124
- }
1125
- getQueryState(t) {
1126
- var e;
1127
- return (e = n(this, S).find({ queryKey: t })) == null ? void 0 : e.state;
1128
- }
1129
- removeQueries(t) {
1130
- const e = n(this, S);
1131
- E.batch(() => {
1132
- e.findAll(t).forEach((s) => {
1133
- e.remove(s);
1134
- });
1135
- });
1136
- }
1137
- resetQueries(t, e) {
1138
- const s = n(this, S), r = {
1139
- type: "active",
1140
- ...t
1141
- };
1142
- return E.batch(() => (s.findAll(t).forEach((i) => {
1143
- i.reset();
1144
- }), this.refetchQueries(r, e)));
1145
- }
1146
- cancelQueries(t = {}, e = {}) {
1147
- const s = { revert: !0, ...e }, r = E.batch(
1148
- () => n(this, S).findAll(t).map((i) => i.cancel(s))
1149
- );
1150
- return Promise.all(r).then(H).catch(H);
1151
- }
1152
- invalidateQueries(t = {}, e = {}) {
1153
- return E.batch(() => {
1154
- if (n(this, S).findAll(t).forEach((r) => {
1155
- r.invalidate();
1156
- }), t.refetchType === "none")
1157
- return Promise.resolve();
1158
- const s = {
1159
- ...t,
1160
- type: t.refetchType ?? t.type ?? "active"
1161
- };
1162
- return this.refetchQueries(s, e);
1163
- });
1164
- }
1165
- refetchQueries(t = {}, e) {
1166
- const s = {
1167
- ...e,
1168
- cancelRefetch: (e == null ? void 0 : e.cancelRefetch) ?? !0
1169
- }, r = E.batch(
1170
- () => n(this, S).findAll(t).filter((i) => !i.isDisabled()).map((i) => {
1171
- let a = i.fetch(void 0, s);
1172
- return s.throwOnError || (a = a.catch(H)), i.state.fetchStatus === "paused" ? Promise.resolve() : a;
1173
- })
1174
- );
1175
- return Promise.all(r).then(H);
1176
- }
1177
- fetchQuery(t) {
1178
- const e = this.defaultQueryOptions(t);
1179
- typeof e.retry > "u" && (e.retry = !1);
1180
- const s = n(this, S).build(this, e);
1181
- return s.isStaleByTime(e.staleTime) ? s.fetch(e) : Promise.resolve(s.state.data);
1182
- }
1183
- prefetchQuery(t) {
1184
- return this.fetchQuery(t).then(H).catch(H);
1185
- }
1186
- fetchInfiniteQuery(t) {
1187
- return t.behavior = ar(t.pages), this.fetchQuery(t);
1188
- }
1189
- prefetchInfiniteQuery(t) {
1190
- return this.fetchInfiniteQuery(t).then(H).catch(H);
1191
- }
1192
- resumePausedMutations() {
1193
- return n(this, oe).resumePausedMutations();
1194
- }
1195
- getQueryCache() {
1196
- return n(this, S);
1197
- }
1198
- getMutationCache() {
1199
- return n(this, oe);
1200
- }
1201
- getDefaultOptions() {
1202
- return n(this, ue);
1203
- }
1204
- setDefaultOptions(t) {
1205
- o(this, ue, t);
1206
- }
1207
- setQueryDefaults(t, e) {
1208
- n(this, Me).set(Be(t), {
1209
- queryKey: t,
1210
- defaultOptions: e
1211
- });
1212
- }
1213
- getQueryDefaults(t) {
1214
- const e = [...n(this, Me).values()];
1215
- let s = {};
1216
- return e.forEach((r) => {
1217
- $e(t, r.queryKey) && (s = { ...s, ...r.defaultOptions });
1218
- }), s;
1219
- }
1220
- setMutationDefaults(t, e) {
1221
- n(this, ke).set(Be(t), {
1222
- mutationKey: t,
1223
- defaultOptions: e
1224
- });
1225
- }
1226
- getMutationDefaults(t) {
1227
- const e = [...n(this, ke).values()];
1228
- let s = {};
1229
- return e.forEach((r) => {
1230
- $e(t, r.mutationKey) && (s = { ...s, ...r.defaultOptions });
1231
- }), s;
1232
- }
1233
- defaultQueryOptions(t) {
1234
- if (t != null && t._defaulted)
1235
- return t;
1236
- const e = {
1237
- ...n(this, ue).queries,
1238
- ...(t == null ? void 0 : t.queryKey) && this.getQueryDefaults(t.queryKey),
1239
- ...t,
1240
- _defaulted: !0
1241
- };
1242
- return e.queryHash || (e.queryHash = Mt(
1243
- e.queryKey,
1244
- e
1245
- )), typeof e.refetchOnReconnect > "u" && (e.refetchOnReconnect = e.networkMode !== "always"), typeof e.throwOnError > "u" && (e.throwOnError = !!e.suspense), typeof e.networkMode > "u" && e.persister && (e.networkMode = "offlineFirst"), e;
1246
- }
1247
- defaultMutationOptions(t) {
1248
- return t != null && t._defaulted ? t : {
1249
- ...n(this, ue).mutations,
1250
- ...(t == null ? void 0 : t.mutationKey) && this.getMutationDefaults(t.mutationKey),
1251
- ...t,
1252
- _defaulted: !0
1253
- };
1254
- }
1255
- clear() {
1256
- n(this, S).clear(), n(this, oe).clear();
1257
- }
1258
- }, S = new WeakMap(), oe = new WeakMap(), ue = new WeakMap(), Me = new WeakMap(), ke = new WeakMap(), ce = new WeakMap(), qe = new WeakMap(), Ue = new WeakMap(), Xt), N, C, De, q, be, Qe, X, Ve, Ne, Ie, ve, xe, le, we, Ce, _e, We, xt, Je, wt, Ye, Ct, Xe, Ot, Ze, Pt, et, jt, tt, St, ht, cs, Zt, cr = (Zt = class extends Ke {
1259
- constructor(e, s) {
1260
- super();
1261
- l(this, Ce);
1262
- l(this, We);
1263
- l(this, Je);
1264
- l(this, Ye);
1265
- l(this, Xe);
1266
- l(this, Ze);
1267
- l(this, et);
1268
- l(this, tt);
1269
- l(this, ht);
1270
- l(this, N, void 0);
1271
- l(this, C, void 0);
1272
- l(this, De, void 0);
1273
- l(this, q, void 0);
1274
- l(this, be, void 0);
1275
- l(this, Qe, void 0);
1276
- l(this, X, void 0);
1277
- l(this, Ve, void 0);
1278
- l(this, Ne, void 0);
1279
- // This property keeps track of the last query with defined data.
1280
- // It will be used to pass the previous data and query to the placeholder function between renders.
1281
- l(this, Ie, void 0);
1282
- l(this, ve, void 0);
1283
- l(this, xe, void 0);
1284
- l(this, le, void 0);
1285
- l(this, we, void 0);
1286
- o(this, C, void 0), o(this, De, void 0), o(this, q, void 0), o(this, we, /* @__PURE__ */ new Set()), o(this, N, e), this.options = s, o(this, X, null), this.bindMethods(), this.setOptions(s);
1287
- }
1288
- bindMethods() {
1289
- this.refetch = this.refetch.bind(this);
1290
- }
1291
- onSubscribe() {
1292
- this.listeners.size === 1 && (n(this, C).addObserver(this), Kt(n(this, C), this.options) ? y(this, Ce, _e).call(this) : this.updateResult(), y(this, Xe, Ot).call(this));
1293
- }
1294
- onUnsubscribe() {
1295
- this.hasListeners() || this.destroy();
1296
- }
1297
- shouldFetchOnReconnect() {
1298
- return Et(
1299
- n(this, C),
1300
- this.options,
1301
- this.options.refetchOnReconnect
1302
- );
1303
- }
1304
- shouldFetchOnWindowFocus() {
1305
- return Et(
1306
- n(this, C),
1307
- this.options,
1308
- this.options.refetchOnWindowFocus
1309
- );
1310
- }
1311
- destroy() {
1312
- this.listeners = /* @__PURE__ */ new Set(), y(this, Ze, Pt).call(this), y(this, et, jt).call(this), n(this, C).removeObserver(this);
1313
- }
1314
- setOptions(e, s) {
1315
- const r = this.options, i = n(this, C);
1316
- if (this.options = n(this, N).defaultQueryOptions(e), ut(r, this.options) || n(this, N).getQueryCache().notify({
1317
- type: "observerOptionsUpdated",
1318
- query: n(this, C),
1319
- observer: this
1320
- }), typeof this.options.enabled < "u" && typeof this.options.enabled != "boolean")
1321
- throw new Error("Expected enabled to be a boolean");
1322
- this.options.queryKey || (this.options.queryKey = r.queryKey), y(this, tt, St).call(this);
1323
- const a = this.hasListeners();
1324
- a && _t(
1325
- n(this, C),
1326
- i,
1327
- this.options,
1328
- r
1329
- ) && y(this, Ce, _e).call(this), this.updateResult(s), a && (n(this, C) !== i || this.options.enabled !== r.enabled || this.options.staleTime !== r.staleTime) && y(this, We, xt).call(this);
1330
- const c = y(this, Je, wt).call(this);
1331
- a && (n(this, C) !== i || this.options.enabled !== r.enabled || c !== n(this, le)) && y(this, Ye, Ct).call(this, c);
1332
- }
1333
- getOptimisticResult(e) {
1334
- const s = n(this, N).getQueryCache().build(n(this, N), e), r = this.createResult(s, e);
1335
- return hr(this, r) && (o(this, q, r), o(this, Qe, this.options), o(this, be, n(this, C).state)), r;
1336
- }
1337
- getCurrentResult() {
1338
- return n(this, q);
1339
- }
1340
- trackResult(e) {
1341
- const s = {};
1342
- return Object.keys(e).forEach((r) => {
1343
- Object.defineProperty(s, r, {
1344
- configurable: !1,
1345
- enumerable: !0,
1346
- get: () => (n(this, we).add(r), e[r])
1347
- });
1348
- }), s;
1349
- }
1350
- getCurrentQuery() {
1351
- return n(this, C);
1352
- }
1353
- refetch({ ...e } = {}) {
1354
- return this.fetch({
1355
- ...e
1356
- });
1357
- }
1358
- fetchOptimistic(e) {
1359
- const s = n(this, N).defaultQueryOptions(e), r = n(this, N).getQueryCache().build(n(this, N), s);
1360
- return r.isFetchingOptimistic = !0, r.fetch().then(() => this.createResult(r, s));
1361
- }
1362
- fetch(e) {
1363
- return y(this, Ce, _e).call(this, {
1364
- ...e,
1365
- cancelRefetch: e.cancelRefetch ?? !0
1366
- }).then(() => (this.updateResult(), n(this, q)));
1367
- }
1368
- createResult(e, s) {
1369
- var I;
1370
- const r = n(this, C), i = this.options, a = n(this, q), c = n(this, be), d = n(this, Qe), b = e !== r ? e.state : n(this, De), { state: h } = e;
1371
- let { error: O, errorUpdatedAt: k, fetchStatus: m, status: v } = h, j = !1, f;
1372
- if (s._optimisticResults) {
1373
- const M = this.hasListeners(), P = !M && Kt(e, s), Z = M && _t(e, r, s, i);
1374
- (P || Z) && (m = dt(e.options.networkMode) ? "fetching" : "paused", h.dataUpdatedAt || (v = "pending")), s._optimisticResults === "isRestoring" && (m = "idle");
1375
- }
1376
- if (s.select && typeof h.data < "u")
1377
- if (a && h.data === (c == null ? void 0 : c.data) && s.select === n(this, Ve))
1378
- f = n(this, Ne);
1379
- else
1380
- try {
1381
- o(this, Ve, s.select), f = s.select(h.data), f = vt(a == null ? void 0 : a.data, f, s), o(this, Ne, f), o(this, X, null);
1382
- } catch (M) {
1383
- o(this, X, M);
1384
- }
1385
- else
1386
- f = h.data;
1387
- if (typeof s.placeholderData < "u" && typeof f > "u" && v === "pending") {
1388
- let M;
1389
- if (a != null && a.isPlaceholderData && s.placeholderData === (d == null ? void 0 : d.placeholderData))
1390
- M = a.data;
1391
- else if (M = typeof s.placeholderData == "function" ? s.placeholderData(
1392
- (I = n(this, Ie)) == null ? void 0 : I.state.data,
1393
- n(this, Ie)
1394
- ) : s.placeholderData, s.select && typeof M < "u")
1395
- try {
1396
- M = s.select(M), o(this, X, null);
1397
- } catch (P) {
1398
- o(this, X, P);
1399
- }
1400
- typeof M < "u" && (v = "success", f = vt(
1401
- a == null ? void 0 : a.data,
1402
- M,
1403
- s
1404
- ), j = !0);
1405
- }
1406
- n(this, X) && (O = n(this, X), f = n(this, Ne), k = Date.now(), v = "error");
1407
- const g = m === "fetching", w = v === "pending", x = v === "error", F = w && g;
1408
- return {
1409
- status: v,
1410
- fetchStatus: m,
1411
- isPending: w,
1412
- isSuccess: v === "success",
1413
- isError: x,
1414
- isInitialLoading: F,
1415
- isLoading: F,
1416
- data: f,
1417
- dataUpdatedAt: h.dataUpdatedAt,
1418
- error: O,
1419
- errorUpdatedAt: k,
1420
- failureCount: h.fetchFailureCount,
1421
- failureReason: h.fetchFailureReason,
1422
- errorUpdateCount: h.errorUpdateCount,
1423
- isFetched: h.dataUpdateCount > 0 || h.errorUpdateCount > 0,
1424
- isFetchedAfterMount: h.dataUpdateCount > b.dataUpdateCount || h.errorUpdateCount > b.errorUpdateCount,
1425
- isFetching: g,
1426
- isRefetching: g && !w,
1427
- isLoadingError: x && h.dataUpdatedAt === 0,
1428
- isPaused: m === "paused",
1429
- isPlaceholderData: j,
1430
- isRefetchError: x && h.dataUpdatedAt !== 0,
1431
- isStale: kt(e, s),
1432
- refetch: this.refetch
1433
- };
1434
- }
1435
- updateResult(e) {
1436
- const s = n(this, q), r = this.createResult(n(this, C), this.options);
1437
- if (o(this, be, n(this, C).state), o(this, Qe, this.options), n(this, be).data !== void 0 && o(this, Ie, n(this, C)), ut(r, s))
1438
- return;
1439
- o(this, q, r);
1440
- const i = {}, a = () => {
1441
- if (!s)
1442
- return !0;
1443
- const { notifyOnChangeProps: c } = this.options, d = typeof c == "function" ? c() : c;
1444
- if (d === "all" || !d && !n(this, we).size)
1445
- return !0;
1446
- const p = new Set(
1447
- d ?? n(this, we)
1448
- );
1449
- return this.options.throwOnError && p.add("error"), Object.keys(n(this, q)).some((b) => {
1450
- const h = b;
1451
- return n(this, q)[h] !== s[h] && p.has(h);
1452
- });
1453
- };
1454
- (e == null ? void 0 : e.listeners) !== !1 && a() && (i.listeners = !0), y(this, ht, cs).call(this, { ...i, ...e });
1455
- }
1456
- onQueryUpdate() {
1457
- this.updateResult(), this.hasListeners() && y(this, Xe, Ot).call(this);
1458
- }
1459
- }, N = new WeakMap(), C = new WeakMap(), De = new WeakMap(), q = new WeakMap(), be = new WeakMap(), Qe = new WeakMap(), X = new WeakMap(), Ve = new WeakMap(), Ne = new WeakMap(), Ie = new WeakMap(), ve = new WeakMap(), xe = new WeakMap(), le = new WeakMap(), we = new WeakMap(), Ce = new WeakSet(), _e = function(e) {
1460
- y(this, tt, St).call(this);
1461
- let s = n(this, C).fetch(
1462
- this.options,
1463
- e
1464
- );
1465
- return e != null && e.throwOnError || (s = s.catch(H)), s;
1466
- }, We = new WeakSet(), xt = function() {
1467
- if (y(this, Ze, Pt).call(this), Le || n(this, q).isStale || !gt(this.options.staleTime))
1468
- return;
1469
- const s = ss(
1470
- n(this, q).dataUpdatedAt,
1471
- this.options.staleTime
1472
- ) + 1;
1473
- o(this, ve, setTimeout(() => {
1474
- n(this, q).isStale || this.updateResult();
1475
- }, s));
1476
- }, Je = new WeakSet(), wt = function() {
1477
- return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(n(this, C)) : this.options.refetchInterval) ?? !1;
1478
- }, Ye = new WeakSet(), Ct = function(e) {
1479
- y(this, et, jt).call(this), o(this, le, e), !(Le || this.options.enabled === !1 || !gt(n(this, le)) || n(this, le) === 0) && o(this, xe, setInterval(() => {
1480
- (this.options.refetchIntervalInBackground || ct.isFocused()) && y(this, Ce, _e).call(this);
1481
- }, n(this, le)));
1482
- }, Xe = new WeakSet(), Ot = function() {
1483
- y(this, We, xt).call(this), y(this, Ye, Ct).call(this, y(this, Je, wt).call(this));
1484
- }, Ze = new WeakSet(), Pt = function() {
1485
- n(this, ve) && (clearTimeout(n(this, ve)), o(this, ve, void 0));
1486
- }, et = new WeakSet(), jt = function() {
1487
- n(this, xe) && (clearInterval(n(this, xe)), o(this, xe, void 0));
1488
- }, tt = new WeakSet(), St = function() {
1489
- const e = n(this, N).getQueryCache().build(n(this, N), this.options);
1490
- if (e === n(this, C))
1491
- return;
1492
- const s = n(this, C);
1493
- o(this, C, e), o(this, De, e.state), this.hasListeners() && (s == null || s.removeObserver(this), e.addObserver(this));
1494
- }, ht = new WeakSet(), cs = function(e) {
1495
- E.batch(() => {
1496
- e.listeners && this.listeners.forEach((s) => {
1497
- s(n(this, q));
1498
- }), n(this, N).getQueryCache().notify({
1499
- query: n(this, C),
1500
- type: "observerResultsUpdated"
1501
- });
1502
- });
1503
- }, Zt);
1504
- function lr(t, e) {
1505
- return e.enabled !== !1 && !t.state.dataUpdatedAt && !(t.state.status === "error" && e.retryOnMount === !1);
1506
- }
1507
- function Kt(t, e) {
1508
- return lr(t, e) || t.state.dataUpdatedAt > 0 && Et(t, e, e.refetchOnMount);
1509
- }
1510
- function Et(t, e, s) {
1511
- if (e.enabled !== !1) {
1512
- const r = typeof s == "function" ? s(t) : s;
1513
- return r === "always" || r !== !1 && kt(t, e);
1514
- }
1515
- return !1;
1516
- }
1517
- function _t(t, e, s, r) {
1518
- return s.enabled !== !1 && (t !== e || r.enabled === !1) && (!s.suspense || t.state.status !== "error") && kt(t, s);
1519
- }
1520
- function kt(t, e) {
1521
- return t.isStaleByTime(e.staleTime);
1522
- }
1523
- function hr(t, e) {
1524
- return !ut(t.getCurrentResult(), e);
1525
- }
1526
- var he, Q, $, te, Te, ot, st, Ft, es, dr = (es = class extends Ke {
1527
- constructor(e, s) {
1528
- super();
1529
- l(this, Te);
1530
- l(this, st);
1531
- l(this, he, void 0);
1532
- l(this, Q, void 0);
1533
- l(this, $, void 0);
1534
- l(this, te, void 0);
1535
- o(this, Q, void 0), o(this, he, e), this.setOptions(s), this.bindMethods(), y(this, Te, ot).call(this);
1536
- }
1537
- bindMethods() {
1538
- this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
1539
- }
1540
- setOptions(e) {
1541
- var r;
1542
- const s = this.options;
1543
- this.options = n(this, he).defaultMutationOptions(e), ut(s, this.options) || n(this, he).getMutationCache().notify({
1544
- type: "observerOptionsUpdated",
1545
- mutation: n(this, $),
1546
- observer: this
1547
- }), (r = n(this, $)) == null || r.setOptions(this.options);
1548
- }
1549
- onUnsubscribe() {
1550
- var e;
1551
- this.hasListeners() || (e = n(this, $)) == null || e.removeObserver(this);
1552
- }
1553
- onMutationUpdate(e) {
1554
- y(this, Te, ot).call(this), y(this, st, Ft).call(this, e);
1555
- }
1556
- getCurrentResult() {
1557
- return n(this, Q);
1558
- }
1559
- reset() {
1560
- o(this, $, void 0), y(this, Te, ot).call(this), y(this, st, Ft).call(this);
1561
- }
1562
- mutate(e, s) {
1563
- var r;
1564
- return o(this, te, s), (r = n(this, $)) == null || r.removeObserver(this), o(this, $, n(this, he).getMutationCache().build(n(this, he), this.options)), n(this, $).addObserver(this), n(this, $).execute(e);
1565
- }
1566
- }, he = new WeakMap(), Q = new WeakMap(), $ = new WeakMap(), te = new WeakMap(), Te = new WeakSet(), ot = function() {
1567
- var s;
1568
- const e = ((s = n(this, $)) == null ? void 0 : s.state) ?? us();
1569
- o(this, Q, {
1570
- ...e,
1571
- isPending: e.status === "pending",
1572
- isSuccess: e.status === "success",
1573
- isError: e.status === "error",
1574
- isIdle: e.status === "idle",
1575
- mutate: this.mutate,
1576
- reset: this.reset
1577
- });
1578
- }, st = new WeakSet(), Ft = function(e) {
1579
- E.batch(() => {
1580
- var s, r, i, a, c, d, p, b;
1581
- n(this, te) && this.hasListeners() && ((e == null ? void 0 : e.type) === "success" ? ((r = (s = n(this, te)).onSuccess) == null || r.call(
1582
- s,
1583
- e.data,
1584
- n(this, Q).variables,
1585
- n(this, Q).context
1586
- ), (a = (i = n(this, te)).onSettled) == null || a.call(
1587
- i,
1588
- e.data,
1589
- null,
1590
- n(this, Q).variables,
1591
- n(this, Q).context
1592
- )) : (e == null ? void 0 : e.type) === "error" && ((d = (c = n(this, te)).onError) == null || d.call(
1593
- c,
1594
- e.error,
1595
- n(this, Q).variables,
1596
- n(this, Q).context
1597
- ), (b = (p = n(this, te)).onSettled) == null || b.call(
1598
- p,
1599
- void 0,
1600
- e.error,
1601
- n(this, Q).variables,
1602
- n(this, Q).context
1603
- ))), this.listeners.forEach((h) => {
1604
- h(n(this, Q));
1605
- });
1606
- });
1607
- }, es), ls = R.createContext(
1608
- void 0
1609
- ), z = (t) => {
1610
- const e = R.useContext(ls);
1611
- if (t)
1612
- return t;
1613
- if (!e)
1614
- throw new Error("No QueryClient set, use QueryClientProvider to set one");
1615
- return e;
1616
- }, fr = ({
1617
- client: t,
1618
- children: e
1619
- }) => (R.useEffect(() => (t.mount(), () => {
1620
- t.unmount();
1621
- }), [t]), /* @__PURE__ */ R.createElement(ls.Provider, { value: t }, e)), hs = R.createContext(!1), yr = () => R.useContext(hs);
1622
- hs.Provider;
1623
- function pr() {
1624
- let t = !1;
1625
- return {
1626
- clearReset: () => {
1627
- t = !1;
1628
- },
1629
- reset: () => {
1630
- t = !0;
1631
- },
1632
- isReset: () => t
1633
- };
1634
- }
1635
- var mr = R.createContext(pr()), gr = () => R.useContext(mr);
1636
- function ds(t, e) {
1637
- return typeof t == "function" ? t(...e) : !!t;
1638
- }
1639
- var br = (t, e) => {
1640
- (t.suspense || t.throwOnError) && (e.isReset() || (t.retryOnMount = !1));
1641
- }, vr = (t) => {
1642
- R.useEffect(() => {
1643
- t.clearReset();
1644
- }, [t]);
1645
- }, xr = ({
1646
- result: t,
1647
- errorResetBoundary: e,
1648
- throwOnError: s,
1649
- query: r
1650
- }) => t.isError && !e.isReset() && !t.isFetching && ds(s, [t.error, r]), wr = (t) => {
1651
- t.suspense && typeof t.staleTime != "number" && (t.staleTime = 1e3);
1652
- }, Cr = (t, e) => (t == null ? void 0 : t.suspense) && e.isPending, Or = (t, e, s) => e.fetchOptimistic(t).catch(() => {
1653
- s.clearReset();
1654
- });
1655
- function Pr(t, e, s) {
1656
- if (process.env.NODE_ENV !== "production" && (typeof t != "object" || Array.isArray(t)))
1657
- throw new Error(
1658
- 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
1659
- );
1660
- const r = z(s), i = yr(), a = gr(), c = r.defaultQueryOptions(t);
1661
- c._optimisticResults = i ? "isRestoring" : "optimistic", wr(c), br(c, a), vr(a);
1662
- const [d] = R.useState(
1663
- () => new e(
1664
- r,
1665
- c
1666
- )
1667
- ), p = d.getOptimisticResult(c);
1668
- if (R.useSyncExternalStore(
1669
- R.useCallback(
1670
- (b) => {
1671
- const h = i ? () => {
1672
- } : d.subscribe(E.batchCalls(b));
1673
- return d.updateResult(), h;
1674
- },
1675
- [d, i]
1676
- ),
1677
- () => d.getCurrentResult(),
1678
- () => d.getCurrentResult()
1679
- ), R.useEffect(() => {
1680
- d.setOptions(c, { listeners: !1 });
1681
- }, [c, d]), Cr(c, p))
1682
- throw Or(c, d, a);
1683
- if (xr({
1684
- result: p,
1685
- errorResetBoundary: a,
1686
- throwOnError: c.throwOnError,
1687
- query: d.getCurrentQuery()
1688
- }))
1689
- throw p.error;
1690
- return c.notifyOnChangeProps ? p : d.trackResult(p);
1691
- }
1692
- function rt(t, e) {
1693
- return Pr(t, cr, e);
1694
- }
1695
- function V(t, e) {
1696
- const s = z(e), [r] = R.useState(
1697
- () => new dr(
1698
- s,
1699
- t
1700
- )
1701
- );
1702
- R.useEffect(() => {
1703
- r.setOptions(t);
1704
- }, [r, t]);
1705
- const i = R.useSyncExternalStore(
1706
- R.useCallback(
1707
- (c) => r.subscribe(E.batchCalls(c)),
1708
- [r]
1709
- ),
1710
- () => r.getCurrentResult(),
1711
- () => r.getCurrentResult()
1712
- ), a = R.useCallback(
1713
- (c, d) => {
1714
- r.mutate(c, d).catch(jr);
1715
- },
1716
- [r]
1717
- );
1718
- if (i.error && ds(r.options.throwOnError, [i.error]))
1719
- throw i.error;
1720
- return { ...i, mutate: a, mutateAsync: i.mutate };
1721
- }
1722
- function jr() {
1723
- }
1724
- function U() {
1725
- return z().getQueryData(["apiBaseUrl"]) || "/api/chaibuilder";
1726
- }
1727
- const Oe = () => {
1728
- const { data: t, refetch: e } = rt({
1729
- queryKey: ["currentPage"],
1730
- queryFn: () => localStorage.getItem("currentPage") || ""
1731
- });
1732
- return [
1733
- t,
1734
- (s) => {
1735
- s && (localStorage.setItem("currentPage", s || ""), e());
1736
- }
1737
- ];
1738
- };
1739
- let Bt = "";
1740
- const nt = () => (Bt = localStorage.getItem("__chai_at"), Bt);
1741
- function Sr(t) {
1742
- const e = {
1743
- method: "GET",
1744
- headers: { "x-chai-access-token": nt() }
1745
- };
1746
- return fetch(t, e);
1747
- }
1748
- function Er(t, e) {
1749
- const s = {
1750
- method: "POST",
1751
- headers: { "x-chai-access-token": nt() },
1752
- body: JSON.stringify(e)
1753
- };
1754
- return fetch(t, s);
1755
- }
1756
- function Fr(t, e) {
1757
- const s = {
1758
- method: "PUT",
1759
- headers: { "x-chai-access-token": nt() },
1760
- body: JSON.stringify(e)
1761
- };
1762
- return fetch(t, s);
1763
- }
1764
- function Ar(t, e) {
1765
- const s = {
1766
- method: "DELETE",
1767
- headers: { "x-chai-access-token": nt() },
1768
- body: JSON.stringify(e)
1769
- };
1770
- return fetch(t, s);
1771
- }
1772
- const L = {
1773
- get: Sr,
1774
- post: Er,
1775
- put: Fr,
1776
- delete: Ar
1777
- }, fs = () => {
1778
- const [t, e] = Oe(), s = U();
1779
- return rt({
1780
- queryKey: ["project"],
1781
- queryFn: async () => {
1782
- const { data: r } = await L.get(`${s}/project`).then((i) => i.json());
1783
- if (!t && r) {
1784
- const i = localStorage.getItem("currentPage");
1785
- e(i || (r == null ? void 0 : r.homepage));
1786
- }
1787
- return r;
1788
- }
1789
- });
1790
- }, ys = () => {
1791
- const t = U();
1792
- return rt({
1793
- queryKey: ["pages"],
1794
- queryFn: async () => {
1795
- const { data: e } = await L.get(`${t}/pages`).then((s) => s.json());
1796
- return e || [];
1797
- }
1798
- });
1799
- }, ps = () => {
1800
- const [t] = Oe(), e = U();
1801
- return rt({
1802
- queryKey: ["page_data", t],
1803
- queryFn: async () => {
1804
- const { data: s } = await L.get(`${e}/page?uuid=${t}`).then((r) => r.json());
1805
- return s;
1806
- },
1807
- enabled: !!t,
1808
- staleTime: 3e3
1809
- });
1810
- }, At = () => /* @__PURE__ */ u.jsx("div", { className: "h-screen w-screen bg-gray-200", children: /* @__PURE__ */ u.jsxs("div", { className: "flex flex-col h-full w-full justify-center items-center", children: [
1811
- /* @__PURE__ */ u.jsxs("div", { className: "flex flex-row gap-2", children: [
1812
- /* @__PURE__ */ u.jsx("div", { className: "w-4 h-4 rounded-full bg-orange-600 animate-bounce [animation-delay:.6s]" }),
1813
- /* @__PURE__ */ u.jsx("div", { className: "w-4 h-4 rounded-full bg-blue-600 animate-bounce [animation-delay:.4s]" }),
1814
- /* @__PURE__ */ u.jsx("div", { className: "w-4 h-4 rounded-full bg-green-600 animate-bounce [animation-delay:.2s]" }),
1815
- /* @__PURE__ */ u.jsx("div", { className: "w-4 h-4 rounded-full bg-yellow-600 animate-bounce [animation-delay:.0s]" })
1816
- ] }),
1817
- /* @__PURE__ */ u.jsx("div", { className: "text-gray-700 font-thin", children: "Loading Builder..." })
1818
- ] }) }), Rr = (t = "Project updated successfully.") => {
1819
- const e = z(), s = U();
1820
- return V({
1821
- mutationFn: async (r) => await L.put(`${s}/project`, r).then((i) => i.json()),
1822
- onSuccess: () => {
1823
- e.invalidateQueries({ queryKey: ["project"] }), se.success(t);
1824
- }
1825
- });
1826
- }, Mr = () => {
1827
- const [t] = ["SAVED"], [e, s] = Oe(), r = Cs();
1828
- return (i) => t !== "SAVED" ? (se.error("You have unsaved changes. Please save before changing the page."), !1) : e === i.uuid ? !1 : (r(), setTimeout(() => {
1829
- s(i.uuid);
1830
- }, 100), !0);
1831
- }, mn = () => {
1832
- const t = z(), e = Mr(), s = U();
1833
- return V({
1834
- mutationFn: async (r) => L.post(`${s}/pages`, r).then((i) => i.json()),
1835
- onSuccess: (r) => {
1836
- t.invalidateQueries({ queryKey: ["pages"] }), e({ uuid: r.uuid, slug: r.slug }), se.success("Page added successfully.");
1837
- }
1838
- });
1839
- }, kr = () => {
1840
- const t = U(), [e] = Oe(), s = z();
1841
- return V({
1842
- mutationFn: async (r) => L.put(`${t}/page`, r).then((i) => i.json()),
1843
- onSuccess: async (r) => {
1844
- var i;
1845
- if (r.result === "error" && ((i = r.error) == null ? void 0 : i.code) == "PAGE_LOCKED") {
1846
- s.invalidateQueries({ queryKey: ["page_data", e] });
1847
- return;
1848
- }
1849
- se.success("Page saved successfully.");
1850
- }
1851
- });
1852
- }, qr = () => {
1853
- const t = U(), { data: e } = ys(), [s] = Oe(), { data: r } = fs(), i = z();
1854
- return V({
1855
- mutationFn: async () => {
1856
- const a = e.find((c) => c.uuid === s).slug;
1857
- return await L.post(`${t}/publish`, {
1858
- slug: a,
1859
- uuid: s,
1860
- isHomepage: (r == null ? void 0 : r.homepage) === s
1861
- }).then((c) => c.json());
1862
- },
1863
- onSuccess: async (a) => {
1864
- var c;
1865
- if (a.result === "error" && ((c = a.error) == null ? void 0 : c.code) == "PAGE_LOCKED") {
1866
- i.invalidateQueries({ queryKey: ["page_data", s] });
1867
- return;
1868
- }
1869
- se.success("Page published successfully.", {
1870
- position: "top-right",
1871
- duration: 2e3
1872
- });
1873
- }
1874
- });
1875
- }, gn = () => {
1876
- const t = z(), e = U();
1877
- return V({
1878
- mutationFn: async (s) => L.delete(`${e}/page`, s).then((r) => r.json()),
1879
- onSuccess: () => {
1880
- se.success("Page deleted successfully."), t.invalidateQueries({ queryKey: ["pages"] });
1881
- }
1882
- });
1883
- }, Ur = () => {
1884
- const t = z(), e = U();
1885
- return V({
1886
- mutationFn: async (s) => L.post(`${e}/take-control`, { uuid: s }).then((r) => r.json()),
1887
- onSuccess: (s, r) => {
1888
- t.invalidateQueries({ queryKey: ["page_data", r] });
1889
- }
1890
- });
1891
- }, Dr = () => {
1892
- const t = U();
1893
- return V({
1894
- mutationFn: async () => {
1895
- const { data: e } = await L.get(`${t}/library`).then((s) => s.json());
1896
- return Ms(
1897
- ks(e, (s) => !qs(s, "hidden")),
1898
- "group"
1899
- );
1900
- }
1901
- });
1902
- }, Qr = () => {
1903
- const t = U();
1904
- return V({
1905
- mutationFn: async (e) => {
1906
- if (!e || !e.uuid)
1907
- return [];
1908
- try {
1909
- const { data: s } = await L.get(`${t}/block?uuid=${e.uuid}&format=${e.format}`).then(async (r) => e.format === "html" ? Rs(await r.text()) : await r.json());
1910
- return Us(s, "0._name", Ds(e.group)), s || [];
1911
- } catch {
1912
- return [];
1913
- }
1914
- }
1915
- });
1916
- }, Nr = () => {
1917
- const t = U();
1918
- return V({
1919
- mutationFn: async (e) => {
1920
- const s = new FormData();
1921
- s.append("file", e);
1922
- const { data: r } = await fetch(`${t}/upload`, {
1923
- method: "POST",
1924
- headers: { "x-chai-access-token": nt() },
1925
- body: s
1926
- }).then((i) => i.json());
1927
- return r;
1928
- }
1929
- });
1930
- };
1931
- var ms = {
1932
- color: void 0,
1933
- size: void 0,
1934
- className: void 0,
1935
- style: void 0,
1936
- attr: void 0
1937
- }, $t = de.createContext && de.createContext(ms), fe = function() {
1938
- return fe = Object.assign || function(t) {
1939
- for (var e, s = 1, r = arguments.length; s < r; s++) {
1940
- e = arguments[s];
1941
- for (var i in e)
1942
- Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
1943
- }
1944
- return t;
1945
- }, fe.apply(this, arguments);
1946
- }, Ir = function(t, e) {
1947
- var s = {};
1948
- for (var r in t)
1949
- Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (s[r] = t[r]);
1950
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
1951
- for (var i = 0, r = Object.getOwnPropertySymbols(t); i < r.length; i++)
1952
- e.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[i]) && (s[r[i]] = t[r[i]]);
1953
- return s;
1954
- };
1955
- function gs(t) {
1956
- return t && t.map(function(e, s) {
1957
- return de.createElement(e.tag, fe({
1958
- key: s
1959
- }, e.attr), gs(e.child));
1960
- });
1961
- }
1962
- function bs(t) {
1963
- return function(e) {
1964
- return de.createElement(Tr, fe({
1965
- attr: fe({}, t.attr)
1966
- }, e), gs(t.child));
1967
- };
1968
- }
1969
- function Tr(t) {
1970
- var e = function(s) {
1971
- var r = t.attr, i = t.size, a = t.title, c = Ir(t, ["attr", "size", "title"]), d = i || s.size || "1em", p;
1972
- return s.className && (p = s.className), t.className && (p = (p ? p + " " : "") + t.className), de.createElement("svg", fe({
1973
- stroke: "currentColor",
1974
- fill: "currentColor",
1975
- strokeWidth: "0"
1976
- }, s.attr, r, c, {
1977
- className: p,
1978
- style: fe(fe({
1979
- color: t.color || s.color
1980
- }, s.style), t.style),
1981
- height: d,
1982
- width: d,
1983
- xmlns: "http://www.w3.org/2000/svg"
1984
- }), a && de.createElement("title", null, a), t.children);
1985
- };
1986
- return $t !== void 0 ? de.createElement($t.Consumer, null, function(s) {
1987
- return e(s);
1988
- }) : e(ms);
1989
- }
1990
- function vs(t) {
1991
- return bs({ tag: "svg", attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" } }, { tag: "path", attr: { d: "M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z" } }] })(t);
1992
- }
1993
- function Lr(t) {
1994
- return bs({ tag: "svg", attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" } }, { tag: "path", attr: { d: "M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" } }] })(t);
1995
- }
1996
- const Kr = () => {
1997
- const { mutate: t, isPending: e } = Ur(), [s] = Oe(), { data: r } = ps(), i = qt(r, "lockedBy.name", ""), a = qt(r, "lockedBy.email", "");
1998
- return /* @__PURE__ */ u.jsxs("div", { className: "bg-white dark:bg-gray-800 rounded-lg drop-shadow-2xl mx-auto p-10 space-y-4 text-center max-w-xl", children: [
1999
- /* @__PURE__ */ u.jsxs("h2", { className: "text-2xl font-bold", children: [
2000
- "Page is ",
2001
- /* @__PURE__ */ u.jsx("span", { className: "text-red-500", children: "locked" })
2002
- ] }),
2003
- /* @__PURE__ */ u.jsxs("div", { className: "text-gray-500 dark:text-gray-400 font-light", children: [
2004
- "This page is currently being edited by ",
2005
- /* @__PURE__ */ u.jsx("br", {}),
2006
- /* @__PURE__ */ u.jsxs("div", { className: "flex items-center gap-x-3 w-max mx-auto font-medium text-gray-700 mt-2 text-sm", children: [
2007
- /* @__PURE__ */ u.jsxs("div", { className: "flex items-center gap-x-2 bg-gray-100 py-1 px-2 rounded-md", children: [
2008
- /* @__PURE__ */ u.jsx(Lr, { className: "w-4 h-4 text-gray-500" }),
2009
- " ",
2010
- i
2011
- ] }),
2012
- /* @__PURE__ */ u.jsxs("div", { className: "flex items-center gap-x-2 bg-gray-100 py-1 px-2 rounded-md lowercase", children: [
2013
- /* @__PURE__ */ u.jsx(vs, { className: "w-4 h-4 text-gray-500" }),
2014
- " ",
2015
- a
2016
- ] })
2017
- ] }),
2018
- /* @__PURE__ */ u.jsxs("div", { className: "pt-4", children: [
2019
- "If you take control, ",
2020
- i,
2021
- " will be ",
2022
- /* @__PURE__ */ u.jsx("span", { className: "text-red-500", children: "restricted" }),
2023
- " from making additional edits."
2024
- ] })
2025
- ] }),
2026
- /* @__PURE__ */ u.jsx(
2027
- ts,
2028
- {
2029
- disabled: e,
2030
- onClick: () => t(s),
2031
- className: `w-36 ${e ? "bg-transparent shadow-none hover:bg-transparent" : ""}`,
2032
- children: e ? /* @__PURE__ */ u.jsx(Ns, { className: "text-sm animate-spin text-gray-500" }) : "Take Over"
2033
- }
2034
- )
2035
- ] });
2036
- }, _r = () => {
2037
- const t = U(), e = z();
2038
- return V({
2039
- mutationFn: async (s) => {
2040
- const r = await fetch(`${t}/login`, { method: "POST", body: JSON.stringify(s) });
2041
- if (r.ok)
2042
- return await r.json();
2043
- throw r.status === 401 ? new Error("Invalid login credentials") : new Error("Invalid");
2044
- },
2045
- onSuccess: (s) => {
2046
- const { data: r } = s;
2047
- if (!r.accessToken) {
2048
- se.error("Something went wrong. Please try again.", { position: "top-center" });
2049
- return;
2050
- }
2051
- localStorage.setItem("__chai_at", r.accessToken), localStorage.setItem("__chai_ur", JSON.stringify(Qs(r, ["accessToken"]))), e.invalidateQueries({ queryKey: ["verify"] }), se.success("Logged in successfully.");
2052
- },
2053
- onError: () => {
2054
- se.error("Invalid login credentials. Please try again.", { position: "top-center" });
2055
- }
2056
- });
2057
- }, Br = () => {
2058
- const t = U();
2059
- return rt({
2060
- queryKey: ["verify"],
2061
- queryFn: async () => {
2062
- const e = await L.get(`${t}/verify`);
2063
- return e.ok ? (await e.json()).result === "success" ? { valid: !0 } : (localStorage.removeItem("__chai_at"), { valid: !1 }) : (localStorage.removeItem("__chai_at"), { valid: !0 });
2064
- }
2065
- });
2066
- }, $r = () => {
2067
- const t = U(), e = z();
2068
- return V({
2069
- mutationFn: async () => {
2070
- const { result: s } = await L.post(`${t}/logout`).then((r) => r.json());
2071
- if (s === "success")
2072
- return localStorage.clear(), e.invalidateQueries({ queryKey: ["verify"] }), { logout: !0 };
2073
- throw new Error("Invalid session");
2074
- }
2075
- });
2076
- }, Hr = ({ children: t }) => {
2077
- const e = $r();
2078
- return /* @__PURE__ */ u.jsxs(Ls, { children: [
2079
- /* @__PURE__ */ u.jsx(Ks, { asChild: !0, children: t }),
2080
- /* @__PURE__ */ u.jsxs(_s, { children: [
2081
- /* @__PURE__ */ u.jsxs(Bs, { children: [
2082
- /* @__PURE__ */ u.jsxs($s, { children: [
2083
- "Are you sure, you want to ",
2084
- /* @__PURE__ */ u.jsx("span", { className: "text-red-500", children: "Sign Out" }),
2085
- "?"
2086
- ] }),
2087
- /* @__PURE__ */ u.jsx(Hs, { children: "Kindly ensure that all your data is saved before proceeding with the sign-out process to prevent any potential loss of unsaved information" })
2088
- ] }),
2089
- /* @__PURE__ */ u.jsxs(zs, { children: [
2090
- /* @__PURE__ */ u.jsx(Gs, { disabled: e.isPending, children: "Cancel" }),
2091
- /* @__PURE__ */ u.jsxs(
2092
- "button",
2093
- {
2094
- disabled: e.isPending,
2095
- onClick: () => e.mutate(),
2096
- className: "rounded-md text-white w-28 text-center justify-center bg-red-600 hover:bg-red-700 flex items-center gap-x-2",
2097
- children: [
2098
- e.isPending && /* @__PURE__ */ u.jsx(Ts, { className: "animate-spin w-5 h-5" }),
2099
- "Sign Out"
2100
- ]
2101
- }
2102
- )
2103
- ] })
2104
- ] })
2105
- ] });
2106
- }, zr = () => /* @__PURE__ */ u.jsx(Hr, { children: /* @__PURE__ */ u.jsx("button", { className: "border-gray-200 rounded-md p-2 mb-2 border", children: /* @__PURE__ */ u.jsx(Is, { className: "w-4 h-4 text-red-500 cursor-pointer hover:text-red-300 duration-300" }) }) }), Gr = zr, Vr = Rt(() => import("./PagesPanel-6JuwBLFQ.js")), Wr = Rt(() => import("./ProjectPanel-cu2QSDW9.js")), Jr = Rt(() => import("./CurrentPage-6Jp4xAWK.js")), Yr = () => /* @__PURE__ */ u.jsx("h2", { children: "Your Logo" }), Xr = () => {
2107
- const { mutate: t } = qr();
2108
- return Ps("editable", !0) ? /* @__PURE__ */ u.jsx(ts, { onClick: t, className: "bg-blue-600 text-white", children: "Publish" }) : null;
2109
- }, Zr = (t) => {
2110
- const { data: e, isLoading: s } = fs(), { data: r, isLoading: i } = ys(), { data: a } = ps(), { mutate: c } = Rr(), { mutate: d } = kr(), [p] = Oe(), b = Nr(), h = Dr(), O = Qr(), k = U(), m = yt(
2111
- async (w) => await b.mutateAsync(w),
2112
- [b]
2113
- ), v = yt(async () => await h.mutateAsync(), [h]), j = yt(
2114
- async (w) => await O.mutateAsync(w),
2115
- [O]
2116
- ), f = async (w = 20, x = 0) => {
2117
- const F = `limit=${w}&offset=${x}`;
2118
- return await fetch(`${k}/assets?${F}`).then((D) => D.json());
2119
- }, { logo: g = Yr } = t;
2120
- return s || !e ? /* @__PURE__ */ u.jsx(At, {}) : i || !r ? /* @__PURE__ */ u.jsx(At, {}) : /* @__PURE__ */ u.jsx("div", { className: "bg-background text-foreground", children: /* @__PURE__ */ u.jsx(
2121
- Os,
2122
- {
2123
- editable: a != null && a.lockedBy ? a == null ? void 0 : a.lockedBy.self : !0,
2124
- nonEditableComponent: Kr,
2125
- blocks: (a == null ? void 0 : a.blocks) || [],
2126
- brandingOptions: e.brandingOptions,
2127
- darkMode: t.darkMode || !1,
2128
- dataProviders: (a == null ? void 0 : a.providers) || [],
2129
- onSavePage: async ({ blocks: w, providers: x }) => (await d({ blocks: w, providers: x, uuid: p }), !0),
2130
- onSaveBrandingOptions: async (w) => (await c({ brandingOptions: w }), !0),
2131
- topBarComponents: {
2132
- left: [g],
2133
- center: [Jr],
2134
- right: [Xr]
2135
- },
2136
- sideBarComponents: {
2137
- top: [
2138
- { icon: js, name: "pages", panel: Vr },
2139
- { icon: Ss, name: "settings", panel: Wr }
2140
- ],
2141
- bottom: [Gr]
2142
- },
2143
- uploadMediaCallback: m,
2144
- fetchMediaCallback: f,
2145
- getUILibraryBlocks: v,
2146
- getExternalPredefinedBlock: j,
2147
- getPages: () => r,
2148
- unsplashAccessKey: t.unsplashAccessKey || ""
2149
- }
2150
- ) });
2151
- }, en = ({ logo: t }) => {
2152
- const [e, s] = pt(!1), [r, i] = pt(""), [a, c] = pt(""), { mutate: d, isPending: p } = _r(), b = (h) => {
2153
- h.preventDefault(), d({ email: r, password: a });
2154
- };
2155
- return /* @__PURE__ */ u.jsx("section", { className: "h-screen w-screen flex items-center justify-center bg-[radial-gradient(#AAA,transparent_0.5px)] duration-300 [background-size:6px_6px]", children: /* @__PURE__ */ u.jsx("div", { className: "overflow-hidden bg-white rounded-xl w-96 drop-shadow-2xl duration-300", children: /* @__PURE__ */ u.jsxs("div", { className: "p-12", children: [
2156
- /* @__PURE__ */ u.jsxs("div", { className: "max-w-2xl mx-auto text-center", children: [
2157
- /* @__PURE__ */ u.jsx(xs, { children: t ? de.createElement(t) : "" }),
2158
- /* @__PURE__ */ u.jsx("p", { className: "max-w-xl mx-auto text-base leading-relaxed text-gray-700 font-thin", children: "Enter your login credential to continue" })
2159
- ] }),
2160
- /* @__PURE__ */ u.jsx("div", { className: "mt-8", children: /* @__PURE__ */ u.jsxs("form", { method: "POST", onSubmit: b, className: "space-y-5", children: [
2161
- /* @__PURE__ */ u.jsx("div", { children: /* @__PURE__ */ u.jsxs("div", { className: "mt-2.5 relative text-gray-400 focus-within:text-gray-600", children: [
2162
- /* @__PURE__ */ u.jsx("div", { className: "absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none", children: /* @__PURE__ */ u.jsx(vs, {}) }),
2163
- /* @__PURE__ */ u.jsx(
2164
- "input",
2165
- {
2166
- value: r,
2167
- onChange: (h) => i(h.target.value),
2168
- type: "email",
2169
- id: "email",
2170
- placeholder: "Enter email",
2171
- className: "block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"
2172
- }
2173
- )
2174
- ] }) }),
2175
- /* @__PURE__ */ u.jsx("div", { children: /* @__PURE__ */ u.jsxs("div", { className: "mt-2.5 relative text-gray-400 focus-within:text-gray-600", children: [
2176
- /* @__PURE__ */ u.jsx("div", { className: "absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none", children: /* @__PURE__ */ u.jsx(
2177
- "svg",
2178
- {
2179
- className: "w-5 h-5",
2180
- xmlns: "http://www.w3.org/2000/svg",
2181
- fill: "none",
2182
- viewBox: "0 0 24 24",
2183
- stroke: "currentColor",
2184
- children: /* @__PURE__ */ u.jsx(
2185
- "path",
2186
- {
2187
- strokeLinecap: "round",
2188
- strokeLinejoin: "round",
2189
- strokeWidth: "2",
2190
- d: "M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4"
2191
- }
2192
- )
2193
- }
2194
- ) }),
2195
- /* @__PURE__ */ u.jsx(
2196
- "input",
2197
- {
2198
- value: a,
2199
- onChange: (h) => c(h.target.value),
2200
- type: e ? "text" : "password",
2201
- id: "pwd",
2202
- placeholder: "Enter password",
2203
- className: "block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"
2204
- }
2205
- ),
2206
- /* @__PURE__ */ u.jsx(
2207
- "button",
2208
- {
2209
- type: "button",
2210
- className: "absolute inset-y-0 right-4 flex items-center pl-3 cursor-pointer",
2211
- onClick: () => s(!e),
2212
- children: e ? /* @__PURE__ */ u.jsx(Es, {}) : /* @__PURE__ */ u.jsx(Fs, {})
2213
- }
2214
- )
2215
- ] }) }),
2216
- /* @__PURE__ */ u.jsx("div", { children: /* @__PURE__ */ u.jsx(
2217
- "button",
2218
- {
2219
- disabled: p || Ut(r) < 2 || Ut(a) < 2,
2220
- type: "submit",
2221
- className: "inline-flex disabled:bg-gray-400 items-center justify-center w-full px-4 py-4 text-base font-semibold text-white transition-all duration-200 bg-blue-600 border border-transparent rounded-md focus:outline-none hover:bg-blue-700 focus:bg-blue-700",
2222
- children: p ? "Signing in..." : "Login"
2223
- }
2224
- ) })
2225
- ] }) }),
2226
- /* @__PURE__ */ u.jsx("div", { className: "mt-4 flex items-center justify-end gap-x-2 text-sm", children: /* @__PURE__ */ u.jsx(
2227
- "a",
2228
- {
2229
- href: "https://apps.chaibuilder.com/settings",
2230
- target: "_blank",
2231
- className: "text-gray-500 hover:text-blue-400",
2232
- children: "Forget your password?"
2233
- }
2234
- ) })
2235
- ] }) }) });
2236
- }, tn = (t) => {
2237
- const { data: e, isLoading: s } = Br(), r = z();
2238
- return ws(() => {
2239
- r.setQueryData(["apiBaseUrl"], t.apiBaseUrl || "/api/chaibuilder");
2240
- }, [t.apiBaseUrl, r]), s ? /* @__PURE__ */ u.jsx(At, {}) : e != null && e.valid ? /* @__PURE__ */ u.jsx(Zr, { ...t }) : /* @__PURE__ */ u.jsx(en, { logo: t.logo });
2241
- }, sn = new ur(), bn = (t) => /* @__PURE__ */ u.jsxs(fr, { client: sn, children: [
2242
- /* @__PURE__ */ u.jsx(As, { richColors: !0 }),
2243
- /* @__PURE__ */ u.jsx(tn, { ...t })
2244
- ] });
2245
- export {
2246
- bn as C,
2247
- fs as a,
2248
- Rr as b,
2249
- Mr as c,
2250
- Oe as d,
2251
- mn as e,
2252
- z as f,
2253
- kr as g,
2254
- gn as h,
2255
- ys as u
2256
- };