@xlsft/grammy-reactive 0.7.34

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 (187) hide show
  1. package/LICENSE +7 -0
  2. package/dist/jsx/index.d.ts +3 -0
  3. package/dist/jsx/index.d.ts.map +1 -0
  4. package/dist/jsx/index.js +2 -0
  5. package/dist/jsx/index.js.map +1 -0
  6. package/dist/jsx/jsx-dev-runtime.d.ts +2 -0
  7. package/dist/jsx/jsx-dev-runtime.d.ts.map +1 -0
  8. package/dist/jsx/jsx-dev-runtime.js +2 -0
  9. package/dist/jsx/jsx-dev-runtime.js.map +1 -0
  10. package/dist/jsx/jsx-runtime.d.ts +2 -0
  11. package/dist/jsx/jsx-runtime.d.ts.map +1 -0
  12. package/dist/jsx/jsx-runtime.js +2 -0
  13. package/dist/jsx/jsx-runtime.js.map +1 -0
  14. package/dist/jsx/runtime/jsx.d.ts +10 -0
  15. package/dist/jsx/runtime/jsx.d.ts.map +1 -0
  16. package/dist/jsx/runtime/jsx.errors.d.ts +4 -0
  17. package/dist/jsx/runtime/jsx.errors.d.ts.map +1 -0
  18. package/dist/jsx/runtime/jsx.errors.js +7 -0
  19. package/dist/jsx/runtime/jsx.errors.js.map +1 -0
  20. package/dist/jsx/runtime/jsx.js +209 -0
  21. package/dist/jsx/runtime/jsx.js.map +1 -0
  22. package/dist/jsx/runtime/jsx.runtime.d.ts +18 -0
  23. package/dist/jsx/runtime/jsx.runtime.d.ts.map +1 -0
  24. package/dist/jsx/runtime/jsx.runtime.js +3 -0
  25. package/dist/jsx/runtime/jsx.runtime.js.map +1 -0
  26. package/dist/lib/helpers/context.helper.d.ts +3 -0
  27. package/dist/lib/helpers/context.helper.d.ts.map +1 -0
  28. package/dist/lib/helpers/index.d.ts +2 -0
  29. package/dist/lib/helpers/index.d.ts.map +1 -0
  30. package/dist/lib/index.d.ts +12 -0
  31. package/dist/lib/index.d.ts.map +1 -0
  32. package/dist/lib/index.js +45 -0
  33. package/dist/lib/index.js.map +1 -0
  34. package/dist/lib/jsx-runtime.d.ts +2 -0
  35. package/dist/lib/jsx-runtime.d.ts.map +1 -0
  36. package/dist/lib/plugin/index.d.ts +4 -0
  37. package/dist/lib/plugin/index.d.ts.map +1 -0
  38. package/dist/lib/plugin/index.js +40 -0
  39. package/dist/lib/plugin/index.js.map +1 -0
  40. package/dist/lib/render/components/Error.d.ts +26 -0
  41. package/dist/lib/render/components/Error.d.ts.map +1 -0
  42. package/dist/lib/render/components/Error.js +25 -0
  43. package/dist/lib/render/components/Error.js.map +1 -0
  44. package/dist/lib/render/message.render.d.ts +40 -0
  45. package/dist/lib/render/message.render.d.ts.map +1 -0
  46. package/dist/lib/render/message.render.js +60 -0
  47. package/dist/lib/render/message.render.js.map +1 -0
  48. package/dist/lib/render/node/fragmemt.render.d.ts +34 -0
  49. package/dist/lib/render/node/fragmemt.render.d.ts.map +1 -0
  50. package/dist/lib/render/node/fragmemt.render.js +56 -0
  51. package/dist/lib/render/node/fragmemt.render.js.map +1 -0
  52. package/dist/lib/render/node/intrinsic.render.d.ts +37 -0
  53. package/dist/lib/render/node/intrinsic.render.d.ts.map +1 -0
  54. package/dist/lib/render/node/intrinsic.render.js +167 -0
  55. package/dist/lib/render/node/intrinsic.render.js.map +1 -0
  56. package/dist/lib/render/node/plain.render.d.ts +27 -0
  57. package/dist/lib/render/node/plain.render.d.ts.map +1 -0
  58. package/dist/lib/render/node/plain.render.js +32 -0
  59. package/dist/lib/render/node/plain.render.js.map +1 -0
  60. package/dist/lib/render/tag.render.d.ts +24 -0
  61. package/dist/lib/render/tag.render.d.ts.map +1 -0
  62. package/dist/lib/render/tag.render.js +27 -0
  63. package/dist/lib/render/tag.render.js.map +1 -0
  64. package/dist/lib/state/create.state.d.ts +8 -0
  65. package/dist/lib/state/create.state.d.ts.map +1 -0
  66. package/dist/lib/state/create.state.js +61 -0
  67. package/dist/lib/state/create.state.js.map +1 -0
  68. package/dist/lib/state/events/onclick.event.d.ts +21 -0
  69. package/dist/lib/state/events/onclick.event.d.ts.map +1 -0
  70. package/dist/lib/state/events/onclick.event.js +36 -0
  71. package/dist/lib/state/events/onclick.event.js.map +1 -0
  72. package/dist/lib/state/hooks/callback.hooks.d.ts +2 -0
  73. package/dist/lib/state/hooks/callback.hooks.d.ts.map +1 -0
  74. package/dist/lib/state/hooks/create.d.ts +7 -0
  75. package/dist/lib/state/hooks/create.d.ts.map +1 -0
  76. package/dist/lib/state/hooks/create.hooks.d.ts +29 -0
  77. package/dist/lib/state/hooks/create.hooks.d.ts.map +1 -0
  78. package/dist/lib/state/hooks/create.hooks.js +38 -0
  79. package/dist/lib/state/hooks/create.hooks.js.map +1 -0
  80. package/dist/lib/state/hooks/effect.hooks.d.ts +5 -0
  81. package/dist/lib/state/hooks/effect.hooks.d.ts.map +1 -0
  82. package/dist/lib/state/hooks/get.hooks.d.ts +25 -0
  83. package/dist/lib/state/hooks/get.hooks.d.ts.map +1 -0
  84. package/dist/lib/state/hooks/get.hooks.js +33 -0
  85. package/dist/lib/state/hooks/get.hooks.js.map +1 -0
  86. package/dist/lib/state/hooks/index.d.ts +7 -0
  87. package/dist/lib/state/hooks/index.d.ts.map +1 -0
  88. package/dist/lib/state/hooks/memo.hooks.d.ts +2 -0
  89. package/dist/lib/state/hooks/memo.hooks.d.ts.map +1 -0
  90. package/dist/lib/state/hooks/reducer.hooks.d.ts +3 -0
  91. package/dist/lib/state/hooks/reducer.hooks.d.ts.map +1 -0
  92. package/dist/lib/state/hooks/ref.hooks.d.ts +4 -0
  93. package/dist/lib/state/hooks/ref.hooks.d.ts.map +1 -0
  94. package/dist/lib/state/hooks/reset.hooks.d.ts +16 -0
  95. package/dist/lib/state/hooks/reset.hooks.d.ts.map +1 -0
  96. package/dist/lib/state/hooks/reset.hooks.js +19 -0
  97. package/dist/lib/state/hooks/reset.hooks.js.map +1 -0
  98. package/dist/lib/state/hooks/set.hooks.d.ts +23 -0
  99. package/dist/lib/state/hooks/set.hooks.d.ts.map +1 -0
  100. package/dist/lib/state/hooks/set.hooks.js +28 -0
  101. package/dist/lib/state/hooks/set.hooks.js.map +1 -0
  102. package/dist/lib/state/hooks/state.hooks.d.ts +50 -0
  103. package/dist/lib/state/hooks/state.hooks.d.ts.map +1 -0
  104. package/dist/lib/state/lifecycle/error.state.d.ts +7 -0
  105. package/dist/lib/state/lifecycle/error.state.d.ts.map +1 -0
  106. package/dist/lib/state/lifecycle/error.state.js +55 -0
  107. package/dist/lib/state/lifecycle/error.state.js.map +1 -0
  108. package/dist/lib/state/lifecycle/mount.state.d.ts +10 -0
  109. package/dist/lib/state/lifecycle/mount.state.d.ts.map +1 -0
  110. package/dist/lib/state/lifecycle/mount.state.js +84 -0
  111. package/dist/lib/state/lifecycle/mount.state.js.map +1 -0
  112. package/dist/lib/state/lifecycle/rerender.state.d.ts +10 -0
  113. package/dist/lib/state/lifecycle/rerender.state.d.ts.map +1 -0
  114. package/dist/lib/state/lifecycle/rerender.state.js +86 -0
  115. package/dist/lib/state/lifecycle/rerender.state.js.map +1 -0
  116. package/dist/lib/state/lifecycle/unmount.state.d.ts +9 -0
  117. package/dist/lib/state/lifecycle/unmount.state.d.ts.map +1 -0
  118. package/dist/lib/state/lifecycle/unmount.state.js +33 -0
  119. package/dist/lib/state/lifecycle/unmount.state.js.map +1 -0
  120. package/dist/types/grammy.types.d.ts +29 -0
  121. package/dist/types/grammy.types.d.ts.map +1 -0
  122. package/dist/types/grammy.types.js +3 -0
  123. package/dist/types/grammy.types.js.map +1 -0
  124. package/dist/types/hooks.types.d.ts +27 -0
  125. package/dist/types/hooks.types.d.ts.map +1 -0
  126. package/dist/types/jsx.types.d.ts +240 -0
  127. package/dist/types/jsx.types.d.ts.map +1 -0
  128. package/dist/types/jsx.types.js +29 -0
  129. package/dist/types/jsx.types.js.map +1 -0
  130. package/dist/types/lib.types.d.ts +80 -0
  131. package/dist/types/lib.types.d.ts.map +1 -0
  132. package/dist/types/lib.types.js +1 -0
  133. package/dist/types/lib.types.js.map +1 -0
  134. package/dist/types/plugin.types.d.ts +81 -0
  135. package/dist/types/plugin.types.d.ts.map +1 -0
  136. package/dist/types/plugin.types.js +1 -0
  137. package/dist/types/plugin.types.js.map +1 -0
  138. package/dist/utils/generateUniqueId.d.ts +29 -0
  139. package/dist/utils/generateUniqueId.d.ts.map +1 -0
  140. package/dist/utils/generateUniqueId.js +41 -0
  141. package/dist/utils/generateUniqueId.js.map +1 -0
  142. package/dist/utils/getEmoji.d.ts +26 -0
  143. package/dist/utils/getEmoji.d.ts.map +1 -0
  144. package/dist/utils/getEmoji.js +33 -0
  145. package/dist/utils/getEmoji.js.map +1 -0
  146. package/dist/utils/getPlainText.d.ts +23 -0
  147. package/dist/utils/getPlainText.d.ts.map +1 -0
  148. package/dist/utils/getPlainText.js +30 -0
  149. package/dist/utils/getPlainText.js.map +1 -0
  150. package/dist/utils/global.d.ts +13 -0
  151. package/dist/utils/global.d.ts.map +1 -0
  152. package/dist/utils/global.js +7 -0
  153. package/dist/utils/global.js.map +1 -0
  154. package/dist/utils/index.d.ts +9 -0
  155. package/dist/utils/index.d.ts.map +1 -0
  156. package/dist/utils/index.js +10 -0
  157. package/dist/utils/index.js.map +1 -0
  158. package/dist/utils/isAbortError.d.ts +2 -0
  159. package/dist/utils/isAbortError.d.ts.map +1 -0
  160. package/dist/utils/isEmoji.d.ts +25 -0
  161. package/dist/utils/isEmoji.d.ts.map +1 -0
  162. package/dist/utils/isEmoji.js +27 -0
  163. package/dist/utils/isEmoji.js.map +1 -0
  164. package/dist/utils/isEqual.d.ts +42 -0
  165. package/dist/utils/isEqual.d.ts.map +1 -0
  166. package/dist/utils/isEqual.js +142 -0
  167. package/dist/utils/isEqual.js.map +1 -0
  168. package/dist/utils/isIntrinsicElement.d.ts +23 -0
  169. package/dist/utils/isIntrinsicElement.d.ts.map +1 -0
  170. package/dist/utils/isIntrinsicElement.js +25 -0
  171. package/dist/utils/isIntrinsicElement.js.map +1 -0
  172. package/dist/utils/isMessageNotFount.d.ts +2 -0
  173. package/dist/utils/isMessageNotFount.d.ts.map +1 -0
  174. package/dist/utils/isUnixTime.d.ts +32 -0
  175. package/dist/utils/isUnixTime.d.ts.map +1 -0
  176. package/dist/utils/isUnixTime.js +38 -0
  177. package/dist/utils/isUnixTime.js.map +1 -0
  178. package/dist/utils/sanitizeHtmlString.d.ts +24 -0
  179. package/dist/utils/sanitizeHtmlString.d.ts.map +1 -0
  180. package/dist/utils/sanitizeHtmlString.js +29 -0
  181. package/dist/utils/sanitizeHtmlString.js.map +1 -0
  182. package/dist/utils/withComponentScope.d.ts +2 -0
  183. package/dist/utils/withComponentScope.d.ts.map +1 -0
  184. package/dist/utils/withRuntime.d.ts +4 -0
  185. package/dist/utils/withRuntime.d.ts.map +1 -0
  186. package/package.json +62 -0
  187. package/readme.md +373 -0
