houdini-react 2.0.0-next.3 → 2.0.0-next.31

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 (171) hide show
  1. package/bin/houdini-react +173 -0
  2. package/package.json +63 -39
  3. package/postInstall.js +360 -0
  4. package/runtime/client.ts +5 -0
  5. package/runtime/clientPlugin.ts +17 -0
  6. package/runtime/componentFields.ts +79 -0
  7. package/runtime/hooks/index.ts +9 -0
  8. package/runtime/hooks/useDeepCompareEffect.ts +91 -0
  9. package/runtime/hooks/useDocumentHandle.ts +232 -0
  10. package/runtime/hooks/useDocumentStore.ts +76 -0
  11. package/runtime/hooks/useDocumentSubscription.ts +62 -0
  12. package/runtime/hooks/useFragment.ts +93 -0
  13. package/runtime/hooks/useFragmentHandle.ts +46 -0
  14. package/runtime/hooks/useIsMounted.ts +14 -0
  15. package/runtime/hooks/useMutation.ts +70 -0
  16. package/runtime/hooks/useQuery.ts +12 -0
  17. package/runtime/hooks/useQueryHandle.ts +186 -0
  18. package/runtime/hooks/useSubscription.ts +12 -0
  19. package/runtime/hooks/useSubscriptionHandle.ts +33 -0
  20. package/runtime/hydration.tsx +155 -0
  21. package/runtime/index.tsx +49 -0
  22. package/runtime/manifest.ts +6 -0
  23. package/runtime/package.json +1 -0
  24. package/runtime/routing/Router.tsx +885 -0
  25. package/runtime/routing/cache.ts +54 -0
  26. package/runtime/routing/index.ts +2 -0
  27. package/server/index.d.ts +1 -0
  28. package/server/index.js +4 -0
  29. package/server/react-streaming.d.js +0 -0
  30. package/vite/index.d.ts +3 -0
  31. package/vite/index.js +286 -0
  32. package/vite/transform.d.ts +11 -0
  33. package/vite/transform.js +90 -0
  34. package/README.md +0 -36
  35. package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
  36. package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
  37. package/build/plugin/codegen/entries/index.d.ts +0 -16
  38. package/build/plugin/codegen/entries/pages.d.ts +0 -2
  39. package/build/plugin/codegen/index.d.ts +0 -17
  40. package/build/plugin/codegen/manifest.d.ts +0 -5
  41. package/build/plugin/codegen/render.d.ts +0 -7
  42. package/build/plugin/codegen/router.d.ts +0 -7
  43. package/build/plugin/codegen/typeRoot.d.ts +0 -5
  44. package/build/plugin/config.d.ts +0 -4
  45. package/build/plugin/dedent.d.ts +0 -1
  46. package/build/plugin/extract.d.ts +0 -6
  47. package/build/plugin/index.d.ts +0 -5
  48. package/build/plugin/state.d.ts +0 -3
  49. package/build/plugin/transform.d.ts +0 -6
  50. package/build/plugin/vite.d.ts +0 -27
  51. package/build/plugin-cjs/index.js +0 -90119
  52. package/build/plugin-cjs/package.json +0 -1
  53. package/build/plugin-esm/index.js +0 -90115
  54. package/build/runtime/client.d.ts +0 -3
  55. package/build/runtime/clientPlugin.d.ts +0 -3
  56. package/build/runtime/componentFields.d.ts +0 -9
  57. package/build/runtime/hooks/index.d.ts +0 -8
  58. package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
  59. package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
  60. package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
  61. package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
  62. package/build/runtime/hooks/useFragment.d.ts +0 -16
  63. package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
  64. package/build/runtime/hooks/useIsMounted.d.ts +0 -3
  65. package/build/runtime/hooks/useMutation.d.ts +0 -14
  66. package/build/runtime/hooks/useQuery.d.ts +0 -5
  67. package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
  68. package/build/runtime/hooks/useSubscription.d.ts +0 -4
  69. package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
  70. package/build/runtime/index.d.ts +0 -14
  71. package/build/runtime/manifest.d.ts +0 -3
  72. package/build/runtime/routing/Router.d.ts +0 -62
  73. package/build/runtime/routing/cache.d.ts +0 -7
  74. package/build/runtime/routing/hooks.d.ts +0 -40
  75. package/build/runtime/routing/index.d.ts +0 -3
  76. package/build/runtime-cjs/client.d.ts +0 -3
  77. package/build/runtime-cjs/client.js +0 -25
  78. package/build/runtime-cjs/clientPlugin.d.ts +0 -3
  79. package/build/runtime-cjs/clientPlugin.js +0 -37
  80. package/build/runtime-cjs/componentFields.d.ts +0 -9
  81. package/build/runtime-cjs/componentFields.js +0 -83
  82. package/build/runtime-cjs/hooks/index.d.ts +0 -8
  83. package/build/runtime-cjs/hooks/index.js +0 -45
  84. package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
  85. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -76
  86. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
  87. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -177
  88. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
  89. package/build/runtime-cjs/hooks/useDocumentStore.js +0 -76
  90. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
  91. package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -76
  92. package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
  93. package/build/runtime-cjs/hooks/useFragment.js +0 -102
  94. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
  95. package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
  96. package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
  97. package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
  98. package/build/runtime-cjs/hooks/useMutation.d.ts +0 -14
  99. package/build/runtime-cjs/hooks/useMutation.js +0 -67
  100. package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
  101. package/build/runtime-cjs/hooks/useQuery.js +0 -32
  102. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
  103. package/build/runtime-cjs/hooks/useQueryHandle.js +0 -131
  104. package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
  105. package/build/runtime-cjs/hooks/useSubscription.js +0 -32
  106. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
  107. package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
  108. package/build/runtime-cjs/index.d.ts +0 -14
  109. package/build/runtime-cjs/index.js +0 -88
  110. package/build/runtime-cjs/manifest.d.ts +0 -3
  111. package/build/runtime-cjs/manifest.js +0 -25
  112. package/build/runtime-cjs/package.json +0 -1
  113. package/build/runtime-cjs/routing/Router.d.ts +0 -62
  114. package/build/runtime-cjs/routing/Router.js +0 -540
  115. package/build/runtime-cjs/routing/cache.d.ts +0 -7
  116. package/build/runtime-cjs/routing/cache.js +0 -61
  117. package/build/runtime-cjs/routing/hooks.d.ts +0 -40
  118. package/build/runtime-cjs/routing/hooks.js +0 -93
  119. package/build/runtime-cjs/routing/index.d.ts +0 -3
  120. package/build/runtime-cjs/routing/index.js +0 -33
  121. package/build/runtime-esm/client.d.ts +0 -3
  122. package/build/runtime-esm/client.js +0 -5
  123. package/build/runtime-esm/clientPlugin.d.ts +0 -3
  124. package/build/runtime-esm/clientPlugin.js +0 -17
  125. package/build/runtime-esm/componentFields.d.ts +0 -9
  126. package/build/runtime-esm/componentFields.js +0 -59
  127. package/build/runtime-esm/hooks/index.d.ts +0 -8
  128. package/build/runtime-esm/hooks/index.js +0 -15
  129. package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
  130. package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
  131. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
  132. package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
  133. package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
  134. package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
  135. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
  136. package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -42
  137. package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
  138. package/build/runtime-esm/hooks/useFragment.js +0 -67
  139. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
  140. package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
  141. package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
  142. package/build/runtime-esm/hooks/useIsMounted.js +0 -14
  143. package/build/runtime-esm/hooks/useMutation.d.ts +0 -14
  144. package/build/runtime-esm/hooks/useMutation.js +0 -42
  145. package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
  146. package/build/runtime-esm/hooks/useQuery.js +0 -8
  147. package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
  148. package/build/runtime-esm/hooks/useQueryHandle.js +0 -97
  149. package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
  150. package/build/runtime-esm/hooks/useSubscription.js +0 -8
  151. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
  152. package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
  153. package/build/runtime-esm/index.d.ts +0 -14
  154. package/build/runtime-esm/index.js +0 -48
  155. package/build/runtime-esm/manifest.d.ts +0 -3
  156. package/build/runtime-esm/manifest.js +0 -5
  157. package/build/runtime-esm/routing/Router.d.ts +0 -62
  158. package/build/runtime-esm/routing/Router.js +0 -499
  159. package/build/runtime-esm/routing/cache.d.ts +0 -7
  160. package/build/runtime-esm/routing/cache.js +0 -36
  161. package/build/runtime-esm/routing/hooks.d.ts +0 -40
  162. package/build/runtime-esm/routing/hooks.js +0 -53
  163. package/build/runtime-esm/routing/index.d.ts +0 -3
  164. package/build/runtime-esm/routing/index.js +0 -6
  165. package/build/server/index.d.ts +0 -1
  166. package/build/server-cjs/index.js +0 -28
  167. package/build/server-cjs/package.json +0 -1
  168. package/build/server-esm/index.js +0 -4
  169. package/build/server-esm/package.json +0 -1
  170. /package/{build/plugin-esm → server}/package.json +0 -0
  171. /package/{build/runtime-esm → vite}/package.json +0 -0
