@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.
- package/LICENSE +7 -0
- package/dist/jsx/index.d.ts +3 -0
- package/dist/jsx/index.d.ts.map +1 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx/jsx-dev-runtime.js +2 -0
- package/dist/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx/jsx-runtime.d.ts +2 -0
- package/dist/jsx/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx/jsx-runtime.js +2 -0
- package/dist/jsx/jsx-runtime.js.map +1 -0
- package/dist/jsx/runtime/jsx.d.ts +10 -0
- package/dist/jsx/runtime/jsx.d.ts.map +1 -0
- package/dist/jsx/runtime/jsx.errors.d.ts +4 -0
- package/dist/jsx/runtime/jsx.errors.d.ts.map +1 -0
- package/dist/jsx/runtime/jsx.errors.js +7 -0
- package/dist/jsx/runtime/jsx.errors.js.map +1 -0
- package/dist/jsx/runtime/jsx.js +209 -0
- package/dist/jsx/runtime/jsx.js.map +1 -0
- package/dist/jsx/runtime/jsx.runtime.d.ts +18 -0
- package/dist/jsx/runtime/jsx.runtime.d.ts.map +1 -0
- package/dist/jsx/runtime/jsx.runtime.js +3 -0
- package/dist/jsx/runtime/jsx.runtime.js.map +1 -0
- package/dist/lib/helpers/context.helper.d.ts +3 -0
- package/dist/lib/helpers/context.helper.d.ts.map +1 -0
- package/dist/lib/helpers/index.d.ts +2 -0
- package/dist/lib/helpers/index.d.ts.map +1 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +45 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/jsx-runtime.d.ts +2 -0
- package/dist/lib/jsx-runtime.d.ts.map +1 -0
- package/dist/lib/plugin/index.d.ts +4 -0
- package/dist/lib/plugin/index.d.ts.map +1 -0
- package/dist/lib/plugin/index.js +40 -0
- package/dist/lib/plugin/index.js.map +1 -0
- package/dist/lib/render/components/Error.d.ts +26 -0
- package/dist/lib/render/components/Error.d.ts.map +1 -0
- package/dist/lib/render/components/Error.js +25 -0
- package/dist/lib/render/components/Error.js.map +1 -0
- package/dist/lib/render/message.render.d.ts +40 -0
- package/dist/lib/render/message.render.d.ts.map +1 -0
- package/dist/lib/render/message.render.js +60 -0
- package/dist/lib/render/message.render.js.map +1 -0
- package/dist/lib/render/node/fragmemt.render.d.ts +34 -0
- package/dist/lib/render/node/fragmemt.render.d.ts.map +1 -0
- package/dist/lib/render/node/fragmemt.render.js +56 -0
- package/dist/lib/render/node/fragmemt.render.js.map +1 -0
- package/dist/lib/render/node/intrinsic.render.d.ts +37 -0
- package/dist/lib/render/node/intrinsic.render.d.ts.map +1 -0
- package/dist/lib/render/node/intrinsic.render.js +167 -0
- package/dist/lib/render/node/intrinsic.render.js.map +1 -0
- package/dist/lib/render/node/plain.render.d.ts +27 -0
- package/dist/lib/render/node/plain.render.d.ts.map +1 -0
- package/dist/lib/render/node/plain.render.js +32 -0
- package/dist/lib/render/node/plain.render.js.map +1 -0
- package/dist/lib/render/tag.render.d.ts +24 -0
- package/dist/lib/render/tag.render.d.ts.map +1 -0
- package/dist/lib/render/tag.render.js +27 -0
- package/dist/lib/render/tag.render.js.map +1 -0
- package/dist/lib/state/create.state.d.ts +8 -0
- package/dist/lib/state/create.state.d.ts.map +1 -0
- package/dist/lib/state/create.state.js +61 -0
- package/dist/lib/state/create.state.js.map +1 -0
- package/dist/lib/state/events/onclick.event.d.ts +21 -0
- package/dist/lib/state/events/onclick.event.d.ts.map +1 -0
- package/dist/lib/state/events/onclick.event.js +36 -0
- package/dist/lib/state/events/onclick.event.js.map +1 -0
- package/dist/lib/state/hooks/callback.hooks.d.ts +2 -0
- package/dist/lib/state/hooks/callback.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/create.d.ts +7 -0
- package/dist/lib/state/hooks/create.d.ts.map +1 -0
- package/dist/lib/state/hooks/create.hooks.d.ts +29 -0
- package/dist/lib/state/hooks/create.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/create.hooks.js +38 -0
- package/dist/lib/state/hooks/create.hooks.js.map +1 -0
- package/dist/lib/state/hooks/effect.hooks.d.ts +5 -0
- package/dist/lib/state/hooks/effect.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/get.hooks.d.ts +25 -0
- package/dist/lib/state/hooks/get.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/get.hooks.js +33 -0
- package/dist/lib/state/hooks/get.hooks.js.map +1 -0
- package/dist/lib/state/hooks/index.d.ts +7 -0
- package/dist/lib/state/hooks/index.d.ts.map +1 -0
- package/dist/lib/state/hooks/memo.hooks.d.ts +2 -0
- package/dist/lib/state/hooks/memo.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/reducer.hooks.d.ts +3 -0
- package/dist/lib/state/hooks/reducer.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/ref.hooks.d.ts +4 -0
- package/dist/lib/state/hooks/ref.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/reset.hooks.d.ts +16 -0
- package/dist/lib/state/hooks/reset.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/reset.hooks.js +19 -0
- package/dist/lib/state/hooks/reset.hooks.js.map +1 -0
- package/dist/lib/state/hooks/set.hooks.d.ts +23 -0
- package/dist/lib/state/hooks/set.hooks.d.ts.map +1 -0
- package/dist/lib/state/hooks/set.hooks.js +28 -0
- package/dist/lib/state/hooks/set.hooks.js.map +1 -0
- package/dist/lib/state/hooks/state.hooks.d.ts +50 -0
- package/dist/lib/state/hooks/state.hooks.d.ts.map +1 -0
- package/dist/lib/state/lifecycle/error.state.d.ts +7 -0
- package/dist/lib/state/lifecycle/error.state.d.ts.map +1 -0
- package/dist/lib/state/lifecycle/error.state.js +55 -0
- package/dist/lib/state/lifecycle/error.state.js.map +1 -0
- package/dist/lib/state/lifecycle/mount.state.d.ts +10 -0
- package/dist/lib/state/lifecycle/mount.state.d.ts.map +1 -0
- package/dist/lib/state/lifecycle/mount.state.js +84 -0
- package/dist/lib/state/lifecycle/mount.state.js.map +1 -0
- package/dist/lib/state/lifecycle/rerender.state.d.ts +10 -0
- package/dist/lib/state/lifecycle/rerender.state.d.ts.map +1 -0
- package/dist/lib/state/lifecycle/rerender.state.js +86 -0
- package/dist/lib/state/lifecycle/rerender.state.js.map +1 -0
- package/dist/lib/state/lifecycle/unmount.state.d.ts +9 -0
- package/dist/lib/state/lifecycle/unmount.state.d.ts.map +1 -0
- package/dist/lib/state/lifecycle/unmount.state.js +33 -0
- package/dist/lib/state/lifecycle/unmount.state.js.map +1 -0
- package/dist/types/grammy.types.d.ts +29 -0
- package/dist/types/grammy.types.d.ts.map +1 -0
- package/dist/types/grammy.types.js +3 -0
- package/dist/types/grammy.types.js.map +1 -0
- package/dist/types/hooks.types.d.ts +27 -0
- package/dist/types/hooks.types.d.ts.map +1 -0
- package/dist/types/jsx.types.d.ts +240 -0
- package/dist/types/jsx.types.d.ts.map +1 -0
- package/dist/types/jsx.types.js +29 -0
- package/dist/types/jsx.types.js.map +1 -0
- package/dist/types/lib.types.d.ts +80 -0
- package/dist/types/lib.types.d.ts.map +1 -0
- package/dist/types/lib.types.js +1 -0
- package/dist/types/lib.types.js.map +1 -0
- package/dist/types/plugin.types.d.ts +81 -0
- package/dist/types/plugin.types.d.ts.map +1 -0
- package/dist/types/plugin.types.js +1 -0
- package/dist/types/plugin.types.js.map +1 -0
- package/dist/utils/generateUniqueId.d.ts +29 -0
- package/dist/utils/generateUniqueId.d.ts.map +1 -0
- package/dist/utils/generateUniqueId.js +41 -0
- package/dist/utils/generateUniqueId.js.map +1 -0
- package/dist/utils/getEmoji.d.ts +26 -0
- package/dist/utils/getEmoji.d.ts.map +1 -0
- package/dist/utils/getEmoji.js +33 -0
- package/dist/utils/getEmoji.js.map +1 -0
- package/dist/utils/getPlainText.d.ts +23 -0
- package/dist/utils/getPlainText.d.ts.map +1 -0
- package/dist/utils/getPlainText.js +30 -0
- package/dist/utils/getPlainText.js.map +1 -0
- package/dist/utils/global.d.ts +13 -0
- package/dist/utils/global.d.ts.map +1 -0
- package/dist/utils/global.js +7 -0
- package/dist/utils/global.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/isAbortError.d.ts +2 -0
- package/dist/utils/isAbortError.d.ts.map +1 -0
- package/dist/utils/isEmoji.d.ts +25 -0
- package/dist/utils/isEmoji.d.ts.map +1 -0
- package/dist/utils/isEmoji.js +27 -0
- package/dist/utils/isEmoji.js.map +1 -0
- package/dist/utils/isEqual.d.ts +42 -0
- package/dist/utils/isEqual.d.ts.map +1 -0
- package/dist/utils/isEqual.js +142 -0
- package/dist/utils/isEqual.js.map +1 -0
- package/dist/utils/isIntrinsicElement.d.ts +23 -0
- package/dist/utils/isIntrinsicElement.d.ts.map +1 -0
- package/dist/utils/isIntrinsicElement.js +25 -0
- package/dist/utils/isIntrinsicElement.js.map +1 -0
- package/dist/utils/isMessageNotFount.d.ts +2 -0
- package/dist/utils/isMessageNotFount.d.ts.map +1 -0
- package/dist/utils/isUnixTime.d.ts +32 -0
- package/dist/utils/isUnixTime.d.ts.map +1 -0
- package/dist/utils/isUnixTime.js +38 -0
- package/dist/utils/isUnixTime.js.map +1 -0
- package/dist/utils/sanitizeHtmlString.d.ts +24 -0
- package/dist/utils/sanitizeHtmlString.d.ts.map +1 -0
- package/dist/utils/sanitizeHtmlString.js +29 -0
- package/dist/utils/sanitizeHtmlString.js.map +1 -0
- package/dist/utils/withComponentScope.d.ts +2 -0
- package/dist/utils/withComponentScope.d.ts.map +1 -0
- package/dist/utils/withRuntime.d.ts +4 -0
- package/dist/utils/withRuntime.d.ts.map +1 -0
- package/package.json +62 -0
- package/readme.md +373 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright © 2026 xlsft
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,UAAU,EACb,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-dev-runtime.js","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","sourceRoot":"","sources":["../../src/jsx/jsx-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IntrinsicElements, FragmentElement, Node, IntrinsicElementOptions, EntityPropsMap, EntityFactoryMap, JSX } from '../../types/jsx.types.ts';
|
|
2
|
+
export declare function createChildren(node: Node): Promise<JSX.Element[]>;
|
|
3
|
+
export declare function createEntity<K extends keyof IntrinsicElements>(tag: K, props: EntityPropsMap[K]): EntityFactoryMap[K];
|
|
4
|
+
export declare function createIntrinsicElement<T extends IntrinsicElementOptions>(options: T): Promise<JSX.Element>;
|
|
5
|
+
export declare function createElement<T extends keyof IntrinsicElements>(type: T, props: IntrinsicElements[T], children: Node): JSX.Element | Promise<JSX.Element>;
|
|
6
|
+
export declare function createFragment(props?: {
|
|
7
|
+
children?: Node;
|
|
8
|
+
}): Promise<FragmentElement>;
|
|
9
|
+
export declare function createRoot(type: any, props: any, key?: any): JSX.Element | Promise<JSX.Element>;
|
|
10
|
+
//# sourceMappingURL=jsx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,iBAAiB,EACjB,eAAe,EACf,IAAI,EACJ,uBAAuB,EAEvB,cAAc,EACd,gBAAgB,EAEhB,GAAG,EACN,MAAM,0BAA0B,CAAA;AAIjC,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAwBvE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAKrH;AAED,wBAAsB,sBAAsB,CAAC,CAAC,SAAS,uBAAuB,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAUhH;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAoB3J,wBAAsB,cAAc,CAAC,KAAK,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAK1F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,sCAO1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.errors.d.ts","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBACxB,OAAO,CAAC,EAAE,MAAM;CAI/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.errors.js","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpC,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC/B,CAAC;CACJ"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { generateUniqueId, isIntrinsicElement } from 'src/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively resolves and normalizes a {@link Node} into a flat array of {@link Element Elements}.
|
|
4
|
+
*
|
|
5
|
+
* This utility is responsible for converting JSX-like child nodes into the
|
|
6
|
+
* internal render tree representation used by the message builder.
|
|
7
|
+
*
|
|
8
|
+
* Supported normalization rules:
|
|
9
|
+
* - `null`, `undefined`, and `boolean` values are ignored
|
|
10
|
+
* - `string` and `number` values are converted into {@link PlainElement}
|
|
11
|
+
* - nested `Node[]` arrays are recursively resolved and flattened
|
|
12
|
+
* - existing {@link Element} objects are preserved as-is
|
|
13
|
+
* - promised nodes are awaited before normalization
|
|
14
|
+
*
|
|
15
|
+
* This makes the function suitable for processing `children` values from
|
|
16
|
+
* intrinsic elements, fragments, and async components.
|
|
17
|
+
*
|
|
18
|
+
* @async
|
|
19
|
+
* @param {Node} node - A render node, nested node list, or promised node value.
|
|
20
|
+
* @returns {Promise<JSX.Element[]>} A promise that resolves to a flat normalized array
|
|
21
|
+
* of renderable elements.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const children = await createChildren([
|
|
25
|
+
* "Hello",
|
|
26
|
+
* ["world", 123],
|
|
27
|
+
* null,
|
|
28
|
+
* ]);
|
|
29
|
+
*
|
|
30
|
+
* // [
|
|
31
|
+
* // { type: "plain", value: "Hello" },
|
|
32
|
+
* // { type: "plain", value: "world" },
|
|
33
|
+
* // { type: "plain", value: 123 }
|
|
34
|
+
* // ]
|
|
35
|
+
*/
|
|
36
|
+
export async function createChildren(node) {
|
|
37
|
+
const resolved = await node;
|
|
38
|
+
if (resolved == null || typeof resolved === "boolean")
|
|
39
|
+
return [];
|
|
40
|
+
const type = typeof resolved;
|
|
41
|
+
if (type === "string" || type === "number") {
|
|
42
|
+
return [{ type: "plain", value: resolved }];
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(resolved)) {
|
|
45
|
+
const children = await Promise.all(resolved.map(createChildren));
|
|
46
|
+
return children.flat();
|
|
47
|
+
}
|
|
48
|
+
return [resolved];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a strongly typed entity descriptor for the given intrinsic tag.
|
|
52
|
+
*
|
|
53
|
+
* This is a low-level factory used to convert an intrinsic JSX tag and its
|
|
54
|
+
* normalized props into an internal {@link Entity} representation.
|
|
55
|
+
*
|
|
56
|
+
* The returned entity type is inferred from the provided `tag`, ensuring
|
|
57
|
+
* that the resulting shape matches the corresponding entry in
|
|
58
|
+
* `IntrinsicElements`.
|
|
59
|
+
*
|
|
60
|
+
* Commonly used when transforming JSX nodes into {@link TextElement}
|
|
61
|
+
* metadata entities such as links, formatting marks, timestamps, emojis,
|
|
62
|
+
* buttons, and other supported Telegram entities.
|
|
63
|
+
*
|
|
64
|
+
* @template {keyof IntrinsicElements} K
|
|
65
|
+
* @param {K} tag - The intrinsic element tag name.
|
|
66
|
+
* @param {EntityPropsMap[K]} props - The normalized props associated with the tag.
|
|
67
|
+
* @returns {EntityFactoryMap[K]} A strongly typed entity object for the given tag.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const link = createEntity("a", { href: "https://example.com" });
|
|
71
|
+
* // { type: "a", href: "https://example.com" }
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const emoji = createEntity("emoji", { id: "123456789" });
|
|
75
|
+
* // { type: "emoji", id: "123456789" }
|
|
76
|
+
*/
|
|
77
|
+
export function createEntity(tag, props) {
|
|
78
|
+
return {
|
|
79
|
+
type: tag,
|
|
80
|
+
...props,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates an intrinsic {@link TextElement} from a JSX-like intrinsic node definition.
|
|
85
|
+
*
|
|
86
|
+
* This function validates the provided intrinsic tag, extracts and normalizes
|
|
87
|
+
* its `children`, converts the remaining props into a strongly typed
|
|
88
|
+
* {@link Entity}, and returns the final internal render-tree node.
|
|
89
|
+
*
|
|
90
|
+
* It acts as the main transformation step for intrinsic JSX tags such as
|
|
91
|
+
* formatting entities (`b`, `i`, `a`, `code`), media nodes (`img`, `preview`),
|
|
92
|
+
* structural blocks (`blockquote`, `p`, `h`), and interactive elements
|
|
93
|
+
* like inline keyboard buttons.
|
|
94
|
+
*
|
|
95
|
+
* Children are recursively resolved through {@link createChildren}, which
|
|
96
|
+
* allows support for nested arrays, async nodes, primitive values, and
|
|
97
|
+
* already constructed elements.
|
|
98
|
+
*
|
|
99
|
+
* @template {IntrinsicElementOptions} T
|
|
100
|
+
* @async
|
|
101
|
+
* @param {T} options - Intrinsic element creation options including the tag and its props.
|
|
102
|
+
* @returns {Promise<JSX.Element>} A promise that resolves to the normalized intrinsic text element.
|
|
103
|
+
*
|
|
104
|
+
* @throws {Error} Throws if the provided tag is not a supported intrinsic element.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const element = await createIntrinsicElement({
|
|
108
|
+
* tag: "a",
|
|
109
|
+
* props: {
|
|
110
|
+
* href: "https://example.com",
|
|
111
|
+
* children: "Open link",
|
|
112
|
+
* },
|
|
113
|
+
* });
|
|
114
|
+
*/
|
|
115
|
+
export async function createIntrinsicElement(options) {
|
|
116
|
+
if (!isIntrinsicElement(options.tag))
|
|
117
|
+
throw new Error(`Invalid intrinsic element: ${options.tag}`);
|
|
118
|
+
const children = "children" in options.props ? options.props.children ?? [] : [];
|
|
119
|
+
const { children: _, ...props } = options.props;
|
|
120
|
+
return {
|
|
121
|
+
id: generateUniqueId(),
|
|
122
|
+
type: "intrinsic",
|
|
123
|
+
entity: createEntity(options.tag, props),
|
|
124
|
+
children: await createChildren(children),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function createElement(type, props, children) {
|
|
128
|
+
const intrinsicElementProps = children === undefined ? props : { ...props, children };
|
|
129
|
+
if (typeof type === "string") {
|
|
130
|
+
if (!isIntrinsicElement(type))
|
|
131
|
+
throw new Error(`Invalid JSX component: ${type}.`);
|
|
132
|
+
return createIntrinsicElement({ tag: type, props: intrinsicElementProps });
|
|
133
|
+
}
|
|
134
|
+
if (typeof type === "function")
|
|
135
|
+
return type(intrinsicElementProps);
|
|
136
|
+
throw new Error(`Invalid JSX component: ${type}.`);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates a JSX fragment node by normalizing its children into a
|
|
140
|
+
* {@link FragmentElement}.
|
|
141
|
+
*
|
|
142
|
+
* Fragments are used to group multiple child nodes without introducing
|
|
143
|
+
* an additional intrinsic entity wrapper in the render tree.
|
|
144
|
+
*
|
|
145
|
+
* This makes the function suitable as the runtime target for JSX fragment
|
|
146
|
+
* syntax (`<>...</>`), allowing multiple sibling nodes to be returned
|
|
147
|
+
* from components or embedded inline in intrinsic children.
|
|
148
|
+
*
|
|
149
|
+
* All provided children are recursively resolved and flattened through
|
|
150
|
+
* {@link createChildren}, which supports async nodes, nested arrays,
|
|
151
|
+
* primitive values, and existing elements.
|
|
152
|
+
*
|
|
153
|
+
* @async
|
|
154
|
+
* @param {{ children?: Node }} [props] - Optional fragment props containing child nodes.
|
|
155
|
+
* @returns {Promise<FragmentElement>} A promise that resolves to the normalized fragment node.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const fragment = await createFragment({
|
|
159
|
+
* children: ["Hello", " ", "world"],
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* // {
|
|
163
|
+
* // type: "fragment",
|
|
164
|
+
* // children: [
|
|
165
|
+
* // { type: "plain", value: "Hello" },
|
|
166
|
+
* // { type: "plain", value: " " },
|
|
167
|
+
* // { type: "plain", value: "world" }
|
|
168
|
+
* // ]
|
|
169
|
+
* // }
|
|
170
|
+
*/
|
|
171
|
+
export async function createFragment(props) {
|
|
172
|
+
return {
|
|
173
|
+
type: 'fragment',
|
|
174
|
+
children: await createChildren(props?.children ?? []),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates a root JSX runtime node from compiler-transformed JSX input.
|
|
179
|
+
*
|
|
180
|
+
* This function serves as the top-level JSX factory entry used by modern
|
|
181
|
+
* JSX transforms, where `type`, `props`, and an optional `key` are passed
|
|
182
|
+
* directly by the compiler.
|
|
183
|
+
*
|
|
184
|
+
* It normalizes missing props, preserves the optional `key` field when
|
|
185
|
+
* provided, extracts `children` from props, and delegates actual element
|
|
186
|
+
* creation to {@link createElement}.
|
|
187
|
+
*
|
|
188
|
+
* This makes it suitable as the runtime target for `jsx`, `jsxs`,
|
|
189
|
+
* or similar compiler-generated calls in a custom JSX runtime.
|
|
190
|
+
*
|
|
191
|
+
* @param {any} type - The intrinsic tag or functional component.
|
|
192
|
+
* @param {any} props - The JSX props object generated by the compiler.
|
|
193
|
+
* @param {any} [key] - Optional JSX key passed by the transform.
|
|
194
|
+
* @returns {JSX.Element | Promise<JSX.Element>} The created render-tree node.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const node = createRoot("b", { children: "Hello" });
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* const node = createRoot(MyComponent, { value: 42 }, "item-1");
|
|
201
|
+
*/
|
|
202
|
+
export function createRoot(type, props, key) {
|
|
203
|
+
props ??= {};
|
|
204
|
+
const children = props.children;
|
|
205
|
+
if (key !== undefined)
|
|
206
|
+
props.key = key;
|
|
207
|
+
return createElement(type, props, children);
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=jsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.js","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Element as _Element, IntrinsicElements as _IntrinsicElements, Component as _Component } from '~/types/jsx.types.ts';
|
|
2
|
+
import { createRoot, createFragment } from './jsx.ts';
|
|
3
|
+
export { createFragment as Fragment, createRoot as jsx, createRoot as jsxDEV, createRoot as jsxs, };
|
|
4
|
+
export declare namespace JSX {
|
|
5
|
+
type Element = _Element | Promise<_Element>;
|
|
6
|
+
type ElementType = keyof _IntrinsicElements | _Component;
|
|
7
|
+
interface ElementAttributesProperty {
|
|
8
|
+
props: {};
|
|
9
|
+
}
|
|
10
|
+
interface ElementChildrenAttribute {
|
|
11
|
+
children: {};
|
|
12
|
+
}
|
|
13
|
+
interface IntrinsicElements extends _IntrinsicElements {
|
|
14
|
+
}
|
|
15
|
+
interface IntrinsicAttributes {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=jsx.runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.runtime.d.ts","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,OAAO,IAAI,QAAQ,EACnB,iBAAiB,IAAI,kBAAkB,EACvC,SAAS,IAAI,UAAU,EAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EACH,cAAc,IAAI,QAAQ,EAC1B,UAAU,IAAI,GAAG,EACjB,UAAU,IAAI,MAAM,EACpB,UAAU,IAAI,IAAI,GACrB,CAAA;AAED,yBAAiB,GAAG,CAAC;IACjB,KAAY,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClD,KAAY,WAAW,GAAG,MAAM,kBAAkB,GAAG,UAAU,CAAA;IAC/D,UAAiB,yBAAyB;QAAG,KAAK,EAAE,EAAE,CAAA;KAAE;IACxD,UAAiB,wBAAwB;QAAG,QAAQ,EAAE,EAAE,CAAA;KAAE;IAC1D,UAAiB,iBAAkB,SAAQ,kBAAkB;KAAG;IAChE,UAAiB,mBAAmB;KAAG;CAC1C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.runtime.js","sourceRoot":"","sources":["../../../src/jsx/runtime/jsx.runtime.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EACH,cAAc,IAAI,QAAQ,EAC1B,UAAU,IAAI,GAAG,EACjB,UAAU,IAAI,MAAM,EACpB,UAAU,IAAI,IAAI,GACrB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.helper.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/context.helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,KAAK,CAAC,CAQ3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type BotMessageHandler } from "~/types/lib.types";
|
|
2
|
+
import { reactive } from "./plugin";
|
|
3
|
+
import type { ReactiveContext } from "~/types/plugin.types";
|
|
4
|
+
export declare function defineMessageHandler<C extends ReactiveContext>(handler: BotMessageHandler<C>): (ctx: C) => Promise<void>;
|
|
5
|
+
export { reactive };
|
|
6
|
+
export { createMessageRender } from "./render/message.render";
|
|
7
|
+
export * from "./state/hooks";
|
|
8
|
+
export * from "./helpers";
|
|
9
|
+
export type { JSX } from "../jsx/runtime/jsx.runtime";
|
|
10
|
+
export type { PluginOptions as Options, ReactiveContextFlavor as ReactiveFlavor } from "../types/plugin.types";
|
|
11
|
+
export type { BotMessageHandler as MessageHandler } from '../types/lib.types';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,eAAe,EAC1D,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAEf,KAAK,CAAC,mBAUvB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA;AACnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,YAAY,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAA;AACrD,YAAY,EACR,aAAa,IAAI,OAAO,EACxB,qBAAqB,IAAI,cAAc,EAC1C,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EACR,iBAAiB,IAAI,cAAc,EACtC,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {} from "~/types/lib.types";
|
|
2
|
+
import { jsx } from "./plugin";
|
|
3
|
+
import { generateUniqueId } from "~/utils";
|
|
4
|
+
import { createMessageState } from "./state/create.state";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a reactive message handler executor.
|
|
7
|
+
*
|
|
8
|
+
* Reactive handlers extend the static lifecycle model with
|
|
9
|
+
* hook-based state utilities such as `useState`, enabling
|
|
10
|
+
* dynamic rerendering flows and interactive message updates.
|
|
11
|
+
*
|
|
12
|
+
* This helper initializes:
|
|
13
|
+
* - a unique message lifecycle session
|
|
14
|
+
* - persistent reactive state storage
|
|
15
|
+
* - hook bindings
|
|
16
|
+
* - the initial mounted render
|
|
17
|
+
*
|
|
18
|
+
* Best suited for interactive Telegram UIs, stateful menus,
|
|
19
|
+
* pagination, toggles, and multi-step flows.
|
|
20
|
+
*
|
|
21
|
+
* @template {ReactiveContext} C
|
|
22
|
+
* @param {BotMessageHandler<C>} handler
|
|
23
|
+
* The reactive JSX message handler definition.
|
|
24
|
+
* @returns {(ctx: C) => Promise<void>}
|
|
25
|
+
* An async context-bound executor that mounts the reactive lifecycle.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* export default defineMessageHandler(async ({ useState }) => {
|
|
29
|
+
* const [count, setCount] = useState(0);
|
|
30
|
+
* return <>
|
|
31
|
+
* <button variant="callback" onClick={() => setCount(count + 1)}>+</button>
|
|
32
|
+
* <button variant="callback" onClick={() => setCount(count - 1)}>-</button>
|
|
33
|
+
* </>;
|
|
34
|
+
* });
|
|
35
|
+
*/
|
|
36
|
+
export function defineMessageHandler(handler) {
|
|
37
|
+
return async (ctx) => {
|
|
38
|
+
const id = generateUniqueId();
|
|
39
|
+
const state = createMessageState({ id, ctx, handler });
|
|
40
|
+
await state.mount();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export { jsx as jsxPlugin };
|
|
44
|
+
export { createMessageRender } from "./render/message.render";
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,oBAAoB,CAChC,OAA6B;IAE7B,OAAO,KAAK,EAAE,GAAM,EAAE,EAAE;QACpB,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAA;QAC7B,MAAM,KAAK,GAAG,kBAAkB,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;QACtD,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC,CAAA;AACL,CAAC;AAED,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/lib/jsx-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MiddlewareFn } from "~/types/grammy.types";
|
|
2
|
+
import type { PluginOptions, ReactiveContext, ReactiveContextFlavor } from "~/types/plugin.types";
|
|
3
|
+
export declare function reactive<C extends ReactiveContext>(options?: PluginOptions<C>): MiddlewareFn<ReactiveContextFlavor<C>>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAiB,MAAM,sBAAsB,CAAC;AAOjH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,eAAe,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CA8CtH"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createOnClickEvent } from "../state/events/onclick.event";
|
|
2
|
+
import { generateUniqueId } from "~/utils";
|
|
3
|
+
import { createMessageRender } from "../render/message.render";
|
|
4
|
+
import { JSXParseError } from "~/jsx/runtime/jsx.errors";
|
|
5
|
+
export function jsx({ bot }) {
|
|
6
|
+
return async (ctx, next) => {
|
|
7
|
+
bot.on("callback_query:data", createOnClickEvent);
|
|
8
|
+
ctx.reply = async function reply(content, other, signal) {
|
|
9
|
+
const dispatch = async (content) => {
|
|
10
|
+
if (!ctx.chat)
|
|
11
|
+
throw new Error("Cannot reply to a message without a chat");
|
|
12
|
+
return await ctx.api.sendMessage(ctx.chat.id, content, {
|
|
13
|
+
business_connection_id: ctx.businessConnectionId,
|
|
14
|
+
...(ctx.msg?.is_topic_message
|
|
15
|
+
? { message_thread_id: ctx.msg.message_thread_id }
|
|
16
|
+
: {}),
|
|
17
|
+
direct_messages_topic_id: ctx.msg?.direct_messages_topic?.topic_id,
|
|
18
|
+
...other,
|
|
19
|
+
}, signal);
|
|
20
|
+
};
|
|
21
|
+
if (typeof content === "string") {
|
|
22
|
+
return await dispatch(content);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const id = generateUniqueId();
|
|
26
|
+
const message = await createMessageRender({
|
|
27
|
+
method: "repl", id,
|
|
28
|
+
jsx: content, ctx, other: {},
|
|
29
|
+
unallowed: ['img']
|
|
30
|
+
});
|
|
31
|
+
other = message.other;
|
|
32
|
+
if (!message)
|
|
33
|
+
throw new JSXParseError("No message rendered");
|
|
34
|
+
return await dispatch(message.text);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
await next();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,UAAU,GAAG,CAA4B,EAAE,GAAG,EAAoB;IACpE,OAAO,KAAK,EAAE,GAA6B,EAAE,IAAkB,EAAE,EAAE;QAE/D,GAAG,CAAC,EAAE,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAA;QAEjD,GAAG,CAAC,KAAK,GAAG,KAAK,UAAU,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM;YACnD,MAAM,QAAQ,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;gBACvC,IAAI,CAAC,GAAG,CAAC,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;gBAC1E,OAAO,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE;oBACnD,sBAAsB,EAAE,GAAG,CAAC,oBAAoB;oBAChD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,gBAAgB;wBACzB,CAAC,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE;wBAClD,CAAC,CAAC,EAAE,CAAC;oBACT,wBAAwB,EAAE,GAAG,CAAC,GAAG,EAAE,qBAAqB,EAAE,QAAQ;oBAClE,GAAG,KAAK;iBACX,EAAE,MAAa,CAAC,CAAA;YACrB,CAAC,CAAA;YACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAA;YAClC,CAAC;iBAAM,CAAC;gBACJ,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAA;gBAC7B,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAEvC;oBACE,MAAM,EAAE,MAAM,EAAE,EAAE;oBAClB,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;oBAC5B,SAAS,EAAE,CAAC,KAAK,CAAC;iBACrB,CAAC,CAAA;gBACF,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;gBACrB,IAAI,CAAC,OAAO;oBAAE,MAAM,IAAI,aAAa,CAAC,qBAAqB,CAAC,CAAA;gBAC5D,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACvC,CAAC;QACL,CAAC,CAAC;QACF,MAAM,IAAI,EAAE,CAAC;IACjB,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactiveContext } from "~/types/plugin.types";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the internal fallback error UI for failed lifecycle sessions.
|
|
4
|
+
*
|
|
5
|
+
* This diagnostic component is used by the lifecycle error boundary
|
|
6
|
+
* to replace a failed reactive message with a developer-friendly
|
|
7
|
+
* formatted error report.
|
|
8
|
+
*
|
|
9
|
+
* The rendered output includes:
|
|
10
|
+
* - exception type
|
|
11
|
+
* - error message
|
|
12
|
+
* - stack trace
|
|
13
|
+
* - lifecycle request ID
|
|
14
|
+
*
|
|
15
|
+
* The request ID helps correlate the rendered fallback message
|
|
16
|
+
* with the owning lifecycle session and callback flow.
|
|
17
|
+
*
|
|
18
|
+
* @param {{ error: Error; id: string }} props - Error display payload.
|
|
19
|
+
* @returns {JSX.Element} The formatted internal error message view.
|
|
20
|
+
*/
|
|
21
|
+
export declare function InternalError<C extends ReactiveContext>({ error, id, retry }: {
|
|
22
|
+
error: Error;
|
|
23
|
+
id?: string;
|
|
24
|
+
retry?: () => Promise<void>;
|
|
25
|
+
}): import("src/jsx/jsx-runtime").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/components/Error.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,eAAe,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAAE,6CAuBzI"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "src/jsx/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the internal fallback error UI for failed lifecycle sessions.
|
|
4
|
+
*
|
|
5
|
+
* This diagnostic component is used by the lifecycle error boundary
|
|
6
|
+
* to replace a failed reactive message with a developer-friendly
|
|
7
|
+
* formatted error report.
|
|
8
|
+
*
|
|
9
|
+
* The rendered output includes:
|
|
10
|
+
* - exception type
|
|
11
|
+
* - error message
|
|
12
|
+
* - stack trace
|
|
13
|
+
* - lifecycle request ID
|
|
14
|
+
*
|
|
15
|
+
* The request ID helps correlate the rendered fallback message
|
|
16
|
+
* with the owning lifecycle session and callback flow.
|
|
17
|
+
*
|
|
18
|
+
* @param {{ error: Error; id: string }} props - Error display payload.
|
|
19
|
+
* @returns {JSX.Element} The formatted internal error message view.
|
|
20
|
+
*/
|
|
21
|
+
export function InternalError({ error, id }) {
|
|
22
|
+
const stack = error.stack || `${error.name}: ${error.message}\n at unknown`;
|
|
23
|
+
return _jsxs(_Fragment, { children: [_jsx("h", { children: "\u26A0\uFE0F Internal Error" }), _jsxs("blockquote", { expandable: true, children: [_jsx("b", { children: "Exception:" }), " ", _jsx("code", { children: error.name || "Error" }), _jsx("br", {}), _jsx("b", { children: "Message:" }), " ", _jsx("i", { children: error.message || "Unknown error" })] }), _jsx("br", {}), _jsx("br", {}), _jsx("h", { children: "\uD83D\uDCCD Stack Trace" }), _jsx("codeblock", { lang: "ts", children: stack }), _jsx("br", {}), _jsx("br", {}), _jsxs("i", { children: ["Request ID: ", _jsx("code", { children: id })] })] });
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=Error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.js","sourceRoot":"","sources":["../../../../src/lib/render/components/Error.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE,EAAgC;IACrE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,kBAAkB,CAAA;IAC9E,OAAO,8BACH,sDAAwB,EACxB,sBAAY,UAAU,mBAClB,qCAAiB,OAAC,yBAAO,KAAK,CAAC,IAAI,IAAI,OAAO,GAAQ,EACtD,cAAM,EACN,mCAAe,OAAC,sBAAI,KAAK,CAAC,OAAO,IAAI,eAAe,GAAK,IAChD,EAAA,cAAK,EAAA,cAAK,EACvB,mDAAqB,EACrB,oBAAW,IAAI,EAAC,IAAI,YACf,KAAK,GACE,EAAA,cAAK,EAAA,cAAK,EACtB,wCAAe,yBAAO,EAAE,GAAQ,IAAI,IACrC,CAAA;AACP,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReactiveContext } from "~/types/plugin.types";
|
|
2
|
+
import type { RenderedMessage, RenderedMessageOptions } from "~/types/lib.types";
|
|
3
|
+
import type { OtherContexted } from "~/types/grammy.types";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a JSX message tree into a Telegram-compatible payload.
|
|
6
|
+
*
|
|
7
|
+
* This is the root render pipeline entry responsible for converting
|
|
8
|
+
* a resolved JSX tree into:
|
|
9
|
+
* - HTML text
|
|
10
|
+
* - Telegram send options
|
|
11
|
+
* - optional media attachments
|
|
12
|
+
* - resolved render view mode
|
|
13
|
+
*
|
|
14
|
+
* The renderer automatically enforces `parse_mode: "HTML"` and
|
|
15
|
+
* converts collected image attachments into Telegram photo media.
|
|
16
|
+
*
|
|
17
|
+
* If at least one media attachment is present, the resulting
|
|
18
|
+
* render view is resolved as `"caption"`. Otherwise, it is
|
|
19
|
+
* rendered as a plain `"message"`.
|
|
20
|
+
*
|
|
21
|
+
* The final text output is automatically trimmed to Telegram's character message limit.
|
|
22
|
+
* If view is `"message"`, the text is trimmed to 4096 characters.
|
|
23
|
+
* If view is `"caption"`, the text is trimmed to 1024 characters.
|
|
24
|
+
*
|
|
25
|
+
* @template {ReactiveContext} C
|
|
26
|
+
* @template {OtherContexted<"sendMessage", "text" | "chat_id" | "parse_mode">} Other
|
|
27
|
+
* @param {RenderedMessageOptions<C, Other>} options - Root render options.
|
|
28
|
+
* @returns {RenderedMessage<Other>} The fully rendered Telegram payload.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const result = await createMessageRender({
|
|
32
|
+
* id,
|
|
33
|
+
* method: "replyWithJSX",
|
|
34
|
+
* jsx: <b>Hello</b>,
|
|
35
|
+
* ctx,
|
|
36
|
+
* other: {},
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
export declare function createMessageRender<C extends ReactiveContext, Other extends OtherContexted<"sendMessage", "text" | "chat_id" | "parse_mode">>(options: RenderedMessageOptions<C, Other>): RenderedMessage<Other>;
|
|
40
|
+
//# sourceMappingURL=message.render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.render.d.ts","sourceRoot":"","sources":["../../../src/lib/render/message.render.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,SAAS,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC,EAC/I,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,KAAK,CAAC,GAC1C,eAAe,CAAC,KAAK,CAAC,CA4BxB"}
|