hono 4.4.9 → 4.5.0-rc.2

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 (76) hide show
  1. package/dist/adapter/bun/conninfo.js +1 -1
  2. package/dist/adapter/cloudflare-pages/handler.js +41 -0
  3. package/dist/adapter/cloudflare-pages/index.js +2 -1
  4. package/dist/adapter/cloudflare-workers/conninfo.js +1 -2
  5. package/dist/adapter/deno/conninfo.js +1 -2
  6. package/dist/cjs/adapter/bun/conninfo.js +1 -1
  7. package/dist/cjs/adapter/cloudflare-pages/handler.js +42 -0
  8. package/dist/cjs/adapter/cloudflare-pages/index.js +2 -0
  9. package/dist/cjs/adapter/cloudflare-workers/conninfo.js +1 -2
  10. package/dist/cjs/adapter/deno/conninfo.js +1 -2
  11. package/dist/cjs/helper/html/index.js +1 -1
  12. package/dist/cjs/helper/streaming/sse.js +5 -0
  13. package/dist/cjs/helper/streaming/stream.js +5 -0
  14. package/dist/cjs/jsx/base.js +29 -2
  15. package/dist/cjs/jsx/constants.js +5 -2
  16. package/dist/cjs/jsx/context.js +15 -18
  17. package/dist/cjs/jsx/dom/client.js +5 -0
  18. package/dist/cjs/jsx/dom/context.js +6 -8
  19. package/dist/cjs/jsx/dom/hooks/index.js +75 -0
  20. package/dist/cjs/jsx/dom/index.js +13 -0
  21. package/dist/cjs/jsx/dom/intrinsic-element/components.js +351 -0
  22. package/dist/cjs/jsx/dom/jsx-dev-runtime.js +8 -1
  23. package/dist/cjs/jsx/dom/render.js +96 -42
  24. package/dist/cjs/jsx/dom/server.js +64 -0
  25. package/dist/cjs/jsx/hooks/index.js +56 -56
  26. package/dist/cjs/jsx/index.js +10 -0
  27. package/dist/cjs/jsx/intrinsic-element/common.js +40 -0
  28. package/dist/cjs/jsx/intrinsic-element/components.js +164 -0
  29. package/dist/cjs/jsx/utils.js +7 -1
  30. package/dist/cjs/middleware/jwt/jwt.js +20 -1
  31. package/dist/cjs/utils/html.js +14 -2
  32. package/dist/cjs/utils/stream.js +8 -1
  33. package/dist/helper/html/index.js +2 -2
  34. package/dist/helper/streaming/sse.js +5 -0
  35. package/dist/helper/streaming/stream.js +5 -0
  36. package/dist/jsx/base.js +24 -3
  37. package/dist/jsx/constants.js +3 -1
  38. package/dist/jsx/context.js +15 -18
  39. package/dist/jsx/dom/client.js +5 -0
  40. package/dist/jsx/dom/context.js +7 -9
  41. package/dist/jsx/dom/hooks/index.js +48 -0
  42. package/dist/jsx/dom/index.js +9 -0
  43. package/dist/jsx/dom/intrinsic-element/components.js +319 -0
  44. package/dist/jsx/dom/jsx-dev-runtime.js +2 -1
  45. package/dist/jsx/dom/render.js +95 -42
  46. package/dist/jsx/dom/server.js +33 -0
  47. package/dist/jsx/hooks/index.js +57 -57
  48. package/dist/jsx/index.js +7 -0
  49. package/dist/jsx/intrinsic-element/common.js +15 -0
  50. package/dist/jsx/intrinsic-element/components.js +134 -0
  51. package/dist/jsx/utils.js +7 -1
  52. package/dist/middleware/jwt/jwt.js +21 -2
  53. package/dist/types/adapter/cloudflare-pages/handler.d.ts +3 -1
  54. package/dist/types/adapter/cloudflare-pages/index.d.ts +1 -1
  55. package/dist/types/helper/conninfo/types.d.ts +1 -1
  56. package/dist/types/jsx/base.d.ts +4 -4
  57. package/dist/types/jsx/constants.d.ts +1 -0
  58. package/dist/types/jsx/context.d.ts +3 -1
  59. package/dist/types/jsx/dom/client.d.ts +5 -0
  60. package/dist/types/jsx/dom/hooks/index.d.ts +38 -0
  61. package/dist/types/jsx/dom/index.d.ts +23 -8
  62. package/dist/types/jsx/dom/intrinsic-element/components.d.ts +16 -0
  63. package/dist/types/jsx/dom/render.d.ts +21 -7
  64. package/dist/types/jsx/dom/server.d.ts +106 -0
  65. package/dist/types/jsx/hooks/index.d.ts +4 -3
  66. package/dist/types/jsx/index.d.ts +11 -4
  67. package/dist/types/jsx/intrinsic-element/common.d.ts +3 -0
  68. package/dist/types/jsx/intrinsic-element/components.d.ts +13 -0
  69. package/dist/types/jsx/intrinsic-elements.d.ts +24 -0
  70. package/dist/types/jsx/streaming.d.ts +1 -1
  71. package/dist/types/middleware/jwt/jwt.d.ts +6 -1
  72. package/dist/types/utils/html.d.ts +5 -1
  73. package/dist/types/utils/stream.d.ts +9 -0
  74. package/dist/utils/html.js +13 -2
  75. package/dist/utils/stream.js +8 -1
  76. package/package.json +10 -2
