@torpor/build 0.4.9 → 0.4.10

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 (103) hide show
  1. package/package.json +7 -3
  2. package/CHANGELOG.md +0 -473
  3. package/scripts/postbuild.ts +0 -12
  4. package/src/bin/index.ts +0 -11
  5. package/src/index.ts +0 -30
  6. package/src/nav/formSubmit.ts +0 -56
  7. package/src/nav/load.ts +0 -9
  8. package/src/nav/loadData.ts +0 -134
  9. package/src/nav/navigate.ts +0 -164
  10. package/src/nav/reload.ts +0 -9
  11. package/src/nav.ts +0 -4
  12. package/src/response/badRequest.ts +0 -19
  13. package/src/response/created.ts +0 -20
  14. package/src/response/forbidden.ts +0 -21
  15. package/src/response/found.ts +0 -30
  16. package/src/response/methodNotAllowed.ts +0 -18
  17. package/src/response/movedPermanently.ts +0 -25
  18. package/src/response/notFound.ts +0 -24
  19. package/src/response/notModified.ts +0 -34
  20. package/src/response/ok.ts +0 -29
  21. package/src/response/permanentRedirect.ts +0 -30
  22. package/src/response/response.ts +0 -22
  23. package/src/response/seeOther.ts +0 -19
  24. package/src/response/serverError.ts +0 -24
  25. package/src/response/temporaryRedirect.ts +0 -31
  26. package/src/response/transfer.ts +0 -14
  27. package/src/response/unauthorized.ts +0 -21
  28. package/src/response/unprocessable.ts +0 -18
  29. package/src/response.ts +0 -37
  30. package/src/run/prepareTemplate.ts +0 -39
  31. package/src/run/run.ts +0 -62
  32. package/src/run/runBuild.ts +0 -77
  33. package/src/run/runDev.ts +0 -89
  34. package/src/run/runPreview.ts +0 -93
  35. package/src/run.ts +0 -6
  36. package/src/server/CookieHelper.ts +0 -36
  37. package/src/server/HeaderHelper.ts +0 -25
  38. package/src/server/Routerx.ts +0 -72
  39. package/src/server/Server.ts +0 -144
  40. package/src/server/ServerEvent.ts +0 -39
  41. package/src/server/connect/bufferToArrayBuffer.ts +0 -8
  42. package/src/server/connect/connectMiddleware.ts +0 -81
  43. package/src/server/connect/flattenHeaders.ts +0 -44
  44. package/src/server/connect/nodeMessageToNodeResponse.ts +0 -89
  45. package/src/server/connect/readableToBuffer.ts +0 -16
  46. package/src/server/connect/requestToNodeMessage.ts +0 -26
  47. package/src/server/contentType.ts +0 -85
  48. package/src/server/types/HttpMethod.ts +0 -12
  49. package/src/server/types/MiddlewareFunction.ts +0 -8
  50. package/src/server/types/ServerFunction.ts +0 -7
  51. package/src/server.ts +0 -7
  52. package/src/site/Router.ts +0 -164
  53. package/src/site/Site.ts +0 -214
  54. package/src/site/clientEntry.ts +0 -108
  55. package/src/site/clientEntryDev.ts +0 -3
  56. package/src/site/defaultAdapter.ts +0 -11
  57. package/src/site/manifest.ts +0 -54
  58. package/src/site/serverEntry.ts +0 -417
  59. package/src/state/$page.ts +0 -24
  60. package/src/state/client.ts +0 -15
  61. package/src/state.ts +0 -3
  62. package/src/test/runTest.ts +0 -350
  63. package/src/test.ts +0 -3
  64. package/src/types/Adapter.ts +0 -8
  65. package/src/types/ClientState.ts +0 -8
  66. package/src/types/InternalState.ts +0 -7
  67. package/src/types/LayoutHandler.ts +0 -5
  68. package/src/types/LayoutPath.ts +0 -10
  69. package/src/types/ManifestRoute.ts +0 -6
  70. package/src/types/PageEndPoint.ts +0 -39
  71. package/src/types/PageLoadEvent.ts +0 -14
  72. package/src/types/PageServerAction.ts +0 -7
  73. package/src/types/PageServerEndPoint.ts +0 -16
  74. package/src/types/PageServerLoad.ts +0 -7
  75. package/src/types/PageState.ts +0 -8
  76. package/src/types/Route.ts +0 -11
  77. package/src/types/RouteHandler.ts +0 -16
  78. package/src/types/RouteLayoutHandler.ts +0 -5
  79. package/src/types/RouteMatchResult.ts +0 -7
  80. package/src/types/RouteType.ts +0 -19
  81. package/src/types/ServerEndPoint.ts +0 -37
  82. package/src/types/ServerHook.ts +0 -11
  83. package/src/types/ServerLoadEvent.ts +0 -37
  84. package/src/types/ServerRequest.ts +0 -7
  85. package/src/utils/pathToRegex.ts +0 -15
  86. package/src/vite-env.d.ts +0 -2
  87. package/test/api/_hook.server.ts +0 -3
  88. package/test/api/posts/+page.server.ts +0 -3
  89. package/test/api/posts/[id]/+page.server.ts +0 -3
  90. package/test/app.test.ts +0 -47
  91. package/test/router.test.ts +0 -78
  92. package/test/routes/+page.server.ts +0 -3
  93. package/test/routes/+page.ts +0 -3
  94. package/test/routes/_error.ts +0 -3
  95. package/test/routes/_hook.server.ts +0 -3
  96. package/test/routes/_layout.server.ts +0 -3
  97. package/test/routes/_layout.ts +0 -3
  98. package/test/routes/posts/+page.ts +0 -3
  99. package/test/routes/posts/[id]/+page.ts +0 -3
  100. package/test/site.test.ts +0 -40
  101. package/tsconfig.json +0 -9
  102. package/tsdown.config.ts +0 -18
  103. package/vitest.config.ts +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/build",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "A framework for building sites and apps with Torpor",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,6 +36,10 @@
