houdini-react 1.3.14 → 2.0.0-go.1

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