@@ -12,7 +12,7 @@ var getConnInfo = (c) => {
12
12
  return {
13
13
  remote: {
14
14
  address: info.address,
15
- addressType: info.family === "IPv6" || info.family === "IPv4" ? info.family : "unknown",
15
+ addressType: info.family === "IPv6" || info.family === "IPv4" ? info.family : void 0,
16
16
  port: info.port
17
17
  }
18
18
  };
@@ -1,4 +1,6 @@
1
1
  // src/adapter/cloudflare-pages/handler.ts
2
+ import { Context } from "../../context.js";
3
+ import { HTTPException } from "../../http-exception.js";
2
4
  var handle = (app) => (eventContext) => {
3
5
  return app.fetch(
4
6
  eventContext.request,
@@ -9,6 +11,44 @@ var handle = (app) => (eventContext) => {
9
11
  }
10
12
  );
11
13
  };
14
+ function handleMiddleware(middleware) {
15
+ return async (executionCtx) => {
16
+ const context = new Context(executionCtx.request, {
17
+ env: executionCtx.env,
18
+ executionCtx
19
+ });
20
+ let response = void 0;
21
+ try {
22
+ response = await middleware(context, async () => {
23
+ try {
24
+ context.res = await executionCtx.next();
25
+ } catch (error) {
26
+ if (error instanceof Error) {
27
+ context.error = error;
28
+ } else {
29
+ throw error;
30
+ }
31
+ }
32
+ });
33
+ } catch (error) {
34
+ if (error instanceof Error) {
35
+ context.error = error;
36
+ } else {
37
+ throw error;
38
+ }
39
+ }
40
+ if (response) {
41
+ return response;
42
+ }
43
+ if (context.error instanceof HTTPException) {
44
+ return context.error.getResponse();
45
+ }
46
+ if (context.error) {
47
+ throw context.error;
48
+ }
49
+ return context.res;
50
+ };
51
+ }
12
52
  var serveStatic = () => {
13
53
  return async (c) => {
14
54
  const env = c.env;
@@ -21,5 +61,6 @@ var serveStatic = () => {
21
61
  };
22
62
  export {
23
63
  handle,
64
+ handleMiddleware,
24
65
  serveStatic
25
66
  };
@@ -1,6 +1,7 @@
1
1
  // src/adapter/cloudflare-pages/index.ts
2
- import { handle, serveStatic } from "./handler.js";
2
+ import { handle, handleMiddleware, serveStatic } from "./handler.js";
3
3
  export {
4
4
  handle,
5
+ handleMiddleware,
5
6
  serveStatic
6
7
  };
@@ -1,8 +1,7 @@
1
1
  // src/adapter/cloudflare-workers/conninfo.ts
2
2
  var getConnInfo = (c) => ({
3
3
  remote: {
4
- address: c.req.header("cf-connecting-ip"),
5
- addressType: "unknown"
4
+ address: c.req.header("cf-connecting-ip")
6
5
  }
7
6
  });
8
7
  export {
@@ -5,8 +5,7 @@ var getConnInfo = (c) => {
5
5
  remote: {
6
6
  address: remoteAddr.hostname,
7
7
  port: remoteAddr.port,
8
- transport: remoteAddr.transport,
9
- addressType: "unknown"
8
+ transport: remoteAddr.transport
10
9
  }
11
10
  };
12
11
  };
@@ -34,7 +34,7 @@ const getConnInfo = (c) => {
34
34
  return {
35
35
  remote: {
36
36
  address: info.address,
37
- addressType: info.family === "IPv6" || info.family === "IPv4" ? info.family : "unknown",
37
+ addressType: info.family === "IPv6" || info.family === "IPv4" ? info.family : void 0,
38
38
  port: info.port
39
39
  }
40
40
  };
@@ -19,9 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var handler_exports = {};
20
20
  __export(handler_exports, {
21
21
  handle: () => handle,
22
+ handleMiddleware: () => handleMiddleware,
22
23
  serveStatic: () => serveStatic
23
24
  });
24
25
  module.exports = __toCommonJS(handler_exports);
26
+ var import_context = require("../../context");
27
+ var import_http_exception = require("../../http-exception");
25
28
  const handle = (app) => (eventContext) => {
26
29
  return app.fetch(
27
30
  eventContext.request,
@@ -32,6 +35,44 @@ const handle = (app) => (eventContext) => {
32
35
  }
33
36
  );
34
37
  };
38
+ function handleMiddleware(middleware) {
39
+ return async (executionCtx) => {
40
+ const context = new import_context.Context(executionCtx.request, {
41
+ env: executionCtx.env,
42
+ executionCtx
43
+ });
44
+ let response = void 0;
45
+ try {
46
+ response = await middleware(context, async () => {
47
+ try {
48
+ context.res = await executionCtx.next();
49
+ } catch (error) {
50
+ if (error instanceof Error) {
51
+ context.error = error;
52
+ } else {
53
+ throw error;
54
+ }
55
+ }
56
+ });
57
+ } catch (error) {
58
+ if (error instanceof Error) {
59
+ context.error = error;
60
+ } else {
61
+ throw error;
62
+ }
63
+ }
64
+ if (response) {
65
+ return response;
66
+ }
67
+ if (context.error instanceof import_http_exception.HTTPException) {
68
+ return context.error.getResponse();
69
+ }
70
+ if (context.error) {
71
+ throw context.error;
72
+ }
73
+ return context.res;
74
+ };
75
+ }
35
76
  const serveStatic = () => {
36
77
  return async (c) => {
37
78
  const env = c.env;
@@ -45,5 +86,6 @@ const serveStatic = () => {
45
86
  // Annotate the CommonJS export names for ESM import in node:
46
87
  0 && (module.exports = {
47
88
  handle,
89
+ handleMiddleware,
48
90
  serveStatic
49
91
  });
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var cloudflare_pages_exports = {};
20
20
  __export(cloudflare_pages_exports, {
21
21
  handle: () => import_handler.handle,
22
+ handleMiddleware: () => import_handler.handleMiddleware,
22
23
  serveStatic: () => import_handler.serveStatic
23
24
  });
24
25
  module.exports = __toCommonJS(cloudflare_pages_exports);
@@ -26,5 +27,6 @@ var import_handler = require("./handler");
26
27
  // Annotate the CommonJS export names for ESM import in node:
27
28
  0 && (module.exports = {
28
29
  handle,
30
+ handleMiddleware,
29
31
  serveStatic
30
32
  });
@@ -23,8 +23,7 @@ __export(conninfo_exports, {
23
23
  module.exports = __toCommonJS(conninfo_exports);
24
24
  const getConnInfo = (c) => ({
25
25
  remote: {
26
- address: c.req.header("cf-connecting-ip"),
27
- addressType: "unknown"
26
+ address: c.req.header("cf-connecting-ip")
28
27
  }
29
28
  });
30
29
  // Annotate the CommonJS export names for ESM import in node:
@@ -27,8 +27,7 @@ const getConnInfo = (c) => {
27
27
  remote: {
28
28
  address: remoteAddr.hostname,
29
29
  port: remoteAddr.port,
30
- transport: remoteAddr.transport,
31
- addressType: "unknown"
30
+ transport: remoteAddr.transport
32
31
  }
33
32
  };
34
33
  };
@@ -56,7 +56,7 @@ const html = (strings, ...values) => {
56
56
  }
57
57
  }
58
58
  buffer[0] += strings[strings.length - 1];
59
- return buffer.length === 1 ? (0, import_html.raw)(buffer[0]) : (0, import_html.stringBufferToString)(buffer);
59
+ return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html.raw)((0, import_html.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks))) : (0, import_html.raw)(buffer[0]) : (0, import_html.stringBufferToString)(buffer, buffer.callbacks);
60
60
  };
61
61
  // Annotate the CommonJS export names for ESM import in node:
62
62
  0 && (module.exports = {
@@ -57,9 +57,14 @@ const run = async (stream, cb, onError) => {
57
57
  stream.close();
58
58
  }
59
59
  };
60
+ const contextStash = /* @__PURE__ */ new WeakMap();
60
61
  const streamSSE = (c, cb, onError) => {
61
62
  const { readable, writable } = new TransformStream();
62
63
  const stream = new SSEStreamingApi(writable, readable);
64
+ c.req.raw.signal.addEventListener("abort", () => {
65
+ stream.abort();
66
+ });
67
+ contextStash.set(stream.responseReadable, c);
63
68
  c.header("Transfer-Encoding", "chunked");
64
69
  c.header("Content-Type", "text/event-stream");
65
70
  c.header("Cache-Control", "no-cache");
@@ -22,9 +22,14 @@ __export(stream_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(stream_exports);
24
24
  var import_stream = require("../../utils/stream");
25
+ const contextStash = /* @__PURE__ */ new WeakMap();
25
26
  const stream = (c, cb, onError) => {
26
27
  const { readable, writable } = new TransformStream();
27
28
  const stream2 = new import_stream.StreamingApi(writable, readable);
29
+ c.req.raw.signal.addEventListener("abort", () => {
30
+ stream2.abort();
31
+ });
32
+ contextStash.set(stream2.responseReadable, c);
28
33
  (async () => {
29
34
  try {
30
35
  await cb(stream2);
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
25
  var base_exports = {};
20
26
  __export(base_exports, {
@@ -32,7 +38,10 @@ module.exports = __toCommonJS(base_exports);
32
38
  var import_html = require("../helper/html");
33
39
  var import_html2 = require("../utils/html");
34
40
  var import_context = require("./context");
41
+ var import_constants = require("./constants");
35
42
  var import_utils = require("./utils");
43
+ var intrinsicElementTags = __toESM(require("./intrinsic-element/components"), 1);
44
+ var import_common = require("./intrinsic-element/common");
36
45
  const emptyTags = [
37
46
  "area",
38
47
  "base",
@@ -126,7 +135,7 @@ class JSXNode {
126
135
  context.values.pop();
127
136
  });
128
137
  }
129
- return buffer.length === 1 ? buffer[0] : (0, import_html2.stringBufferToString)(buffer);
138
+ return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html2.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks)).toString() : buffer[0] : (0, import_html2.stringBufferToString)(buffer, buffer.callbacks);
130
139
  }
131
140
  toStringToBuffer(buffer) {
132
141
  const tag = this.tag;
@@ -210,6 +219,10 @@ class JSXFunctionNode extends JSXNode {
210
219
  res.toStringToBuffer(buffer);
211
220
  } else if (typeof res === "number" || res.isEscaped) {
212
221
  buffer[0] += res;
222
+ if (res.callbacks) {
223
+ buffer.callbacks ||= [];
224
+ buffer.callbacks.push(...res.callbacks);
225
+ }
213
226
  } else {
214
227
  (0, import_html2.escapeToBuffer)(res, buffer);
215
228
  }
@@ -231,9 +244,23 @@ const jsx = (tag, props, ...children) => {
231
244
  node.key = key;
232
245
  return node;
233
246
  };
247
+ let initDomRenderer = false;
234
248
  const jsxFn = (tag, props, children) => {
249
+ if (!initDomRenderer) {
250
+ for (const k in import_common.domRenderers) {
251
+ ;
252
+ intrinsicElementTags[k][import_constants.DOM_RENDERER] = import_common.domRenderers[k];
253
+ }
254
+ initDomRenderer = true;
255
+ }
235
256
  if (typeof tag === "function") {
236
257
  return new JSXFunctionNode(tag, props, children);
258
+ } else if (intrinsicElementTags[tag]) {
259
+ return new JSXFunctionNode(
260
+ intrinsicElementTags[tag],
261
+ props,
262
+ children
263
+ );
237
264
  } else {
238
265
  return new JSXNode(tag, props, children);
239
266
  }
@@ -288,7 +315,7 @@ const cloneElement = (element, props, ...children) => {
288
315
  ...children
289
316
  );
290
317
  };
291
- const reactAPICompatVersion = "18.0.0-hono-jsx";
318
+ const reactAPICompatVersion = "19.0.0-hono-jsx";
292
319
  // Annotate the CommonJS export names for ESM import in node:
293
320
  0 && (module.exports = {
294
321
  Fragment,
@@ -21,17 +21,20 @@ __export(constants_exports, {
21
21
  DOM_ERROR_HANDLER: () => DOM_ERROR_HANDLER,
22
22
  DOM_INTERNAL_TAG: () => DOM_INTERNAL_TAG,
23
23
  DOM_RENDERER: () => DOM_RENDERER,
24
- DOM_STASH: () => DOM_STASH
24
+ DOM_STASH: () => DOM_STASH,
25
+ PERMALINK: () => PERMALINK
25
26
  });
26
27
  module.exports = __toCommonJS(constants_exports);
27
28
  const DOM_RENDERER = Symbol("RENDERER");
28
29
  const DOM_ERROR_HANDLER = Symbol("ERROR_HANDLER");
29
30
  const DOM_STASH = Symbol("STASH");
30
31
  const DOM_INTERNAL_TAG = Symbol("INTERNAL");
32
+ const PERMALINK = Symbol("PERMALINK");
31
33
  // Annotate the CommonJS export names for ESM import in node:
32
34
  0 && (module.exports = {
33
35
  DOM_ERROR_HANDLER,
34
36
  DOM_INTERNAL_TAG,
35
37
  DOM_RENDERER,
36
- DOM_STASH
38
+ DOM_STASH,
39
+ PERMALINK
37
40
  });
@@ -30,26 +30,23 @@ var import_context = require("./dom/context");
30
30
  const globalContexts = [];
31
31
  const createContext = (defaultValue) => {
32
32
  const values = [defaultValue];
33
- const context = {
34
- values,
35
- Provider(props) {
36
- values.push(props.value);
37
- let string;
38
- try {
39
- string = props.children ? (Array.isArray(props.children) ? new import_base.JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
40
- } finally {
41
- values.pop();
42
- }
43
- if (string instanceof Promise) {
44
- return string.then(
45
- (resString) => (0, import_html.raw)(resString, resString.callbacks)
46
- );
47
- } else {
48
- return (0, import_html.raw)(string);
49
- }
33
+ const context = (props) => {
34
+ values.push(props.value);
35
+ let string;
36
+ try {
37
+ string = props.children ? (Array.isArray(props.children) ? new import_base.JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
38
+ } finally {
39
+ values.pop();
40
+ }
41
+ if (string instanceof Promise) {
42
+ return string.then((resString) => (0, import_html.raw)(resString, resString.callbacks));
43
+ } else {
44
+ return (0, import_html.raw)(string);
50
45
  }
51
46
  };
52
- context.Provider[import_constants.DOM_RENDERER] = (0, import_context.createContextProviderFunction)(values);
47
+ context.values = values;
48
+ context.Provider = context;
49
+ context[import_constants.DOM_RENDERER] = (0, import_context.createContextProviderFunction)(values);
53
50
  globalContexts.push(context);
54
51
  return context;
55
52
  };
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var client_exports = {};
20
20
  __export(client_exports, {
21
21
  createRoot: () => createRoot,
22
+ default: () => client_default,
22
23
  hydrateRoot: () => hydrateRoot
23
24
  });
24
25
  module.exports = __toCommonJS(client_exports);
@@ -61,6 +62,10 @@ const hydrateRoot = (element, reactNode, options = {}) => {
61
62
  root.render(reactNode);
62
63
  return root;
63
64
  };
65
+ var client_default = {
66
+ createRoot,
67
+ hydrateRoot
68
+ };
64
69
  // Annotate the CommonJS export names for ESM import in node:
65
70
  0 && (module.exports = {
66
71
  createRoot,
@@ -24,9 +24,8 @@ __export(context_exports, {
24
24
  module.exports = __toCommonJS(context_exports);
25
25
  var import_constants = require("../constants");
26
26
  var import_context = require("../context");
27
- var import_jsx_runtime = require("./jsx-runtime");
28
27
  var import_utils = require("./utils");
29
- const createContextProviderFunction = (values) => (0, import_utils.setInternalTagFlag)(({ value, children }) => {
28
+ const createContextProviderFunction = (values) => ({ value, children }) => {
30
29
  if (!children) {
31
30
  return void 0;
32
31
  }
@@ -51,19 +50,18 @@ const createContextProviderFunction = (values) => (0, import_utils.setInternalTa
51
50
  }),
52
51
  props: {}
53
52
  });
54
- const res = (0, import_jsx_runtime.Fragment)(props);
53
+ const res = (0, import_utils.newJSXNode)({ tag: "", props });
55
54
  res[import_constants.DOM_ERROR_HANDLER] = (err) => {
56
55
  values.pop();
57
56
  throw err;
58
57
  };
59
58
  return res;
60
- });
59
+ };
61
60
  const createContext = (defaultValue) => {
62
61
  const values = [defaultValue];
63
- const context = {
64
- values,
65
- Provider: createContextProviderFunction(values)
66
- };
62
+ const context = createContextProviderFunction(values);
63
+ context.values = values;
64
+ context.Provider = context;
67
65
  import_context.globalContexts.push(context);
68
66
  return context;
69
67
  };
@@ -0,0 +1,75 @@
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 hooks_exports = {};
20
+ __export(hooks_exports, {
21
+ FormContext: () => FormContext,
22
+ registerAction: () => registerAction,
23
+ useActionState: () => useActionState,
24
+ useFormStatus: () => useFormStatus,
25
+ useOptimistic: () => useOptimistic
26
+ });
27
+ module.exports = __toCommonJS(hooks_exports);
28
+ var import_context = require("../../context");
29
+ var import_context2 = require("../context");
30
+ var import_hooks = require("../../hooks");
31
+ var import_constants = require("../../constants");
32
+ const FormContext = (0, import_context2.createContext)({
33
+ pending: false,
34
+ data: null,
35
+ method: null,
36
+ action: null
37
+ });
38
+ const actions = /* @__PURE__ */ new Set();
39
+ const registerAction = (action) => {
40
+ actions.add(action);
41
+ action.finally(() => actions.delete(action));
42
+ };
43
+ const useFormStatus = () => {
44
+ return (0, import_context.useContext)(FormContext);
45
+ };
46
+ const useOptimistic = (state, updateState) => {
47
+ const [optimisticState, setOptimisticState] = (0, import_hooks.useState)(state);
48
+ if (actions.size > 0) {
49
+ Promise.all(actions).finally(() => {
50
+ setOptimisticState(state);
51
+ });
52
+ } else {
53
+ setOptimisticState(state);
54
+ }
55
+ const cb = (0, import_hooks.useCallback)((newData) => {
56
+ setOptimisticState((currentState) => updateState(currentState, newData));
57
+ }, []);
58
+ return [optimisticState, cb];
59
+ };
60
+ const useActionState = (fn, initialState, permalink) => {
61
+ const [state, setState] = (0, import_hooks.useState)(initialState);
62
+ const actionState = async (data) => {
63
+ setState(await fn(state, data));
64
+ };
65
+ actionState[import_constants.PERMALINK] = permalink;
66
+ return [state, actionState];
67
+ };
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ FormContext,
71
+ registerAction,
72
+ useActionState,
73
+ useFormStatus,
74
+ useOptimistic
75
+ });
@@ -21,6 +21,7 @@ __export(dom_exports, {
21
21
  Children: () => import_children.Children,
22
22
  ErrorBoundary: () => import_components.ErrorBoundary,
23
23
  Fragment: () => import_jsx_runtime.Fragment,
24
+ StrictMode: () => import_jsx_runtime.Fragment,
24
25
  Suspense: () => import_components.Suspense,
25
26
  cloneElement: () => cloneElement,
26
27
  createContext: () => import_context2.createContext,
@@ -37,16 +38,19 @@ __export(dom_exports, {
37
38
  startTransition: () => import_hooks.startTransition,
38
39
  startViewTransition: () => import_hooks.startViewTransition,
39
40
  use: () => import_hooks.use,
41
+ useActionState: () => import_hooks2.useActionState,
40
42
  useCallback: () => import_hooks.useCallback,
41
43
  useContext: () => import_context.useContext,
42
44
  useDebugValue: () => import_hooks.useDebugValue,
43
45
  useDeferredValue: () => import_hooks.useDeferredValue,
44
46
  useEffect: () => import_hooks.useEffect,
47
+ useFormStatus: () => import_hooks2.useFormStatus,
45
48
  useId: () => import_hooks.useId,
46
49
  useImperativeHandle: () => import_hooks.useImperativeHandle,
47
50
  useInsertionEffect: () => import_hooks.useInsertionEffect,
48
51
  useLayoutEffect: () => import_hooks.useLayoutEffect,
49
52
  useMemo: () => import_hooks.useMemo,
53
+ useOptimistic: () => import_hooks2.useOptimistic,
50
54
  useReducer: () => import_hooks.useReducer,
51
55
  useRef: () => import_hooks.useRef,
52
56
  useState: () => import_hooks.useState,
@@ -60,6 +64,7 @@ var import_base = require("../base");
60
64
  var import_children = require("../children");
61
65
  var import_context = require("../context");
62
66
  var import_hooks = require("../hooks");
67
+ var import_hooks2 = require("./hooks");
63
68
  var import_components = require("./components");
64
69
  var import_context2 = require("./context");
65
70
  var import_jsx_runtime = require("./jsx-runtime");
@@ -110,6 +115,9 @@ var dom_default = {
110
115
  forwardRef: import_hooks.forwardRef,
111
116
  useImperativeHandle: import_hooks.useImperativeHandle,
112
117
  useSyncExternalStore: import_hooks.useSyncExternalStore,
118
+ useFormStatus: import_hooks2.useFormStatus,
119
+ useActionState: import_hooks2.useActionState,
120
+ useOptimistic: import_hooks2.useOptimistic,
113
121
  Suspense: import_components.Suspense,
114
122
  ErrorBoundary: import_components.ErrorBoundary,
115
123
  createContext: import_context2.createContext,
@@ -120,6 +128,7 @@ var dom_default = {
120
128
  cloneElement,
121
129
  Children: import_children.Children,
122
130
  Fragment: import_jsx_runtime.Fragment,
131
+ StrictMode: import_jsx_runtime.Fragment,
123
132
  flushSync: import_render.flushSync,
124
133
  createPortal: import_render.createPortal
125
134
  };
@@ -128,6 +137,7 @@ var dom_default = {
128
137
  Children,
129
138
  ErrorBoundary,
130
139
  Fragment,
140
+ StrictMode,
131
141
  Suspense,
132
142
  cloneElement,
133
143
  createContext,
@@ -143,16 +153,19 @@ var dom_default = {
143
153
  startTransition,
144
154
  startViewTransition,
145
155
  use,
156
+ useActionState,
146
157
  useCallback,
147
158
  useContext,
148
159
  useDebugValue,
149
160
  useDeferredValue,
150
161
  useEffect,
162
+ useFormStatus,
151
163
  useId,
152
164
  useImperativeHandle,
153
165
  useInsertionEffect,
154
166
  useLayoutEffect,
155
167
  useMemo,
168
+ useOptimistic,
156
169
  useReducer,
157
170
  useRef,
158
171
  useState,