@elefunc/send 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/tui/app.ts +1 -1
- package/src/tui/rezi-checkbox-click.ts +26 -7
package/package.json
CHANGED
package/src/tui/app.ts
CHANGED
|
@@ -910,7 +910,7 @@ export const withAcceptedDraftInput = (state: TuiState, draftInput: string, file
|
|
|
910
910
|
}, notice)
|
|
911
911
|
|
|
912
912
|
export const startTui = async (initialConfig: SessionConfig, showEvents = false) => {
|
|
913
|
-
installCheckboxClickPatch()
|
|
913
|
+
await installCheckboxClickPatch()
|
|
914
914
|
const initialState = createInitialTuiState(initialConfig, showEvents)
|
|
915
915
|
const app = createNodeApp<TuiState>({ initialState })
|
|
916
916
|
let state = initialState
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { WidgetRenderer } from "../../node_modules/@rezi-ui/core/dist/app/widgetRenderer.js"
|
|
2
|
-
|
|
3
1
|
const PATCH_FLAG = Symbol.for("send.rezi.checkboxClickPatchInstalled")
|
|
4
2
|
const CLICKABLE_CHECKBOX_IDS = Symbol.for("send.rezi.checkboxClickPressableIds")
|
|
5
3
|
|
|
@@ -15,10 +13,31 @@ type CheckboxRuntime = {
|
|
|
15
13
|
[CLICKABLE_CHECKBOX_IDS]?: Set<string>
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
type PatchedWidgetRendererClass =
|
|
16
|
+
type PatchedWidgetRendererClass = {
|
|
17
|
+
prototype: {
|
|
18
|
+
routeEngineEvent: (event: unknown) => unknown
|
|
19
|
+
}
|
|
19
20
|
[PATCH_FLAG]?: boolean
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
type WidgetRendererModule = {
|
|
24
|
+
WidgetRenderer: PatchedWidgetRendererClass
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let widgetRendererPromise: Promise<PatchedWidgetRendererClass> | null = null
|
|
28
|
+
|
|
29
|
+
const loadWidgetRenderer = () => {
|
|
30
|
+
if (widgetRendererPromise) return widgetRendererPromise
|
|
31
|
+
widgetRendererPromise = (async () => {
|
|
32
|
+
const coreIndexUrl = await import.meta.resolve("@rezi-ui/core")
|
|
33
|
+
const widgetRendererUrl = new URL("./app/widgetRenderer.js", coreIndexUrl).href
|
|
34
|
+
const module = await import(widgetRendererUrl) as Partial<WidgetRendererModule>
|
|
35
|
+
if (!module.WidgetRenderer) throw new Error(`Unable to load WidgetRenderer from ${widgetRendererUrl}`)
|
|
36
|
+
return module.WidgetRenderer
|
|
37
|
+
})()
|
|
38
|
+
return widgetRendererPromise
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
const syncClickableCheckboxIds = (renderer: CheckboxRuntime) => {
|
|
23
42
|
const nextIds = new Set<string>()
|
|
24
43
|
for (const [id, checkbox] of renderer.checkboxById) {
|
|
@@ -33,14 +52,14 @@ const syncClickableCheckboxIds = (renderer: CheckboxRuntime) => {
|
|
|
33
52
|
renderer[CLICKABLE_CHECKBOX_IDS] = nextIds
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
export const installCheckboxClickPatch = () => {
|
|
37
|
-
const WidgetRendererClass =
|
|
55
|
+
export const installCheckboxClickPatch = async () => {
|
|
56
|
+
const WidgetRendererClass = await loadWidgetRenderer()
|
|
38
57
|
if (WidgetRendererClass[PATCH_FLAG]) return
|
|
39
58
|
WidgetRendererClass[PATCH_FLAG] = true
|
|
40
59
|
|
|
41
|
-
const originalRouteEngineEvent =
|
|
60
|
+
const originalRouteEngineEvent = WidgetRendererClass.prototype.routeEngineEvent as any
|
|
42
61
|
|
|
43
|
-
|
|
62
|
+
WidgetRendererClass.prototype.routeEngineEvent = function (this: unknown, event: any) {
|
|
44
63
|
const renderer = this as CheckboxRuntime
|
|
45
64
|
syncClickableCheckboxIds(renderer)
|
|
46
65
|
const result = originalRouteEngineEvent.call(this, event) as any
|