@@ -1,540 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var Router_exports = {};
30
- __export(Router_exports, {
31
- PageContextProvider: () => PageContextProvider,
32
- Router: () => Router,
33
- RouterContextProvider: () => RouterContextProvider,
34
- router_cache: () => router_cache,
35
- updateLocalSession: () => updateLocalSession,
36
- useCurrentVariables: () => useCurrentVariables,
37
- useQueryResult: () => useQueryResult,
38
- useRoute: () => useRoute
39
- });
40
- module.exports = __toCommonJS(Router_exports);
41
- var import_jsx_runtime = require("react/jsx-runtime");
42
- var import_config = __toESM(require("$houdini/runtime/imports/config"));
43
- var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
44
- var import_scalars = require("$houdini/runtime/lib/scalars");
45
- var import_match = require("$houdini/runtime/router/match");
46
- var import_react = __toESM(require("react"));
47
- var import_react2 = require("react");
48
- var import_cache = require("./cache");
49
- var import_useDocumentHandle = require("../hooks/useDocumentHandle");
50
- var import_useDocumentStore = require("../hooks/useDocumentStore");
51
- var import_hooks = require("./hooks");
52
- const PreloadWhich = {
53
- component: "component",
54
- data: "data",
55
- page: "page"
56
- };
57
- function Router({
58
- manifest,
59
- initialURL,
60
- assetPrefix,
61
- injectToStream
62
- }) {
63
- const [currentURL, setCurrentURL] = import_react.default.useState(() => {
64
- return initialURL || window.location.pathname;
65
- });
66
- const [page, variables] = (0, import_match.find_match)(import_config.default, manifest, currentURL);
67
- if (!page) {
68
- throw new Error("404");
69
- }
70
- const { loadData, loadComponent } = usePageData({
71
- page,
72
- variables,
73
- assetPrefix,
74
- injectToStream
75
- });
76
- const { component_cache, data_cache } = (0, import_hooks.useRouterContext)();
77
- const PageComponent = component_cache.get(page.id);
78
- import_react.default.useEffect(() => {
79
- if (globalThis.window && window.location.pathname !== currentURL) {
80
- window.history.pushState({}, "", currentURL);
81
- }
82
- }, [currentURL]);
83
- import_react.default.useEffect(() => {
84
- if (!globalThis.window) {
85
- return;
86
- }
87
- const onChange = (evt) => {
88
- setCurrentURL(window.location.pathname);
89
- };
90
- window.addEventListener("popstate", onChange);
91
- return () => {
92
- window.removeEventListener("popstate", onChange);
93
- };
94
- }, []);
95
- const goto = (url) => {
96
- data_cache.clear();
97
- setCurrentURL(url);
98
- };
99
- useLinkBehavior({
100
- goto,
101
- preload(url, which) {
102
- const [page2, variables2] = (0, import_match.find_match)(import_config.default, manifest, url);
103
- if (!page2) {
104
- return;
105
- }
106
- if (["page", "component"].includes(which)) {
107
- loadComponent(page2);
108
- }
109
- if (["page", "data"].includes(which)) {
110
- loadData(page2, variables2);
111
- }
112
- }
113
- });
114
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
115
- import_hooks.LocationContext.Provider,
116
- {
117
- value: {
118
- pathname: currentURL,
119
- goto,
120
- params: variables ?? {}
121
- },
122
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id)
123
- }
124
- ) });
125
- }
126
- function usePageData({
127
- page,
128
- variables,
129
- assetPrefix,
130
- injectToStream
131
- }) {
132
- const {
133
- client,
134
- cache,
135
- data_cache,
136
- component_cache,
137
- artifact_cache,
138
- ssr_signals,
139
- last_variables
140
- } = (0, import_hooks.useRouterContext)();
141
- const [session] = (0, import_hooks.useSession)();
142
- function load_query({
143
- id,
144
- artifact,
145
- variables: variables2
146
- }) {
147
- for (const artifact2 of Object.keys(page.documents)) {
148
- last_variables.set(artifact2, variables2);
149
- }
150
- if (ssr_signals.has(id)) {
151
- return ssr_signals.get(id);
152
- }
153
- const observer = data_cache.has(artifact.name) ? data_cache.get(artifact.name) : client.observe({ artifact, cache });
154
- let resolve = () => {
155
- };
156
- let reject = () => {
157
- };
158
- const promise = new Promise((res, rej) => {
159
- resolve = res;
160
- reject = rej;
161
- observer.send({
162
- variables: variables2,
163
- session
164
- }).then(async () => {
165
- data_cache.set(id, observer);
166
- if (observer.state.errors && observer.state.errors.length > 0) {
167
- reject(observer.state.errors.map((e) => e.message).join("\n"));
168
- return;
169
- }
170
- injectToStream?.(`
171
- <script>
172
- {
173
- window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
174
-
175
- const artifactName = "${artifact.name}"
176
- const value = ${JSON.stringify(
177
- (0, import_scalars.marshalSelection)({
178
- selection: observer.artifact.selection,
179
- data: observer.state.data
180
- })
181
- )}
182
-
183
- // if the data is pending, we need to resolve it
184
- if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
185
- // before we resolve the pending signals,
186
- // fill the data cache with values we got on the server
187
- const new_store = window.__houdini__client__.observe({
188
- artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
189
- cache: window.__houdini__cache__,
190
- })
191
-
192
- // we're pushing this store onto the client, it should be initialized
193
- window.__houdini__nav_caches__.data_cache.get(artifactName).send({
194
- setup: true,
195
- variables: ${JSON.stringify(
196
- (0, import_scalars.marshalInputs)({
197
- artifact: observer.artifact,
198
- input: variables2,
199
- config: import_config.default
200
- })
201
- )}
202
- }).then(() => {
203
- window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
204
- })
205
-
206
- }
207
-
208
-
209
- // if there are no data caches available we need to populate the pending one instead
210
- if (!window.__houdini__nav_caches__) {
211
- if (!window.__houdini__pending_data__) {
212
- window.__houdini__pending_data__ = {}
213
- }
214
-
215
- if (!window.__houdini__pending_variables__) {
216
- window.__houdini__pending_variables__ = {}
217
- }
218
-
219
- if (!window.__houdini__pending_artifacts__) {
220
- window.__houdini__pending_artifacts__ = {}
221
- }
222
- }
223
-
224
- window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
225
- window.__houdini__pending_data__[artifactName] = value
226
- window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
227
-
228
- // if this payload finishes off an ssr request, we need to resolve the signal
229
- if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
230
-
231
- // if the data showed up on the client before
232
- if (window.__houdini__nav_caches__.data_cache.has(artifactName)) {
233
- // we're pushing this store onto the client, it should be initialized
234
- window.__houdini__nav_caches__.data_cache.get(artifactName).send({
235
- setup: true,
236
- variables: ${JSON.stringify(
237
- (0, import_scalars.marshalInputs)({
238
- artifact: observer.artifact,
239
- input: variables2,
240
- config: import_config.default
241
- })
242
- )}
243
- })
244
- }
245
-
246
-
247
- // trigger the signal
248
- window.__houdini__nav_caches__.ssr_signals.get(artifactName).resolve()
249
- window.__houdini__nav_caches__.ssr_signals.delete(artifactName)
250
- }
251
- }
252
- </script>
253
- `);
254
- resolve();
255
- }).catch(reject);
256
- });
257
- const resolvable = { ...promise, resolve, reject };
258
- if (!globalThis.window) {
259
- ssr_signals.set(id, resolvable);
260
- }
261
- return resolvable;
262
- }
263
- function loadData(targetPage, variables2) {
264
- if (!targetPage) {
265
- return;
266
- }
267
- for (const [artifact, { variables: pageVariables }] of Object.entries(
268
- targetPage.documents
269
- )) {
270
- if (!last_variables.has(artifact)) {
271
- continue;
272
- }
273
- let last = {};
274
- let usedVariables = {};
275
- for (const variable of Object.keys(pageVariables)) {
276
- last[variable] = last_variables.get(artifact)[variable];
277
- usedVariables[variable] = (variables2 ?? {})[variable];
278
- }
279
- if (Object.keys(usedVariables ?? {}).length > 0 && !(0, import_deepEquals.deepEquals)(last, usedVariables)) {
280
- data_cache.delete(artifact);
281
- }
282
- }
283
- const missing_artifacts = [];
284
- const found_artifacts = {};
285
- for (const key of Object.keys(targetPage.documents)) {
286
- if (artifact_cache.has(key)) {
287
- found_artifacts[key] = artifact_cache.get(key);
288
- } else {
289
- missing_artifacts.push(key);
290
- }
291
- }
292
- for (const artifact_id of missing_artifacts) {
293
- targetPage.documents[artifact_id].artifact().then((mod) => {
294
- const artifact = mod.default;
295
- artifact_cache.set(artifact_id, artifact);
296
- injectToStream?.(`
297
- <script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""></script>
298
- `);
299
- load_query({ id: artifact.name, artifact, variables: variables2 });
300
- }).catch((err) => {
301
- console.log(err);
302
- });
303
- }
304
- for (const artifact of Object.values(found_artifacts)) {
305
- if (!data_cache.has(artifact.name)) {
306
- load_query({ id: artifact.name, artifact, variables: variables2 });
307
- }
308
- }
309
- }
310
- async function loadComponent(targetPage) {
311
- if (component_cache.has(targetPage.id)) {
312
- return;
313
- }
314
- const mod = await targetPage.component();
315
- component_cache.set(targetPage.id, mod.default);
316
- }
317
- loadData(page, variables);
318
- if (!component_cache.has(page.id)) {
319
- throw loadComponent(page);
320
- }
321
- return {
322
- loadData,
323
- loadComponent
324
- };
325
- }
326
- function RouterContextProvider({
327
- children,
328
- client,
329
- cache,
330
- artifact_cache,
331
- component_cache,
332
- data_cache,
333
- ssr_signals,
334
- last_variables,
335
- session: ssrSession = {}
336
- }) {
337
- const [session, setSession] = import_react.default.useState(ssrSession);
338
- const handleNewSession = import_react.default.useCallback((event) => {
339
- setSession(event.detail);
340
- }, []);
341
- import_react.default.useEffect(() => {
342
- window.addEventListener("_houdini_session_", handleNewSession);
343
- return () => {
344
- window.removeEventListener("_houdini_session_", handleNewSession);
345
- };
346
- }, []);
347
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
348
- import_hooks.Context.Provider,
349
- {
350
- value: {
351
- client,
352
- cache,
353
- artifact_cache,
354
- component_cache,
355
- data_cache,
356
- ssr_signals,
357
- last_variables,
358
- session,
359
- setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
360
- },
361
- children
362
- }
363
- );
364
- }
365
- function updateLocalSession(session) {
366
- window.dispatchEvent(
367
- new CustomEvent("_houdini_session_", {
368
- bubbles: true,
369
- detail: session
370
- })
371
- );
372
- }
373
- function useCurrentVariables() {
374
- return import_react.default.useContext(VariableContext);
375
- }
376
- const VariableContext = import_react.default.createContext(null);
377
- function useQueryResult(name) {
378
- const { data_cache, artifact_cache } = (0, import_hooks.useRouterContext)();
379
- const store_ref = data_cache.get(name);
380
- const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
381
- artifact: store_ref.artifact,
382
- observer: store_ref
383
- });
384
- const { data, errors } = storeValue;
385
- if (errors && errors.length > 0) {
386
- throw new Error(JSON.stringify(errors));
387
- }
388
- const handle = (0, import_useDocumentHandle.useDocumentHandle)({
389
- artifact: artifact_cache.get(name),
390
- observer,
391
- storeValue
392
- });
393
- return [data, handle];
394
- }
395
- function useLinkBehavior({
396
- goto,
397
- preload
398
- }) {
399
- useLinkNavigation({ goto });
400
- if (!globalThis.navigator?.connection?.saveData) {
401
- usePreload({ preload });
402
- }
403
- }
404
- function useLinkNavigation({ goto }) {
405
- const [pending, startTransition] = import_react.default.useTransition();
406
- import_react.default.useEffect(() => {
407
- const onClick = (e) => {
408
- if (!e.target) {
409
- return;
410
- }
411
- const link = e.target?.closest("a");
412
- if (!(link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && // left clicks only
413
- !e.metaKey && // open in new tab (mac)
414
- !e.ctrlKey && // open in new tab (windows)
415
- !e.altKey && // download
416
- !e.shiftKey && !e.defaultPrevented)) {
417
- return;
418
- }
419
- const target = link.attributes.getNamedItem("href")?.value;
420
- if (!target || !target.startsWith("/")) {
421
- return;
422
- }
423
- e.preventDefault();
424
- e.stopPropagation();
425
- startTransition(() => {
426
- goto(target);
427
- });
428
- };
429
- window.addEventListener("click", onClick);
430
- return () => {
431
- window.removeEventListener("click", onClick);
432
- };
433
- }, []);
434
- }
435
- function usePreload({ preload }) {
436
- const timeoutRef = import_react.default.useRef(null);
437
- import_react.default.useEffect(() => {
438
- const mouseMove = (e) => {
439
- const target = e.target;
440
- if (!(target instanceof HTMLElement)) {
441
- return;
442
- }
443
- const anchor = target.closest("a");
444
- if (!anchor) {
445
- return;
446
- }
447
- let preloadWhichRaw = anchor.attributes.getNamedItem("data-houdini-preload")?.value;
448
- let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
449
- if (!PreloadWhich[preloadWhich]) {
450
- console.log(
451
- `invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
452
- );
453
- return;
454
- }
455
- if (timeoutRef.current) {
456
- clearTimeout(timeoutRef.current);
457
- }
458
- timeoutRef.current = setTimeout(() => {
459
- const url = anchor.attributes.getNamedItem("href")?.value;
460
- if (!url) {
461
- return;
462
- }
463
- preload(url, preloadWhich);
464
- }, 20);
465
- };
466
- document.addEventListener("mousemove", mouseMove);
467
- return () => {
468
- document.removeEventListener("mousemove", mouseMove);
469
- };
470
- }, []);
471
- }
472
- function router_cache({
473
- pending_queries = [],
474
- artifacts = {},
475
- components = {},
476
- initialData = {},
477
- initialVariables = {},
478
- initialArtifacts = {}
479
- } = {}) {
480
- const result = {
481
- artifact_cache: (0, import_cache.suspense_cache)(initialArtifacts),
482
- component_cache: (0, import_cache.suspense_cache)(),
483
- data_cache: (0, import_cache.suspense_cache)(initialData),
484
- ssr_signals: (0, import_cache.suspense_cache)(),
485
- last_variables: (0, import_cache.suspense_cache)()
486
- };
487
- for (const query of pending_queries) {
488
- result.ssr_signals.set(query, signal_promise());
489
- }
490
- for (const [name, artifact] of Object.entries(artifacts)) {
491
- result.artifact_cache.set(name, artifact);
492
- }
493
- for (const [name, component] of Object.entries(components)) {
494
- result.component_cache.set(name, component);
495
- }
496
- for (const [name, variables] of Object.entries(initialVariables)) {
497
- result.last_variables.set(name, variables);
498
- }
499
- return result;
500
- }
501
- const PageContext = import_react.default.createContext({ params: {} });
502
- function PageContextProvider({
503
- keys,
504
- children
505
- }) {
506
- const location2 = (0, import_hooks.useLocation)();
507
- const params = Object.fromEntries(
508
- Object.entries(location2.params).filter(([key]) => keys.includes(key))
509
- );
510
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageContext.Provider, { value: { params }, children });
511
- }
512
- function useRoute() {
513
- return (0, import_react2.useContext)(PageContext);
514
- }
515
- function signal_promise() {
516
- let resolve = () => {
517
- };
518
- let reject = () => {
519
- };
520
- const promise = new Promise((res, rej) => {
521
- resolve = res;
522
- reject = rej;
523
- });
524
- return {
525
- ...promise,
526
- resolve,
527
- reject
528
- };
529
- }
530
- // Annotate the CommonJS export names for ESM import in node:
531
- 0 && (module.exports = {
532
- PageContextProvider,
533
- Router,
534
- RouterContextProvider,
535
- router_cache,
536
- updateLocalSession,
537
- useCurrentVariables,
538
- useQueryResult,
539
- useRoute
540
- });
@@ -1,7 +0,0 @@
1
- import { LRUCache } from '$houdini/runtime/lib/lru';
2
- export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
3
- export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
4
- #private;
5
- get(key: string): _Data;
6
- set(key: string, value: _Data): void;
7
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cache_exports = {};
20
- __export(cache_exports, {
21
- SuspenseCache: () => SuspenseCache,
22
- suspense_cache: () => suspense_cache
23
- });
24
- module.exports = __toCommonJS(cache_exports);
25
- var import_lru = require("$houdini/runtime/lib/lru");
26
- function suspense_cache(initialData) {
27
- const cache = new SuspenseCache();
28
- for (const [key, value] of Object.entries(initialData ?? {})) {
29
- cache.set(key, value);
30
- }
31
- return cache;
32
- }
33
- class SuspenseCache extends import_lru.LRUCache {
34
- // if get is called before set, we need to invoke a callback.
35
- // that means we need a place to put our callbacks
36
- #callbacks = /* @__PURE__ */ new Map();
37
- get(key) {
38
- if (super.has(key)) {
39
- return super.get(key);
40
- }
41
- throw new Promise((resolve, reject) => {
42
- this.#subscribe(key, resolve, reject);
43
- });
44
- }
45
- // TODO: reject?
46
- set(key, value) {
47
- super.set(key, value);
48
- if (this.#callbacks.has(key)) {
49
- this.#callbacks.get(key)?.forEach(({ resolve }) => resolve());
50
- this.#callbacks.delete(key);
51
- }
52
- }
53
- #subscribe(key, resolve, reject) {
54
- this.#callbacks.set(key, [...this.#callbacks.get(key) || [], { resolve, reject }]);
55
- }
56
- }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- SuspenseCache,
60
- suspense_cache
61
- });
@@ -1,40 +0,0 @@
1
- import type { Cache } from '$houdini/runtime/cache/cache';
2
- import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
3
- import type { LRUCache } from '$houdini/runtime/lib/lru';
4
- import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
5
- import { default as React } from 'react';
6
- import type { SuspenseCache } from './cache';
7
- export type PageComponent = React.ComponentType<{
8
- url: string;
9
- }>;
10
- export type PendingCache = SuspenseCache<Promise<void> & {
11
- resolve: () => void;
12
- reject: (message: string) => void;
13
- }>;
14
- type RouterContext = {
15
- client: HoudiniClient;
16
- cache: Cache;
17
- artifact_cache: SuspenseCache<QueryArtifact>;
18
- component_cache: SuspenseCache<PageComponent>;
19
- data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
20
- ssr_signals: PendingCache;
21
- last_variables: LRUCache<GraphQLVariables>;
22
- session: App.Session;
23
- setSession: (newSession: Partial<App.Session>) => void;
24
- };
25
- export declare const Context: React.Context<RouterContext | null>;
26
- export declare const LocationContext: React.Context<{
27
- pathname: string;
28
- params: Record<string, any>;
29
- goto: (url: string) => void;
30
- }>;
31
- export declare const useLocation: () => {
32
- pathname: string;
33
- params: Record<string, any>;
34
- goto: (url: string) => void;
35
- };
36
- export declare const useRouterContext: () => RouterContext;
37
- export declare function useClient(): HoudiniClient;
38
- export declare function useCache(): Cache;
39
- export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
40
- export {};