@nivaro/react 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,87 @@
1
- import { jsxs as h, jsx as f } from "react/jsx-runtime";
2
- import { QueryClientContext as m, QueryClient as y, QueryClientProvider as b, useQueryClient as v } from "@tanstack/react-query";
3
- import { createContext as i, useContext as l, useState as C, useMemo as w, useCallback as p, useEffect as x } from "react";
4
- import { restoreMetadata as g, startMetadataPersistence as I } from "./lib/metadata-persist.js";
5
- import { isCoalesced as N, withGetCoalescing as P } from "./lib/request-gate.js";
6
- const O = i(null);
7
- function B() {
8
- return l(O);
9
- }
10
- const d = i(null);
11
- function S({ identity: e }) {
12
- const t = v(), { userId: n, epoch: o, version: r } = e;
13
- return x(() => {
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 g(t, { userId: n, epoch: o, version: r }).then(() => {
17
- c || (u = I(t, { userId: n, epoch: o, version: r }));
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
- function V({
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(m), [u] = C(
30
- () => new y({
40
+ const r = l(v), [u] = m(
41
+ () => new w({
31
42
  defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: !1 } }
32
43
  })
33
- ), c = w(
34
- () => N(e) ? e : P(e, { batchReads: n }),
44
+ ), c = x(
45
+ () => O(e) ? e : P(e, { batchReads: n }),
35
46
  [e, n]
36
- ), s = /* @__PURE__ */ h(d.Provider, { value: { client: c }, children: [
37
- o ? /* @__PURE__ */ f(S, { identity: o }) : null,
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(b, { client: u, children: s });
52
+ return r ? s : /* @__PURE__ */ f(g, { client: u, children: s });
41
53
  }
42
- function z() {
43
- const e = l(d);
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(d);
59
+ function D() {
60
+ const e = l(p);
49
61
  return (e == null ? void 0 : e.client) ?? null;
50
62
  }
51
- function L() {
52
- const e = $(), t = e == null ? void 0 : e.getToken();
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 j = i({
71
+ const R = i({
60
72
  isAdmin: !1,
61
73
  userId: ""
62
74
  });
63
- function W() {
64
- return l(j);
75
+ function Y() {
76
+ return l(R);
65
77
  }
66
- function D(e) {
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 K(e) {
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 F = i({
98
+ const Q = i({
87
99
  navigate: (e) => {
88
100
  window.location.href = e;
89
101
  }
90
102
  });
91
- function R() {
92
- return l(F);
103
+ function U() {
104
+ return l(Q);
93
105
  }
94
- function A(e) {
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=${D(e.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 X() {
102
- const e = R(), t = (o) => (e.itemUrl ?? A)(o);
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 Z() {
121
+ function te() {
114
122
  return l(E);
115
123
  }
116
- const Q = i({});
117
- function ee() {
118
- return l(Q);
124
+ const G = i(null);
125
+ function ne() {
126
+ return l(G);
119
127
  }
120
- const k = i(null);
121
- function te() {
122
- return l(k);
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 ne(e) {
126
- const t = l(H), [n, o] = C([]), r = t ? t.get(e) ?? null : n[n.length - 1] ?? null, u = p(
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 = p(
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 oe(e) {
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 re = i(null), M = i(null), le = () => l(M);
156
+ const ue = i(null), W = i(null), se = () => l(W);
145
157
  export {
146
- k as DrilldownContext,
147
- Q as DrilldownViewsContext,
148
- O as GridFlushContext,
149
- j as ItemEditAuthContext,
150
- F as NavigationContext,
151
- V as NivaroProvider,
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
- U as ParentDraftContext,
154
- E as ReimportHandlerContext,
155
- re as RelationPathDataContext,
156
- M as StaleFieldReportContext,
157
- K as decodePrefill,
158
- A as defaultItemUrl,
159
- D as encodePrefill,
160
- oe as fieldDrilldownConfig,
161
- L as useApiFetchConfig,
162
- te as useDrilldown,
163
- ee as useDrilldownViews,
164
- B as useGridFlush,
165
- W as useItemEditAuth,
166
- X as useItemNavigation,
167
- R as useNavigation,
168
- z as useNivaroClient,
169
- $ as useOptionalNivaroClient,
170
- ne as useOverlayState,
171
- Y as useParentDraft,
172
- Z as useReimportHandler,
173
- le as useStaleFieldReporter
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
  };