@nivaro/react 0.3.4 → 0.3.5
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/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.js +288 -286
- package/dist/shared/context.js +96 -84
- package/dist/shared/lib/request-gate.js +190 -178
- package/package.json +1 -1
package/dist/shared/context.js
CHANGED
|
@@ -1,75 +1,87 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { QueryClientContext as
|
|
3
|
-
import { createContext as i, useContext as l, useState as
|
|
4
|
-
import { restoreMetadata as
|
|
5
|
-
import { isCoalesced as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return l(
|
|
9
|
-
}
|
|
10
|
-
const
|
|
11
|
-
function
|
|
12
|
-
const t =
|
|
13
|
-
return
|
|
1
|
+
import { jsxs as b, jsx as f } from "react/jsx-runtime";
|
|
2
|
+
import { QueryClientContext as v, QueryClient as w, QueryClientProvider as g, useQueryClient as C } from "@tanstack/react-query";
|
|
3
|
+
import { createContext as i, useContext as l, useState as m, useMemo as x, useCallback as h, useEffect as y } from "react";
|
|
4
|
+
import { restoreMetadata as I, startMetadataPersistence as N } from "./lib/metadata-persist.js";
|
|
5
|
+
import { isCoalesced as O, withGetCoalescing as P, releaseGatedReadsOnSharedFetch as S } from "./lib/request-gate.js";
|
|
6
|
+
const F = i(null);
|
|
7
|
+
function z() {
|
|
8
|
+
return l(F);
|
|
9
|
+
}
|
|
10
|
+
const p = i(null);
|
|
11
|
+
function $({ identity: e }) {
|
|
12
|
+
const t = C(), { userId: n, epoch: o, version: r } = e;
|
|
13
|
+
return y(() => {
|
|
14
14
|
let u = () => {
|
|
15
15
|
}, c = !1;
|
|
16
|
-
return
|
|
17
|
-
c || (u =
|
|
16
|
+
return I(t, { userId: n, epoch: o, version: r }).then(() => {
|
|
17
|
+
c || (u = N(t, { userId: n, epoch: o, version: r }));
|
|
18
18
|
}), () => {
|
|
19
19
|
c = !0, u();
|
|
20
20
|
};
|
|
21
21
|
}, [t, n, o, r]), null;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const d = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
function j() {
|
|
25
|
+
const e = C();
|
|
26
|
+
return y(() => {
|
|
27
|
+
const t = e.getQueryCache(), n = d.get(t);
|
|
28
|
+
return n ? n.count++ : d.set(t, { count: 1, stop: S(t) }), () => {
|
|
29
|
+
const o = d.get(t);
|
|
30
|
+
o && (o.count--, o.count <= 0 && (o.stop(), d.delete(t)));
|
|
31
|
+
};
|
|
32
|
+
}, [e]), null;
|
|
33
|
+
}
|
|
34
|
+
function L({
|
|
24
35
|
client: e,
|
|
25
36
|
children: t,
|
|
26
37
|
batchReads: n = !1,
|
|
27
38
|
persistMetadata: o = null
|
|
28
39
|
}) {
|
|
29
|
-
const r = l(
|
|
30
|
-
() => new
|
|
40
|
+
const r = l(v), [u] = m(
|
|
41
|
+
() => new w({
|
|
31
42
|
defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: !1 } }
|
|
32
43
|
})
|
|
33
|
-
), c =
|
|
34
|
-
() =>
|
|
44
|
+
), c = x(
|
|
45
|
+
() => O(e) ? e : P(e, { batchReads: n }),
|
|
35
46
|
[e, n]
|
|
36
|
-
), s = /* @__PURE__ */
|
|
37
|
-
o ? /* @__PURE__ */ f(
|
|
47
|
+
), s = /* @__PURE__ */ b(p.Provider, { value: { client: c }, children: [
|
|
48
|
+
o ? /* @__PURE__ */ f($, { identity: o }) : null,
|
|
49
|
+
typeof e.setOpen == "function" ? /* @__PURE__ */ f(j, {}) : null,
|
|
38
50
|
t
|
|
39
51
|
] });
|
|
40
|
-
return r ? s : /* @__PURE__ */ f(
|
|
52
|
+
return r ? s : /* @__PURE__ */ f(g, { client: u, children: s });
|
|
41
53
|
}
|
|
42
|
-
function
|
|
43
|
-
const e = l(
|
|
54
|
+
function K() {
|
|
55
|
+
const e = l(p);
|
|
44
56
|
if (!e) throw new Error("useNivaroClient must be used within <NivaroProvider>");
|
|
45
57
|
return e.client;
|
|
46
58
|
}
|
|
47
|
-
function
|
|
48
|
-
const e = l(
|
|
59
|
+
function D() {
|
|
60
|
+
const e = l(p);
|
|
49
61
|
return (e == null ? void 0 : e.client) ?? null;
|
|
50
62
|
}
|
|
51
|
-
function
|
|
52
|
-
const e =
|
|
63
|
+
function X() {
|
|
64
|
+
const e = D(), t = e == null ? void 0 : e.getToken();
|
|
53
65
|
return {
|
|
54
66
|
apiBase: e ? `${e.url}/api` : "/api",
|
|
55
67
|
authHeaders: t ? { Authorization: `Bearer ${t}` } : {},
|
|
56
68
|
credentials: t ? "omit" : "include"
|
|
57
69
|
};
|
|
58
70
|
}
|
|
59
|
-
const
|
|
71
|
+
const R = i({
|
|
60
72
|
isAdmin: !1,
|
|
61
73
|
userId: ""
|
|
62
74
|
});
|
|
63
|
-
function
|
|
64
|
-
return l(
|
|
75
|
+
function Y() {
|
|
76
|
+
return l(R);
|
|
65
77
|
}
|
|
66
|
-
function
|
|
78
|
+
function A(e) {
|
|
67
79
|
const t = JSON.stringify(e), n = new TextEncoder().encode(t);
|
|
68
80
|
let o = "";
|
|
69
81
|
for (const r of n) o += String.fromCharCode(r);
|
|
70
82
|
return encodeURIComponent(btoa(o));
|
|
71
83
|
}
|
|
72
|
-
function
|
|
84
|
+
function Z(e) {
|
|
73
85
|
if (!e) return null;
|
|
74
86
|
try {
|
|
75
87
|
const t = atob(e.replace(/ /g, "+")), n = Uint8Array.from(t, (r) => r.charCodeAt(0)), o = JSON.parse(new TextDecoder().decode(n));
|
|
@@ -83,52 +95,52 @@ function K(e) {
|
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
|
-
const
|
|
98
|
+
const Q = i({
|
|
87
99
|
navigate: (e) => {
|
|
88
100
|
window.location.href = e;
|
|
89
101
|
}
|
|
90
102
|
});
|
|
91
|
-
function
|
|
92
|
-
return l(
|
|
103
|
+
function U() {
|
|
104
|
+
return l(Q);
|
|
93
105
|
}
|
|
94
|
-
function
|
|
106
|
+
function k(e) {
|
|
95
107
|
const t = `/collections/${e.collection}/${e.itemId}`, n = [];
|
|
96
|
-
e.layoutSlug && n.push(`layout=${encodeURIComponent(e.layoutSlug)}`), e.prefill && Object.keys(e.prefill).length && n.push(`prefill=${
|
|
108
|
+
e.layoutSlug && n.push(`layout=${encodeURIComponent(e.layoutSlug)}`), e.prefill && Object.keys(e.prefill).length && n.push(`prefill=${A(e.prefill)}`);
|
|
97
109
|
for (const [o, r] of Object.entries(e.query ?? {}))
|
|
98
110
|
n.push(`${encodeURIComponent(o)}=${encodeURIComponent(r)}`);
|
|
99
111
|
return n.length ? `${t}?${n.join("&")}` : t;
|
|
100
112
|
}
|
|
101
|
-
function
|
|
102
|
-
const e =
|
|
113
|
+
function ee() {
|
|
114
|
+
const e = U(), t = (o) => (e.itemUrl ?? k)(o);
|
|
103
115
|
return { urlFor: t, open: (o) => {
|
|
104
116
|
var r;
|
|
105
117
|
((r = e.openItem) == null ? void 0 : r.call(e, o)) !== !0 && e.navigate(t(o));
|
|
106
118
|
} };
|
|
107
119
|
}
|
|
108
|
-
const U = i(null);
|
|
109
|
-
function Y() {
|
|
110
|
-
return l(U);
|
|
111
|
-
}
|
|
112
120
|
const E = i(null);
|
|
113
|
-
function
|
|
121
|
+
function te() {
|
|
114
122
|
return l(E);
|
|
115
123
|
}
|
|
116
|
-
const
|
|
117
|
-
function
|
|
118
|
-
return l(
|
|
124
|
+
const G = i(null);
|
|
125
|
+
function ne() {
|
|
126
|
+
return l(G);
|
|
119
127
|
}
|
|
120
|
-
const
|
|
121
|
-
function
|
|
122
|
-
return l(
|
|
128
|
+
const M = i({});
|
|
129
|
+
function oe() {
|
|
130
|
+
return l(M);
|
|
131
|
+
}
|
|
132
|
+
const q = i(null);
|
|
133
|
+
function re() {
|
|
134
|
+
return l(q);
|
|
123
135
|
}
|
|
124
136
|
const H = i(null);
|
|
125
|
-
function
|
|
126
|
-
const t = l(H), [n, o] =
|
|
137
|
+
function le(e) {
|
|
138
|
+
const t = l(H), [n, o] = m([]), r = t ? t.get(e) ?? null : n[n.length - 1] ?? null, u = h(
|
|
127
139
|
(s) => {
|
|
128
140
|
t ? t.push(e, s) : o((a) => [...a, s]);
|
|
129
141
|
},
|
|
130
142
|
[t, e]
|
|
131
|
-
), c =
|
|
143
|
+
), c = h(
|
|
132
144
|
(s = 1) => {
|
|
133
145
|
t ? t.back(s) : o((a) => a.slice(0, Math.max(0, a.length - s)));
|
|
134
146
|
},
|
|
@@ -136,39 +148,39 @@ function ne(e) {
|
|
|
136
148
|
);
|
|
137
149
|
return { value: r, push: u, back: c };
|
|
138
150
|
}
|
|
139
|
-
function
|
|
151
|
+
function ie(e) {
|
|
140
152
|
var u;
|
|
141
153
|
const t = (u = e._overrides) == null ? void 0 : u.drilldown, n = t && typeof t == "object" ? t : null, o = e.interface === "relation-path";
|
|
142
154
|
return (n == null ? void 0 : n.enabled) ?? o ? { enabled: !0, layout_id: (n == null ? void 0 : n.layout_id) ?? null, width: (n == null ? void 0 : n.width) ?? null } : null;
|
|
143
155
|
}
|
|
144
|
-
const
|
|
156
|
+
const ue = i(null), W = i(null), se = () => l(W);
|
|
145
157
|
export {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
q as DrilldownContext,
|
|
159
|
+
M as DrilldownViewsContext,
|
|
160
|
+
F as GridFlushContext,
|
|
161
|
+
R as ItemEditAuthContext,
|
|
162
|
+
Q as NavigationContext,
|
|
163
|
+
L as NivaroProvider,
|
|
152
164
|
H as OverlayHistoryContext,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
E as ParentDraftContext,
|
|
166
|
+
G as ReimportHandlerContext,
|
|
167
|
+
ue as RelationPathDataContext,
|
|
168
|
+
W as StaleFieldReportContext,
|
|
169
|
+
Z as decodePrefill,
|
|
170
|
+
k as defaultItemUrl,
|
|
171
|
+
A as encodePrefill,
|
|
172
|
+
ie as fieldDrilldownConfig,
|
|
173
|
+
X as useApiFetchConfig,
|
|
174
|
+
re as useDrilldown,
|
|
175
|
+
oe as useDrilldownViews,
|
|
176
|
+
z as useGridFlush,
|
|
177
|
+
Y as useItemEditAuth,
|
|
178
|
+
ee as useItemNavigation,
|
|
179
|
+
U as useNavigation,
|
|
180
|
+
K as useNivaroClient,
|
|
181
|
+
D as useOptionalNivaroClient,
|
|
182
|
+
le as useOverlayState,
|
|
183
|
+
te as useParentDraft,
|
|
184
|
+
ne as useReimportHandler,
|
|
185
|
+
se as useStaleFieldReporter
|
|
174
186
|
};
|