36
36
  "types": "./src/types/manifest.d.ts"
37
37
  }
38
38
  },
39
+ "files": [
40
+ "dist",
41
+ "./src/types/manifest.d.ts"
42
+ ],
39
43
  "publishConfig": {
40
44
  "access": "public"
41
45
  },
@@ -50,8 +54,8 @@
50
54
  "dotenv": "^17.2.3",
51
55
  "vite": "^7.2.2",
52
56
  "vite-tsconfig-paths": "^5.1.4",
53
- "@torpor/unplugin": "^0.2.1",
54
- "@torpor/view": "^0.4.14"
57
+ "@torpor/view": "^0.4.16",
58
+ "@torpor/unplugin": "^0.2.1"
55
59
  },
56
60
  "devDependencies": {
57
61
  "@trivago/prettier-plugin-sort-imports": "^6.0.0",
package/CHANGELOG.md DELETED
@@ -1,473 +0,0 @@
1
- # @torpor/build
2
-
3
- ## 0.4.9
4
-
5
- ### Patch Changes
6
-
7
- - 2e057c3: Fix: form and button actions
8
-
9
- ## 0.4.8
10
-
11
- ### Patch Changes
12
-
13
- - d813c86: Fix: pass search params to client side data cache
14
-
15
- ## 0.4.7
16
-
17
- ### Patch Changes
18
-
19
- - a09c14e: Fix: bad bin script
20
-
21
- ## 0.4.6
22
-
23
- ### Patch Changes
24
-
25
- - cf8d8db: Fix: pass search params to client side navigation
26
- - 64adf0b: Feat: `subFolder` option when adding routes
27
- - Updated dependencies [9bca98e]
28
- - Updated dependencies [7382b6d]
29
- - Updated dependencies [d68d347]
30
- - Updated dependencies [4e3d726]
31
- - Updated dependencies [adfa504]
32
- - @torpor/view@0.4.14
33
-
34
- ## 0.4.5
35
-
36
- ### Patch Changes
37
-
38
- - ec90aef: Fix: submit to a button's formaction if set
39
-
40
- ## 0.4.4
41
-
42
- ### Patch Changes
43
-
44
- - 5b12119: Fix: don't add error JSON as the message
45
- - Updated dependencies [3cc2168]
46
- - Updated dependencies [13f2afb]
47
- - @torpor/view@0.4.7
48
-
49
- ## 0.4.3
50
-
51
- ### Patch Changes
52
-
53
- - 426f7bd: Fix: return default $page.form status and message
54
-
55
- ## 0.4.2
56
-
57
- ### Patch Changes
58
-
59
- - 5dd6a23: Fix: only set $page.form if the result is JSON
60
-
61
- ## 0.4.1
62
-
63
- ### Patch Changes
64
-
65
- - 5972cf8: Fix: ensure that $page and client are always in scope
66
- - Updated dependencies [00a1868]
67
- - @torpor/view@0.4.3
68
-
69
- ## 0.4.0
70
-
71
- ### Minor Changes
72
-
73
- - 168dff3: !Edit: rename Range to Region to avoid name conflicts
74
-
75
- ### Patch Changes
76
-
77
- - 051998b: Feat: very rudimentary dev tools
78
- - Updated dependencies [255aad3]
79
- - Updated dependencies [8b377a2]
80
- - Updated dependencies [450b739]
81
- - Updated dependencies [168dff3]
82
- - Updated dependencies [fc60fe0]
83
- - Updated dependencies [42c6b60]
84
- - Updated dependencies [2818679]
85
- - Updated dependencies [38fd0a5]
86
- - Updated dependencies [3e6f3f7]
87
- - Updated dependencies [051998b]
88
- - @torpor/view@0.4.0
89
- - @torpor/unplugin@0.2.1
90
-
91
- ## 0.3.1
92
-
93
- ### Patch Changes
94
-
95
- - 34d17f7: Feat: UI Form component and client-side submit
96
- - Updated dependencies [f4716c5]
97
- - Updated dependencies [1253f7a]
98
- - Updated dependencies [6268e00]
99
- - Updated dependencies [f2fb547]
100
- - @torpor/view@0.3.2
101
-
102
- ## 0.3.0
103
-
104
- ### Minor Changes
105
-
106
- - 51dbba7: Chore: drop CJS build and go ESM only
107
- - 62b0d2e: !Edit: renamed responses and updated documentation
108
-
109
- ### Patch Changes
110
-
111
- - bbdc8d3: Feat: return form errors from the server
112
- - e1ae2bb: Feat: load and reload methods for navigation
113
- - Updated dependencies [be98b35]
114
- - Updated dependencies [51dbba7]
115
- - Updated dependencies [2298a87]
116
- - Updated dependencies [3a8431a]
117
- - Updated dependencies [eb58d37]
118
- - Updated dependencies [e0637be]
119
- - Updated dependencies [9fcc613]
120
- - Updated dependencies [f5f84e6]
121
- - Updated dependencies [6cc57ff]
122
- - Updated dependencies [c4f9d18]
123
- - Updated dependencies [5598bc9]
124
- - Updated dependencies [18f1ccf]
125
- - Updated dependencies [c2b5c02]
126
- - Updated dependencies [91d1536]
127
- - Updated dependencies [4dc16df]
128
- - Updated dependencies [543b229]
129
- - Updated dependencies [3cf3ae6]
130
- - @torpor/view@0.3.0
131
- - @torpor/unplugin@0.2.0
132
-
133
- ## 0.2.0
134
-
135
- ### Minor Changes
136
-
137
- - b716d5c: Feat: inline styles during SSR
138
-
139
- ### Patch Changes
140
-
141
- - a4f2573: Fix: reload the page on successful form submit
142
- - 67e6ca6: Fix: don't intercept external links
143
- - Updated dependencies [c38f914]
144
- - Updated dependencies [995d950]
145
- - Updated dependencies [b716d5c]
146
- - Updated dependencies [014bda0]
147
- - @torpor/view@0.2.0
148
- - @torpor/unplugin@0.1.17
149
-
150
- ## 0.1.34
151
-
152
- ### Patch Changes
153
-
154
- - 1221923: Fix: updating layouts in [parameter] routes
155
- - Updated dependencies [741a289]
156
- - @torpor/view@0.1.11
157
-
158
- ## 0.1.33
159
-
160
- ### Patch Changes
161
-
162
- - 74bf42d: Fix: store (and clear) the right layout slot ranges
163
- - Updated dependencies [74bf42d]
164
- - @torpor/view@0.1.10
165
-
166
- ## 0.1.32
167
-
168
- ### Patch Changes
169
-
170
- - 951a86f: Feat: re-use layout data and UI
171
- - 182d436: Feat: prefetching link data
172
- - Updated dependencies [1866f30]
173
- - Updated dependencies [a31647f]
174
- - Updated dependencies [951a86f]
175
- - Updated dependencies [6d6fb89]
176
- - Updated dependencies [9c13f0f]
177
- - @torpor/view@0.1.6
178
-
179
- ## 0.1.31
180
-
181
- ### Patch Changes
182
-
183
- - Updated dependencies [f390b78]
184
- - @torpor/view@0.1.5
185
- - @torpor/unplugin@0.1.16
186
-
187
- ## 0.1.30
188
-
189
- ### Patch Changes
190
-
191
- - Updated dependencies [daba2ad]
192
- - @torpor/view@0.1.4
193
- - @torpor/unplugin@0.1.15
194
-
195
- ## 0.1.29
196
-
197
- ### Patch Changes
198
-
199
- - Updated dependencies [de51225]
200
- - @torpor/view@0.1.3
201
- - @torpor/unplugin@0.1.14
202
-
203
- ## 0.1.28
204
-
205
- ### Patch Changes
206
-
207
- - fa85b57: Fix: force `.torp` file compilation in dev
208
-
209
- ## 0.1.27
210
-
211
- ### Patch Changes
212
-
213
- - bed55d5: Feat: allow passing Vite options in dev
214
-
215
- ## 0.1.26
216
-
217
- ### Patch Changes
218
-
219
- - 348cd75: Feat: allow creating the Site router with files
220
- - Updated dependencies [0e69292]
221
- - Updated dependencies [b69fde1]
222
- - @torpor/view@0.1.2
223
- - @torpor/unplugin@0.1.13
224
-
225
- ## 0.1.25
226
-
227
- ### Patch Changes
228
-
229
- - 3fe0d0e: Feat: set default error messages in responses
230
- - f26603f: Feat: basic error handling
231
- - Updated dependencies [f9fd76d]
232
- - Updated dependencies [1ddc240]
233
- - Updated dependencies [7b9dc31]
234
- - @torpor/view@0.1.1
235
- - @torpor/unplugin@0.1.12
236
-
237
- ## 0.1.24
238
-
239
- ### Patch Changes
240
-
241
- - 6092a91: Fix: don't swallow error responses when loading data
242
-
243
- ## 0.1.23
244
-
245
- ### Patch Changes
246
-
247
- - 22f62d4: Fix: Site.viteConfig settings
248
-
249
- ## 0.1.22
250
-
251
- ### Patch Changes
252
-
253
- - 4e0ec90: Feat: allow more Site.viteConfig settings
254
-
255
- ## 0.1.21
256
-
257
- ### Patch Changes
258
-
259
- - 4296742: Feat: add Site.viteConfig to set Vite options in build
260
-
261
- ## 0.1.20
262
-
263
- ### Patch Changes
264
-
265
- - a61f30f: Debug: double hydration
266
- - Updated dependencies [28a993b]
267
- - Updated dependencies [98602ec]
268
- - Updated dependencies [a49d307]
269
- - Updated dependencies [995513a]
270
- - Updated dependencies [c9a9cf8]
271
- - Updated dependencies [cbd07ca]
272
- - Updated dependencies [f53b184]
273
- - Updated dependencies [215db17]
274
- - Updated dependencies [95e866b]
275
- - @torpor/unplugin@0.1.11
276
- - @torpor/view@0.1.0
277
-
278
- ## 0.1.19
279
-
280
- ### Patch Changes
281
-
282
- - 170c886: Debug: double hydration
283
-
284
- ## 0.1.18
285
-
286
- ### Patch Changes
287
-
288
- - Updated dependencies [fb896c6]
289
- - Updated dependencies [85bccf6]
290
- - @torpor/view@0.0.14
291
- - @torpor/unplugin@0.1.10
292
-
293
- ## 0.1.17
294
-
295
- ### Patch Changes
296
-
297
- - 7373f27: Fix: parse the cookie value retrieved from the map
298
- - 679a448: Fix: set $page props on every navigation
299
- - e5b761b: Feat: allow passing ServerEvent to runTest
300
- - Updated dependencies [ed4a6db]
301
- - @torpor/view@0.0.13
302
- - @torpor/unplugin@0.1.9
303
-
304
- ## 0.1.16
305
-
306
- ### Patch Changes
307
-
308
- - 9332635: Fix: set $page props in the correct object
309
- - Updated dependencies [ff5f459]
310
- - @torpor/view@0.0.12
311
- - @torpor/unplugin@0.1.8
312
-
313
- ## 0.1.15
314
-
315
- ### Patch Changes
316
-
317
- - Updated dependencies [e4060e6]
318
- - @torpor/unplugin@0.1.7
319
-
320
- ## 0.1.14
321
-
322
- ### Patch Changes
323
-
324
- - e395c9e: Feat: rudimentary test infrastructure
325
- - Updated dependencies [5676a0b]
326
- - @torpor/unplugin@0.1.6
327
-
328
- ## 0.1.13
329
-
330
- ### Patch Changes
331
-
332
- - 02eac8e: Feat: allow passing extra inputs to build
333
-
334
- ## 0.1.12
335
-
336
- ### Patch Changes
337
-
338
- - 8de094b: Fix: ignore trailing slashes when matching routes
339
-
340
- ## 0.1.11
341
-
342
- ### Patch Changes
343
-
344
- - 858538b: Fix: move adapter to globalThis, pass it to server loads
345
-
346
- ## 0.1.10
347
-
348
- ### Patch Changes
349
-
350
- - Updated dependencies [78e78b9]
351
- - @torpor/view@0.0.11
352
- - @torpor/unplugin@0.1.5
353
-
354
- ## 0.1.9
355
-
356
- ### Patch Changes
357
-
358
- - ff685cb: Fix: use the existing fragment name
359
-
360
- ## 0.1.8
361
-
362
- ### Patch Changes
363
-
364
- - fe7444e: Refactor: rearrange build exports
365
- - Updated dependencies [8852c89]
366
- - @torpor/unplugin@0.1.4
367
-
368
- ## 0.1.7
369
-
370
- ### Patch Changes
371
-
372
- - Updated dependencies [3cf6de6]
373
- - @torpor/view@0.0.10
374
- - @torpor/unplugin@0.1.3
375
-
376
- ## 0.1.6
377
-
378
- ### Patch Changes
379
-
380
- - 47c5277: Chore: update dependencies
381
- - Updated dependencies [47c5277]
382
- - @torpor/unplugin@0.1.2
383
- - @torpor/view@0.0.9
384
-
385
- ## 0.1.5
386
-
387
- ### Patch Changes
388
-
389
- - 5c9d90f: Fix: double check server rendering from Vite options
390
- - Updated dependencies [a8ead36]
391
- - @torpor/view@0.0.8
392
- - @torpor/unplugin@0.1.1
393
-
394
- ## 0.1.4
395
-
396
- ### Patch Changes
397
-
398
- - 20ddf6c: Fix: better/less console.logging
399
-
400
- ## 0.1.3
401
-
402
- ### Patch Changes
403
-
404
- - 4b86717: Refactor: separate adapters into packages
405
-
406
- ## 0.1.2
407
-
408
- ### Patch Changes
409
-
410
- - d31d14d: Feat: allow running from code
411
-
412
- ## 0.1.1
413
-
414
- ### Patch Changes
415
-
416
- - Updated dependencies
417
- - @torpor/unplugin@0.1.0
418
-
419
- ## 0.1.0
420
-
421
- ### Minor Changes
422
-
423
- - Chore: replace Vinxi with Vite plugins
424
-
425
- ## 0.0.6
426
-
427
- ### Patch Changes
428
-
429
- - Updated dependencies [b90d729]
430
- - @torpor/view@0.0.7
431
- - @torpor/unplugin@0.0.6
432
-
433
- ## 0.0.5
434
-
435
- ### Patch Changes
436
-
437
- - 79da6cf: Refactor: export more types
438
- - 3707fdb: Fix: better ordering of routes
439
- - Updated dependencies [808da4c]
440
- - @torpor/view@0.0.6
441
- - @torpor/unplugin@0.0.5
442
-
443
- ## 0.0.4
444
-
445
- ### Patch Changes
446
-
447
- - Updated dependencies [44cf656]
448
- - Updated dependencies [a278176]
449
- - @torpor/view@0.0.5
450
- - @torpor/unplugin@0.0.4
451
-
452
- ## 0.0.3
453
-
454
- ### Patch Changes
455
-
456
- - Updated dependencies [76dd6ea]
457
- - Updated dependencies [8f0a0a1]
458
- - @torpor/view@0.0.4
459
- - @torpor/unplugin@0.0.3
460
-
461
- ## 0.0.2
462
-
463
- ### Patch Changes
464
-
465
- - Fix: use /~server for hooks as well as layouts
466
- - Fix: catch-all routes should get checked last
467
- - Updated dependencies
468
- - Updated dependencies
469
- - Updated dependencies
470
- - Updated dependencies
471
- - Updated dependencies
472
- - @torpor/view@0.0.3
473
- - @torpor/unplugin@0.0.2
@@ -1,12 +0,0 @@
1
- import { renameSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
- // HACK: tsdown only creates *.mjs files now (post v0.16), so we need to rename
6
- // the bin/index.mjs file to bin/index.js for it to be run by node
7
-
8
- const scriptsFolder = dirname(fileURLToPath(import.meta.url));
9
- const distFolder = resolve(scriptsFolder, "../dist");
10
-
11
- renameSync(join(distFolder, "bin", "index.mjs"), join(distFolder, "bin", "index.js"));
12
- renameSync(join(distFolder, "bin", "index.mjs.map"), join(distFolder, "bin", "index.js.map"));
package/src/bin/index.ts DELETED
@@ -1,11 +0,0 @@
1
- #! /usr/bin/env node
2
- import run from "../run/run";
3
-
4
- const workingDir = process.cwd();
5
- if (process.argv.includes("--dev")) {
6
- await run(workingDir, "dev");
7
- } else if (process.argv.includes("--build")) {
8
- await run(workingDir, "build");
9
- } else if (process.argv.includes("--preview")) {
10
- await run(workingDir, "preview");
11
- }
package/src/index.ts DELETED
@@ -1,30 +0,0 @@
1
- import Router from "./site/Router";
2
- import Site from "./site/Site";
3
- import type Adapter from "./types/Adapter";
4
- import type PageEndPoint from "./types/PageEndPoint";
5
- import type PageLoadEvent from "./types/PageLoadEvent";
6
- import type PageServerAction from "./types/PageServerAction";
7
- import type PageServerEndPoint from "./types/PageServerEndPoint";
8
- import type PageServerLoad from "./types/PageServerLoad";
9
- import type ServerEndPoint from "./types/ServerEndPoint";
10
- import type ServerHook from "./types/ServerHook";
11
- import type ServerLoadEvent from "./types/ServerLoadEvent";
12
- import type ServerRequest from "./types/ServerRequest";
13
-
14
- // NOTE: Don't export any general functionality from here -- it may result in
15
- // Vite errors like `Could not resolve '../pkg' in lightningcss` etc
16
-
17
- export { Site, Router };
18
-
19
- export type {
20
- Adapter,
21
- PageEndPoint,
22
- PageServerEndPoint,
23
- PageServerLoad,
24
- PageServerAction,
25
- ServerEndPoint,
26
- ServerRequest,
27
- ServerHook,
28
- PageLoadEvent,
29
- ServerLoadEvent,
30
- };
@@ -1,56 +0,0 @@
1
- import $page from "../state/$page";
2
- import load from "./load";
3
- import reload from "./reload";
4
-
5
- export default async function formSubmit(e: SubmitEvent): Promise<void> {
6
- // We'll take it from here
7
- e.preventDefault();
8
-
9
- // Reset $page on submit and link navigation
10
- // TODO: Should we put data in $page.data??
11
- $page.form = undefined;
12
-
13
- // Perform a POST fetch to the form's action location
14
- const form = e.target as HTMLFormElement;
15
- const button = e.submitter as HTMLButtonElement;
16
- // HACK: submit buttons have their formAction set to the current page if not
17
- // set, so we can't just check whether it's empty and fallback to form action
18
- //const action = button?.formAction ?? form.action;
19
- let action = form.action || document.URL;
20
- if (button && button.formAction && button.formAction !== document.URL) {
21
- action = button.formAction;
22
- }
23
- const options = {
24
- body: new FormData(form),
25
- method: "POST",
26
- mode: "cors",
27
- credentials: "same-origin",
28
- // Add a special header which tells the server that we want the raw
29
- // error response (if applicable) rather than the reloaded page that you
30
- // would get if submitting a page without javascript
31
- headers: {
32
- "x-torpor-form-submit": "",
33
- },
34
- };
35
- const response = await fetch(
36
- action,
37
- // @ts-ignore -- don't know what it's complaining about here
38
- options,
39
- );
40
-
41
- if (response.status === 200 && response.headers.has("x-torpor-form-redirect")) {
42
- // TODO: Should do the correct type of redirect e.g. seeOther etc
43
- const redirect = response.headers.get("location")!;
44
- await load(redirect);
45
- window.location.href = redirect;
46
- } else if (
47
- (response.status >= 200 && response.status <= 299) ||
48
- (response.status >= 400 && response.status <= 499)
49
- ) {
50
- // Put the response into `$page.form`, and it will be put into `$props` in reload
51
- if (response.headers.get("content-type") === "application/json") {
52
- $page.form = await response.json();
53
- }
54
- await reload();
55
- }
56
- }
package/src/nav/load.ts DELETED
@@ -1,9 +0,0 @@
1
- import navigate from "./navigate";
2
-
3
- /**
4
- * Loads and renders the page at the supplied path.
5
- */
6
- export default async function load(path: string): Promise<boolean> {
7
- const url = new URL(path, document.location.href);
8
- return await navigate(url);
9
- }