@@ -0,0 +1,36 @@
1
+ import { globalButtonCallbacks } from "~/utils";
2
+ import { createErrorMessageState } from "../lifecycle/error.state";
3
+ /**
4
+ * Dispatches registered reactive button callbacks for callback queries.
5
+ *
6
+ * This internal middleware resolves callback payloads against the
7
+ * button callback registry and executes the matching handler within
8
+ * its owning lifecycle session.
9
+ *
10
+ * If no registered callback exists, middleware control is delegated
11
+ * directly to the next handler.
12
+ *
13
+ * On handler failure, the owning lifecycle session is transitioned
14
+ * into its error fallback state.
15
+ *
16
+ * @param {ReactiveContext} ctx - The reactive Telegram context.
17
+ * @param {NextFunction} next - The next middleware in the pipeline.
18
+ * @returns {Promise<void>}
19
+ */
20
+ export async function createOnClickEvent(ctx, next) {
21
+ if (ctx.callbackQuery?.data === undefined || !globalButtonCallbacks[ctx.callbackQuery.data])
22
+ return await next();
23
+ const id = ctx.callbackQuery.data.match(/^::(.*?)::/)?.[1] ?? null;
24
+ if (!id)
25
+ return await next();
26
+ try {
27
+ await globalButtonCallbacks[ctx.callbackQuery.data](ctx);
28
+ await ctx.answerCallbackQuery();
29
+ await next();
30
+ }
31
+ catch (e) {
32
+ await createErrorMessageState(id, ctx, e);
33
+ console.error(e);
34
+ }
35
+ }
36
+ //# sourceMappingURL=onclick.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onclick.event.js","sourceRoot":"","sources":["../../../../src/lib/state/events/onclick.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAIlE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAoB,EAAE,IAAkB;IAC7E,IAAI,GAAG,CAAC,aAAa,EAAE,IAAI,KAAK,SAAS,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,IAAI,EAAE,CAAA;IAChH,MAAM,EAAE,GAAG,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;IAClE,IAAI,CAAC,EAAE;QAAE,OAAO,MAAM,IAAI,EAAE,CAAA;IAC5B,IAAI,CAAC;QACD,MAAM,qBAAqB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,CAAA;QACzD,MAAM,GAAG,CAAC,mBAAmB,EAAE,CAAA;QAC/B,MAAM,IAAI,EAAE,CAAA;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAU,CAAC,CAAA;QAClD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useCallback<T extends (...args: any[]) => any>(callback: T, deps?: unknown[]): T;
2
+ //# sourceMappingURL=callback.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/callback.hooks.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,CAE/F"}
@@ -0,0 +1,7 @@
1
+ export declare const createHook: () => {
2
+ runtime: import("../../../types/hooks.types").HookRuntime;
3
+ key: string;
4
+ hooks: unknown[];
5
+ index: number;
6
+ };
7
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/create.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;CAOtB,CAAA"}
@@ -0,0 +1,29 @@
1
+ import type { BotEventHooks, BotHandlerLifecycleInstance, BotMessageHandler } from "~/types/lib.types";
2
+ import type { ReactiveContext } from "~/types/plugin.types";
3
+ /**
4
+ * Creates the reactive hook bindings for a mounted message lifecycle session.
5
+ *
6
+ * This internal factory builds the concrete hook runtime implementation
7
+ * used by reactive message handlers, including state persistence and
8
+ * rerender-triggering setters.
9
+ *
10
+ * Hook state is bound to the provided lifecycle session ID and uses
11
+ * stable call-order indexing semantics.
12
+ *
13
+ * @template {ReactiveContext} C
14
+ * @param {string} id - The unique lifecycle session identifier.
15
+ * @param {C} ctx - The bound reactive Telegram context.
16
+ * @param {BotMessageHandler<C>} handler - The reactive handler owning the hooks.
17
+ * @param {BotHandlerLifecycleInstance<C>} state - The active lifecycle controller.
18
+ * @returns {BotEventHooks} The concrete reactive hook bindings.
19
+ *
20
+ * @see {@link BotEventHooks}
21
+ */
22
+ export declare function createHooks<C extends ReactiveContext>({ id, ctx, handler, state, controller }: {
23
+ id: string;
24
+ ctx: C;
25
+ handler: BotMessageHandler<C>;
26
+ state: BotHandlerLifecycleInstance<C>;
27
+ controller?: AbortController;
28
+ }): BotEventHooks;
29
+ //# sourceMappingURL=create.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/create.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGvG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;IAC5F,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,KAAK,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,eAAe,CAAC;CAChC,GAAG,aAAa,CAoBhB"}
@@ -0,0 +1,38 @@
1
+ import { getHook } from "./get.hooks";
2
+ import { setHook } from "./set.hooks";
3
+ /**
4
+ * Creates the reactive hook bindings for a mounted message lifecycle session.
5
+ *
6
+ * This internal factory builds the concrete hook runtime implementation
7
+ * used by reactive message handlers, including state persistence and
8
+ * rerender-triggering setters.
9
+ *
10
+ * Hook state is bound to the provided lifecycle session ID and uses
11
+ * stable call-order indexing semantics.
12
+ *
13
+ * @template {ReactiveContext} C
14
+ * @param {string} id - The unique lifecycle session identifier.
15
+ * @param {C} ctx - The bound reactive Telegram context.
16
+ * @param {BotMessageHandler<C>} handler - The reactive handler owning the hooks.
17
+ * @param {BotHandlerLifecycleInstance<C>} state - The active lifecycle controller.
18
+ * @returns {BotEventHooks} The concrete reactive hook bindings.
19
+ *
20
+ * @see {@link BotEventHooks}
21
+ */
22
+ export function createHooks({ id, ctx, handler, state, controller }) {
23
+ let i = 0;
24
+ function useState(initial) {
25
+ const index = i++;
26
+ const value = getHook(id, index, () => initial);
27
+ const setValue = async (v) => {
28
+ const newValue = typeof v === "function"
29
+ ? v(getHook(id, index, () => initial))
30
+ : v;
31
+ setHook(id, index, newValue);
32
+ await state.rerender();
33
+ };
34
+ return [value, setValue];
35
+ }
36
+ return { useState };
37
+ }
38
+ //# sourceMappingURL=create.hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.hooks.js","sourceRoot":"","sources":["../../../../src/lib/state/hooks/create.hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAA4B,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAM3F;IACG,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,SAAS,QAAQ,CAAI,OAAU;QAC3B,MAAM,KAAK,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,OAAO,CAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;QAEnD,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAuB,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,UAAU;gBACpC,CAAC,CAAE,CAAoB,CAAC,OAAO,CAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;gBAC7D,CAAC,CAAC,CAAC,CAAC;YAER,OAAO,CAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAChC,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAA;QAC1B,CAAC,CAAC;QAEF,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { EffectCleanup } from "~/types/hooks.types";
2
+ export declare function useEffect(effect: () => EffectCleanup | Promise<EffectCleanup>, deps?: unknown[]): void;
3
+ export declare function flushEffects(): Promise<void>;
4
+ export declare function cleanupEffects(): Promise<void>;
5
+ //# sourceMappingURL=effect.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/effect.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAA4B,MAAM,qBAAqB,CAAC;AAInF,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAyBtG;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAclD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAYpD"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Reads a hook value from the lifecycle hook registry.
3
+ *
4
+ * Hook state is addressed by:
5
+ * - lifecycle session ID
6
+ * - stable hook slot index
7
+ *
8
+ * If the slot has not been initialized yet, the provided
9
+ * initializer is executed once and its result is stored
10
+ * for future rerender cycles.
11
+ *
12
+ * This provides React-like lazy first-render initialization
13
+ * semantics for stateful hooks.
14
+ *
15
+ * @template T
16
+ * @param {string} id - The unique lifecycle session identifier.
17
+ * @param {number} index - The stable hook slot index.
18
+ * @param {() => T} initializer - Lazy initializer for the hook value.
19
+ * @returns {T} The persisted hook value.
20
+ *
21
+ * @example
22
+ * const count = getHook(id, 0, () => 0);
23
+ */
24
+ export declare function getHook<T>(id: string, index: number, initializer: () => T): T;
25
+ //# sourceMappingURL=get.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/get.hooks.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ7E"}
@@ -0,0 +1,33 @@
1
+ import { globalHooks } from "~/utils";
2
+ /**
3
+ * Reads a hook value from the lifecycle hook registry.
4
+ *
5
+ * Hook state is addressed by:
6
+ * - lifecycle session ID
7
+ * - stable hook slot index
8
+ *
9
+ * If the slot has not been initialized yet, the provided
10
+ * initializer is executed once and its result is stored
11
+ * for future rerender cycles.
12
+ *
13
+ * This provides React-like lazy first-render initialization
14
+ * semantics for stateful hooks.
15
+ *
16
+ * @template T
17
+ * @param {string} id - The unique lifecycle session identifier.
18
+ * @param {number} index - The stable hook slot index.
19
+ * @param {() => T} initializer - Lazy initializer for the hook value.
20
+ * @returns {T} The persisted hook value.
21
+ *
22
+ * @example
23
+ * const count = getHook(id, 0, () => 0);
24
+ */
25
+ export function getHook(id, index, initializer) {
26
+ if (!globalHooks[id])
27
+ globalHooks[id] = [];
28
+ if (globalHooks[id][index] === undefined) {
29
+ globalHooks[id][index] = initializer();
30
+ }
31
+ return globalHooks[id][index];
32
+ }
33
+ //# sourceMappingURL=get.hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.hooks.js","sourceRoot":"","sources":["../../../../src/lib/state/hooks/get.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,OAAO,CAAI,EAAU,EAAE,KAAa,EAAE,WAAoB;IACtE,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAAE,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IAE3C,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;QACvC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,WAAW,EAAE,CAAC;IAC3C,CAAC;IAED,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,CAAM,CAAC;AACvC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { useState } from "./state.hooks";
2
+ export { useMemo } from "./memo.hooks";
3
+ export { useRef } from "./ref.hooks";
4
+ export { useCallback } from "./callback.hooks";
5
+ export { useReducer } from "./reducer.hooks";
6
+ export { useEffect } from "./effect.hooks";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function useMemo<T>(factory: () => T, deps?: unknown[]): T;
2
+ //# sourceMappingURL=memo.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/memo.hooks.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,CAUhE"}
@@ -0,0 +1,3 @@
1
+ import type { ReducerHook } from "~/types/hooks.types";
2
+ export declare function useReducer<S, A>(reducer: ReducerHook<S, A>, initialState: S): [S, (action: A) => Promise<void>];
3
+ //# sourceMappingURL=reducer.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/reducer.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC3B,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,YAAY,EAAE,CAAC,GAChB,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAQnC"}
@@ -0,0 +1,4 @@
1
+ export declare function useRef<T>(initial: T): {
2
+ current: T;
3
+ };
4
+ //# sourceMappingURL=ref.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/ref.hooks.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;;EAEnC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Clears all stored hook state for a lifecycle session.
3
+ *
4
+ * This fully resets the hook registry bucket associated with the
5
+ * provided session ID by replacing it with a new empty hook array.
6
+ *
7
+ * Primarily used before rerender cycles to restart hook indexing
8
+ * and ensure deterministic React-like hook ordering.
9
+ *
10
+ * @param {string} id - The unique lifecycle session identifier.
11
+ *
12
+ * @example
13
+ * resetHooks(id);
14
+ */
15
+ export declare function resetHooks(id: string): void;
16
+ //# sourceMappingURL=reset.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reset.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/reset.hooks.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,QAEpC"}
@@ -0,0 +1,19 @@
1
+ import { globalHooks } from "~/utils";
2
+ /**
3
+ * Clears all stored hook state for a lifecycle session.
4
+ *
5
+ * This fully resets the hook registry bucket associated with the
6
+ * provided session ID by replacing it with a new empty hook array.
7
+ *
8
+ * Primarily used before rerender cycles to restart hook indexing
9
+ * and ensure deterministic React-like hook ordering.
10
+ *
11
+ * @param {string} id - The unique lifecycle session identifier.
12
+ *
13
+ * @example
14
+ * resetHooks(id);
15
+ */
16
+ export function resetHooks(id) {
17
+ globalHooks[id] = [];
18
+ }
19
+ //# sourceMappingURL=reset.hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reset.hooks.js","sourceRoot":"","sources":["../../../../src/lib/state/hooks/reset.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,EAAU;IACjC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Stores a hook value in the persistent lifecycle hook state registry.
3
+ *
4
+ * Hook state is addressed by:
5
+ * - lifecycle session ID
6
+ * - hook call index
7
+ *
8
+ * If the hook storage bucket for the session does not yet exist,
9
+ * it is created lazily.
10
+ *
11
+ * This function is primarily used by the reactive hook runtime
12
+ * to persist stateful values between rerender cycles.
13
+ *
14
+ * @template T
15
+ * @param {string} id - The unique lifecycle session identifier.
16
+ * @param {number} index - The stable hook slot index.
17
+ * @param {T} value - The hook value to store.
18
+ *
19
+ * @example
20
+ * setHook(id, 0, count);
21
+ */
22
+ export declare function setHook<T>(id: string, index: number, value: T): void;
23
+ //# sourceMappingURL=set.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/set.hooks.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,QAG7D"}
@@ -0,0 +1,28 @@
1
+ import { globalHooks } from "~/utils";
2
+ /**
3
+ * Stores a hook value in the persistent lifecycle hook state registry.
4
+ *
5
+ * Hook state is addressed by:
6
+ * - lifecycle session ID
7
+ * - hook call index
8
+ *
9
+ * If the hook storage bucket for the session does not yet exist,
10
+ * it is created lazily.
11
+ *
12
+ * This function is primarily used by the reactive hook runtime
13
+ * to persist stateful values between rerender cycles.
14
+ *
15
+ * @template T
16
+ * @param {string} id - The unique lifecycle session identifier.
17
+ * @param {number} index - The stable hook slot index.
18
+ * @param {T} value - The hook value to store.
19
+ *
20
+ * @example
21
+ * setHook(id, 0, count);
22
+ */
23
+ export function setHook(id, index, value) {
24
+ if (!globalHooks[id])
25
+ globalHooks[id] = [];
26
+ globalHooks[id][index] = value;
27
+ }
28
+ //# sourceMappingURL=set.hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.hooks.js","sourceRoot":"","sources":["../../../../src/lib/state/hooks/set.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,OAAO,CAAI,EAAU,EAAE,KAAa,EAAE,KAAQ;IAC1D,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAAE,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IAC3C,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AACnC,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Creates a persistent reactive state value for the current message handler.
3
+ *
4
+ * The state value is preserved across rerender cycles for the same
5
+ * mounted message session.
6
+ *
7
+ * The `initial` value is only used during the first render of the
8
+ * hook slot. On subsequent rerenders, the previously stored state
9
+ * value is returned instead.
10
+ *
11
+ * Calling the updater function stores the new value and immediately
12
+ * triggers an asynchronous message rerender.
13
+ *
14
+ * Supports both:
15
+ * - direct value updates
16
+ * - updater callbacks based on the previous state
17
+ *
18
+ * > Hook calls must remain in the same order between rerenders.
19
+ * > Changing the hook call order may corrupt state alignment.
20
+ *
21
+ * @template T
22
+ * @param {T} initial - The initial state value for the first render.
23
+ * @returns {[T, (val: T | ((prev: T) => T)) => Promise<void>]}
24
+ * A tuple containing the current state value and an async updater.
25
+ *
26
+ * @example
27
+ * const [count, setCount] = useState(0);
28
+ *
29
+ * @example
30
+ * await setCount(10);
31
+ *
32
+ * @example
33
+ * await setCount(prev => prev + 1);
34
+ *
35
+ * @example
36
+ * const Counter = defineMessageHandler(async ({ useState }) => {
37
+ * const [count, setCount] = useState(0);
38
+ *
39
+ * return (
40
+ * <button
41
+ * variant="callback"
42
+ * onClick={() => setCount(prev => prev + 1)}
43
+ * >
44
+ * Count: {count}
45
+ * </button>
46
+ * );
47
+ * });
48
+ */
49
+ export declare function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => Promise<void>];
50
+ //# sourceMappingURL=state.hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/hooks/state.hooks.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAe3F"}
@@ -0,0 +1,7 @@
1
+ import type { ReactiveContext } from "~/types/plugin.types";
2
+ export declare function createErrorMessageState<C extends ReactiveContext>({ id, ctx, error }: {
3
+ id: string;
4
+ ctx: C;
5
+ error: Error;
6
+ }): Promise<void>;
7
+ //# sourceMappingURL=error.state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.state.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/lifecycle/error.state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAI3D,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACzF,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,KAAK,CAAC;CAChB,iBA2BA"}
@@ -0,0 +1,55 @@
1
+ import { InternalError } from "~/lib/render/components/Error";
2
+ import { createMessageRender } from "~/lib/render/message.render";
3
+ import { globalCurrentState, globalPreviousState } from "~/utils";
4
+ /**
5
+ * Executes the error lifecycle transition for a mounted message session.
6
+ *
7
+ * When a lifecycle phase fails, this transition replaces the currently
8
+ * mounted Telegram message with an internal fallback error view.
9
+ *
10
+ * The existing mounted message is deleted first, after which the
11
+ * framework renders the built-in `InternalError` component and sends
12
+ * it as the new active lifecycle message.
13
+ *
14
+ * After a successful fallback render, the resulting error message
15
+ * snapshot becomes both the current and previous lifecycle state.
16
+ *
17
+ * If the session is no longer mounted, the operation exits silently.
18
+ *
19
+ * Errors occurring during the fallback rendering process are only
20
+ * logged to the console to avoid recursive error-state loops.
21
+ *
22
+ * @template {ReactiveContext} C
23
+ * @param {string} id - The unique lifecycle session identifier.
24
+ * @param {C} ctx - The bound reactive Telegram context.
25
+ * @param {Error} error - The original lifecycle error to render.
26
+ * @returns {Promise<void>}
27
+ *
28
+ * @example
29
+ * await createErrorMessageState(id, ctx, error);
30
+ */
31
+ export async function createErrorMessageState(id, ctx, error) {
32
+ try {
33
+ if (!globalCurrentState[id])
34
+ return;
35
+ await ctx.deleteMessage();
36
+ const data = await createMessageRender({
37
+ id,
38
+ method: createErrorMessageState.name,
39
+ jsx: await InternalError({ error, id }),
40
+ ctx,
41
+ other: {},
42
+ });
43
+ const message = await ctx.reply(data.text, data.other);
44
+ if (!message)
45
+ throw new Error("Failed to send error message");
46
+ globalCurrentState[id] = message;
47
+ if (!globalCurrentState[id])
48
+ throw new Error("No state rendered");
49
+ globalPreviousState[id] = globalCurrentState[id];
50
+ }
51
+ catch (e) {
52
+ console.error(e);
53
+ }
54
+ }
55
+ //# sourceMappingURL=error.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.state.js","sourceRoot":"","sources":["../../../../src/lib/state/lifecycle/error.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEjE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAA4B,EAAU,EAAE,GAAM,EAAE,KAAY;IACrG,IAAI,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAAE,OAAM;QACnC,MAAM,GAAG,CAAC,aAAa,EAAE,CAAA;QACzB,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC;YACnC,EAAE;YACF,MAAM,EAAE,uBAAuB,CAAC,IAAI;YACpC,GAAG,EAAE,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YACvC,GAAG;YACH,KAAK,EAAE,EAAS;SACnB,CAAC,CAAA;QACF,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACtD,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAC7D,kBAAkB,CAAC,EAAE,CAAC,GAAG,OAAO,CAAA;QAChC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QACjE,mBAAmB,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAA;IACpD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { BotHandlerLifecycleInstance, BotMessageHandler } from "src/types/lib.types";
2
+ import type { ReactiveContext } from "src/types/plugin.types";
3
+ export declare function createMountMessageState<C extends ReactiveContext>({ id, ctx, handler, controller, state }: {
4
+ id: string;
5
+ ctx: C;
6
+ handler: BotMessageHandler<C>;
7
+ controller?: AbortController;
8
+ state: BotHandlerLifecycleInstance<C>;
9
+ }): Promise<void>;
10
+ //# sourceMappingURL=mount.state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.state.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/lifecycle/mount.state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAK7D,wBAAsB,uBAAuB,CAAC,CAAC,SAAS,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IAC9G,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;CACxC,iBA+CA"}
@@ -0,0 +1,84 @@
1
+ import { createMessageRender } from "src/lib/render/message.render";
2
+ import { globalCurrentState, globalPreviousState } from "src/utils";
3
+ import { createErrorMessageState } from "./error.state";
4
+ /**
5
+ * Executes the mount lifecycle transition for a message session.
6
+ *
7
+ * This lifecycle step performs the initial handler execution,
8
+ * renders the JSX tree into a Telegram payload, sends the first
9
+ * message output, and stores the resulting message snapshot as
10
+ * the active lifecycle state.
11
+ *
12
+ * Supported mount flows:
13
+ * - plain text messages via `reply`
14
+ * - media captions with single photo via `replyWithPhoto`
15
+ * - media groups via `replyWithMediaGroup`
16
+ *
17
+ * After a successful mount, the created message snapshot is stored
18
+ * as both the current and previous lifecycle state.
19
+ *
20
+ * Supports both static and reactive handlers. When provided,
21
+ * lifecycle controls and hook bindings are injected into the
22
+ * handler execution context.
23
+ *
24
+ * Any runtime errors during mounting are delegated to the lifecycle
25
+ * error handler before being logged.
26
+ *
27
+ * @template {ReactiveContext} C
28
+ * @param {string} id - The unique lifecycle session identifier.
29
+ * @param {C} ctx - The bound reactive Telegram context.
30
+ * @param {BotStaticMessageHandler<C> | BotMessageHandler<C>} handler
31
+ * The handler used to generate the initial JSX tree.
32
+ * @param {BotHandlerLifecycleInstance<C>} [state]
33
+ * Optional lifecycle controller injected into the handler.
34
+ * @param {ReturnType<typeof createHooks<C>>} [hooks]
35
+ * Optional reactive hook bindings for stateful handlers.
36
+ * @returns {Promise<void>}
37
+ *
38
+ * @example
39
+ * await createMountMessageState(id, ctx, handler, state, hooks);
40
+ */
41
+ export async function createMountMessageState({ id, ctx, handler, state, hooks }) {
42
+ try {
43
+ const element = await handler({ ctx, ...state || {}, ...hooks || {} });
44
+ const data = await createMessageRender({
45
+ id,
46
+ method: createMountMessageState.name,
47
+ jsx: element,
48
+ ctx,
49
+ other: {},
50
+ });
51
+ if (data.view === 'message') {
52
+ const message = await ctx.reply(data.text, data.other);
53
+ if (!message)
54
+ throw new Error("Failed to send message");
55
+ globalCurrentState[id] = message;
56
+ }
57
+ else if (data.view === 'caption') {
58
+ if (data.media.length > 2) {
59
+ const messages = await ctx.replyWithMediaGroup(data.media.slice(0, 10), data.other);
60
+ if (!messages || !messages[0])
61
+ throw new Error("Failed to send media group");
62
+ globalCurrentState[id] = messages[0];
63
+ }
64
+ else if (data.media.length === 1) {
65
+ if (!data.photo)
66
+ throw new Error("No photo provided for caption view");
67
+ const message = await ctx.replyWithPhoto(data.photo, data.other);
68
+ if (!message)
69
+ throw new Error("Failed to send photo");
70
+ globalCurrentState[id] = message;
71
+ }
72
+ else
73
+ throw new TypeError("No media provided for caption view");
74
+ }
75
+ if (!globalCurrentState[id])
76
+ throw new Error("No state rendered");
77
+ globalPreviousState[id] = globalCurrentState[id];
78
+ }
79
+ catch (e) {
80
+ await createErrorMessageState(id, ctx, e);
81
+ console.error(e);
82
+ }
83
+ }
84
+ //# sourceMappingURL=mount.state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.state.js","sourceRoot":"","sources":["../../../../src/lib/state/lifecycle/mount.state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAA4B,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAMxG;IACG,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,EAAE,EAAE,GAAG,KAAK,IAAI,EAAE,EAAS,CAAC,CAAA;QAC7E,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC;YACnC,EAAE;YACF,MAAM,EAAE,uBAAuB,CAAC,IAAI;YACpC,GAAG,EAAE,OAAO;YACZ,GAAG;YACH,KAAK,EAAE,EAAS;SACnB,CAAC,CAAA;QACF,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YACtD,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;YACvD,kBAAkB,CAAC,EAAE,CAAC,GAAG,OAAO,CAAA;QACpC,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;gBACnF,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;gBAC5E,kBAAkB,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;YACxC,CAAC;iBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,KAAK;oBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;gBACtE,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;gBAChE,IAAI,CAAC,OAAO;oBAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBACrD,kBAAkB,CAAC,EAAE,CAAC,GAAG,OAAO,CAAA;YACpC,CAAC;;gBAAM,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QACjE,mBAAmB,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAA;IACpD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAU,CAAC,CAAA;QAClD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { BotHandlerLifecycleInstance, BotMessageHandler } from "~/types/lib.types";
2
+ import type { ReactiveContext } from "~/types/plugin.types";
3
+ export declare function createRerenderMessageState<C extends ReactiveContext>({ id, ctx, handler, controller, state }: {
4
+ id: string;
5
+ ctx: C;
6
+ handler: BotMessageHandler<C>;
7
+ controller?: AbortController;
8
+ state: BotHandlerLifecycleInstance<C>;
9
+ }): Promise<void>;
10
+ //# sourceMappingURL=rerender.state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rerender.state.d.ts","sourceRoot":"","sources":["../../../../src/lib/state/lifecycle/rerender.state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAGvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAM3D,wBAAsB,0BAA0B,CAAC,CAAC,SAAS,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;IACjH,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;CACxC,iBAyEA"}