@lynx-js/lynx-ui-common 3.137.0 → 3.142.0
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/CHANGELOG.md +12 -0
- package/dist/hooks/useGlobalEventListener.d.ts +2 -2
- package/dist/hooks/useGlobalEventListener.jsx.map +1 -1
- package/dist/hooks/useMemoizedFn.d.ts +2 -2
- package/dist/hooks/useMemoizedFn.jsx.map +1 -1
- package/dist/hooks/useRegisteredEvents.jsx.map +1 -1
- package/dist/reactive/hooks/useReactiveValue.jsx.map +1 -1
- package/dist/types/interfaces/BaseScrollEvents.d.ts +4 -4
- package/dist/types/interfaces/BaseScrollEvents.d.ts.map +1 -1
- package/dist/utils/getEventDetail.jsx.map +1 -1
- package/dist/utils/selector.jsx.map +1 -1
- package/package.json +2 -2
- package/src/hooks/useGlobalEventListener.ts +3 -3
- package/src/hooks/useMemoizedFn.ts +4 -4
- package/src/hooks/useRegisteredEvents.ts +9 -9
- package/src/reactive/hooks/useReactiveValue.ts +2 -2
- package/src/types/interfaces/BaseScrollEvents.ts +6 -4
- package/src/utils/getEventDetail.ts +1 -1
- package/src/utils/selector.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-common
|
|
2
2
|
|
|
3
|
+
## 3.142.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Accept React 18 and newer types. ReactLynx still defines the compatible versions for each app. ([#383](https://github.com/lynx-family/lynx-ui/pull/383))
|
|
8
|
+
|
|
9
|
+
## 3.139.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Correct generated API types for scroll callbacks and union-valued arrays. ([#273](https://github.com/lynx-family/lynx-ui/pull/273))
|
|
14
|
+
|
|
3
15
|
## 3.137.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
type
|
|
1
|
+
type Noop = (...p: any) => void;
|
|
2
2
|
/**
|
|
3
3
|
* Use this hook to register events
|
|
4
4
|
* Events will be registered at first render, preventing possible message missing.
|
|
5
5
|
* When deps updates, handlerFunc will be updated, old event listener will be removed.
|
|
6
6
|
*/
|
|
7
|
-
export declare function useGlobalEventListener(eventName: string, handler:
|
|
7
|
+
export declare function useGlobalEventListener(eventName: string, handler: Noop, deps?: readonly unknown[]): void;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=useGlobalEventListener.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks/useGlobalEventListener.jsx","sources":["../../src/hooks/useGlobalEventListener.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useCallback, useEffect, useMemo } from '@lynx-js/react'\n\n//
|
|
1
|
+
{"version":3,"file":"hooks/useGlobalEventListener.jsx","sources":["../../src/hooks/useGlobalEventListener.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useCallback, useEffect, useMemo } from '@lynx-js/react'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic type definition\ntype Noop = (...p: any) => void\n\n/**\n * Use this hook to register events\n * Events will be registered at first render, preventing possible message missing.\n * When deps updates, handlerFunc will be updated, old event listener will be removed.\n */\nexport function useGlobalEventListener(\n eventName: string,\n handler: Noop,\n deps?: readonly unknown[],\n) {\n const handlerFunc = useCallback(handler, deps ?? [])\n\n /**\n * We use useMemo to make it only run one time\n * useMemo will run at render.\n * If dependency changes, useMemo will rerun to have correct handlerFunc\n * then a new listener will be added with correct handlerFunc\n */\n useMemo(() => {\n if (!__LEPUS__) {\n lynx\n .getJSModule('GlobalEventEmitter')\n .addListener(eventName, handlerFunc)\n }\n }, [eventName, handlerFunc])\n\n /**\n * We use return value of useEffect to removeListener\n * Dependency is just the same as `useMemo` above\n * If dependency changes, useEffect's cleaning up func will be run, which is essentially\n * the cleaning up func of `addListener` run at useMemo\n */\n useEffect(\n () => () => {\n lynx\n .getJSModule('GlobalEventEmitter')\n .removeListener(eventName, handlerFunc)\n },\n [eventName, handlerFunc],\n )\n}\n"],"names":["useGlobalEventListener","eventName","handler","deps","handlerFunc","useCallback","useMemo","__LEPUS__","lynx","useEffect"],"mappings":";AAcO,SAASA,uBACdC,SAAiB,EACjBC,OAAa,EACbC,IAAyB;IAEzB,MAAMC,cAAcC,YAAYH,SAASC,QAAQ,EAAE;IAQnDG,QAAQ;QACN,IAAI,CAACC,WACHC,KACG,WAAW,CAAC,sBACZ,WAAW,CAACP,WAAWG;IAE9B,GAAG;QAACH;QAAWG;KAAY;IAQ3BK,UACE,IAAM;YACJD,KACG,WAAW,CAAC,sBACZ,cAAc,CAACP,WAAWG;QAC/B,GACA;QAACH;QAAWG;KAAY;AAE5B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type
|
|
1
|
+
type Noop = (this: any, ...args: any[]) => any;
|
|
2
2
|
/**
|
|
3
3
|
* Hooks for persistent functions. In general, useMemoizedFn can be used instead of useCallback.
|
|
4
4
|
* In some scenarios, we need to use useCallback to cache a function, but when the second parameter deps changes, the function will be regenerated, causing the function reference to change.
|
|
5
5
|
*/
|
|
6
|
-
declare function useMemoizedFn<T extends
|
|
6
|
+
declare function useMemoizedFn<T extends Noop>(fn: T): T;
|
|
7
7
|
export { useMemoizedFn };
|
|
8
8
|
//# sourceMappingURL=useMemoizedFn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks/useMemoizedFn.jsx","sources":["../../src/hooks/useMemoizedFn.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo, useRef } from '@lynx-js/react'\n\n//
|
|
1
|
+
{"version":3,"file":"hooks/useMemoizedFn.jsx","sources":["../../src/hooks/useMemoizedFn.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo, useRef } from '@lynx-js/react'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic type definition\ntype Noop = (this: any, ...args: any[]) => any\n\ntype PickFunction<T extends Noop> = (\n this: ThisParameterType<T>,\n ...args: Parameters<T>\n) => ReturnType<T>\n\n/**\n * Hooks for persistent functions. In general, useMemoizedFn can be used instead of useCallback.\n * In some scenarios, we need to use useCallback to cache a function, but when the second parameter deps changes, the function will be regenerated, causing the function reference to change.\n */\nfunction useMemoizedFn<T extends Noop>(fn: T) {\n const fnRef = useRef<T>(fn)\n\n // why not write `fnRef.current = fn`?\n // https://github.com/alibaba/hooks/issues/728\n fnRef.current = useMemo<T>(() => fn, [fn])\n\n const memoizedFn = useRef<PickFunction<T>>()\n memoizedFn.current ??= function(this, ...args) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return fnRef.current.apply(this, args)\n }\n\n return memoizedFn.current as unknown as T\n}\n\nexport { useMemoizedFn }\n"],"names":["useMemoizedFn","fn","fnRef","useRef","useMemo","memoizedFn","args"],"mappings":";AAkBA,SAASA,cAA8BC,EAAK;IAC1C,MAAMC,QAAQC,OAAUF;IAIxBC,MAAM,OAAO,GAAGE,QAAW,IAAMH,IAAI;QAACA;KAAG;IAEzC,MAAMI,aAAaF;IACnBE,WAAW,OAAO,KAAK,SAAe,GAAGC,IAAI;QAE3C,OAAOJ,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,EAAEI;IACnC;IAEA,OAAOD,WAAW,OAAO;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks/useRegisteredEvents.jsx","sources":["../../src/hooks/useRegisteredEvents.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMainThreadRef } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { TouchEvent } from '@lynx-js/types'\n\nimport { mainThreadifyEventsMapping } from '../utils'\n\n// These standard touch callbacks are registered through useTouchEmulation to fit the base touch-style API for both touch and mouse inputs.\nconst EMULATED_TOUCH_EVENT_NAMES = new Set([\n 'onTouchStart',\n 'onTouchMove',\n 'onTouchEnd',\n 'onTouchCancel',\n])\n\nconst useMainThreadifyEvents = (\n //
|
|
1
|
+
{"version":3,"file":"hooks/useRegisteredEvents.jsx","sources":["../../src/hooks/useRegisteredEvents.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMainThreadRef } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { TouchEvent } from '@lynx-js/types'\n\nimport { mainThreadifyEventsMapping } from '../utils'\n\n// These standard touch callbacks are registered through useTouchEmulation to fit the base touch-style API for both touch and mouse inputs.\nconst EMULATED_TOUCH_EVENT_NAMES = new Set([\n 'onTouchStart',\n 'onTouchMove',\n 'onTouchEnd',\n 'onTouchCancel',\n])\n\nconst useMainThreadifyEvents = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map\n events: Record<string, any>,\n mainThreadEvents: Record<string, string>, // e.g.: { 'onScroll': bindscroll } -> { 'main-thread:bindscroll': main-thread:bindscroll }\n) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map\n type ReducedEventsType = Record<string, any>\n const mainThreadifyEvents: ReducedEventsType = {}\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- main-thread marker\n const dummyRef = useMainThreadRef()\n for (const event of Object.keys(events)) {\n if (event in mainThreadEvents) {\n mainThreadifyEvents[mainThreadEvents[event]] = (e: unknown) => {\n 'main thread'\n if (events[event]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n events[event](e)\n }\n }\n }\n }\n return mainThreadifyEvents\n}\n/**\n * Only bind the events that are passed in and registered in the registeredProps to improve performance.\n * @example\n * ```\n * const XXXOwnedProps: Record<string, string> = {\n * ...ScrollEvents,\n * ...ExposureEventsAndProps,\n * ...TouchEvents,\n * ...LayoutEvents,\n * };\n * const registerProps = useRegisteredEvents(props, XXXOwnedProps);\n * <XXX {...registerProps} />\n *\n * ```\n */\nexport const useRegisteredEvents = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map\n events: Record<string, any>,\n registeredEventsMapping: Record<string, string>,\n) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map\n type ReducedEventsType = Record<string, any>\n const reducedEvents: ReducedEventsType = {}\n for (const event of Object.keys(events)) {\n if (\n event in registeredEventsMapping\n && !EMULATED_TOUCH_EVENT_NAMES.has(event)\n ) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n reducedEvents[registeredEventsMapping[event]] = events[event]\n }\n }\n const touchHandlers = useTouchEmulation({\n onTouchStart: events.onTouchStart as\n | ((event: TouchEvent) => void)\n | undefined,\n onTouchMove: events.onTouchMove as\n | ((event: TouchEvent) => void)\n | undefined,\n onTouchEnd: events.onTouchEnd as\n | ((event: TouchEvent) => void)\n | undefined,\n onTouchCancel: events.onTouchCancel as\n | ((event: TouchEvent) => void)\n | undefined,\n })\n const mainThreadifyEvents = mainThreadifyEventsMapping(\n registeredEventsMapping,\n )\n const mainThreadifyEventsContents = useMainThreadifyEvents(\n events,\n mainThreadifyEvents,\n )\n return { ...reducedEvents, ...touchHandlers, ...mainThreadifyEventsContents }\n}\n"],"names":["EMULATED_TOUCH_EVENT_NAMES","Set","useMainThreadifyEvents","events","mainThreadEvents","mainThreadifyEvents","useMainThreadRef","event","Object","e","useRegisteredEvents","registeredEventsMapping","reducedEvents","touchHandlers","useTouchEmulation","mainThreadifyEventsMapping","mainThreadifyEventsContents"],"mappings":";;;AAYA,MAAMA,6BAA6B,IAAIC,IAAI;IACzC;IACA;IACA;IACA;CACD;AAED,MAAMC,yBAAyB,CAE7BC,QACAC;IAIA,MAAMC,sBAAyC,CAAC;IAE/BC;IACjB,KAAK,MAAMC,SAASC,OAAO,IAAI,CAACL,QAC9B,IAAII,SAASH,kBACXC,mBAAmB,CAACD,gBAAgB,CAACG,MAAM,CAAC,GAAG,CAACE;QAC9C;QACA,IAAIN,MAAM,CAACI,MAAM,EAEfJ,MAAM,CAACI,MAAM,CAACE;IAElB;IAGJ,OAAOJ;AACT;AAgBO,MAAMK,sBAAsB,CAEjCP,QACAQ;IAIA,MAAMC,gBAAmC,CAAC;IAC1C,KAAK,MAAML,SAASC,OAAO,IAAI,CAACL,QAC9B,IACEI,SAASI,2BACN,CAACX,2BAA2B,GAAG,CAACO,QAGnCK,aAAa,CAACD,uBAAuB,CAACJ,MAAM,CAAC,GAAGJ,MAAM,CAACI,MAAM;IAGjE,MAAMM,gBAAgBC,kBAAkB;QACtC,cAAcX,OAAO,YAAY;QAGjC,aAAaA,OAAO,WAAW;QAG/B,YAAYA,OAAO,UAAU;QAG7B,eAAeA,OAAO,aAAa;IAGrC;IACA,MAAME,sBAAsBU,2BAC1BJ;IAEF,MAAMK,8BAA8Bd,uBAClCC,QACAE;IAEF,OAAO;QAAE,GAAGO,aAAa;QAAE,GAAGC,aAAa;QAAE,GAAGG,2BAA2B;IAAC;AAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive/hooks/useReactiveValue.jsx","sources":["../../../src/reactive/hooks/useReactiveValue.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { runOnMainThread, useMainThreadRef, useMemo } from '@lynx-js/react'\nimport type { MainThreadRef } from '@lynx-js/react'\n\nimport type {\n ReactiveValueAPI,\n ReactiveValueOptions,\n Subscriber,\n Unsubscribe,\n} from '../types'\n\nexport type ReactiveValue<T> = ReturnType<\n typeof createMainThreadReactiveValue<T>\n>\n\nexport function createMainThreadReactiveValue<T>(\n initialValue: T,\n options: ReactiveValueOptions = {},\n) {\n 'main thread'\n class ReactiveValue<T> implements ReactiveValueAPI<T> {\n _value: T\n _subscribers = new Set<Subscriber<T>>()\n _options: ReactiveValueOptions\n _isDestroyed = false\n\n constructor(initialValue: T, options: ReactiveValueOptions = {}) {\n this._value = initialValue\n this._options = options\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._isDestroyed) return\n\n if (this._value !== newValue) {\n this._value = newValue\n this._notifySubscribers()\n }\n }\n\n get(): T {\n return this._value\n }\n\n set(newValue: T): void {\n this.value = newValue\n }\n\n subscribe(callback: Subscriber<T>): Unsubscribe {\n //
|
|
1
|
+
{"version":3,"file":"reactive/hooks/useReactiveValue.jsx","sources":["../../../src/reactive/hooks/useReactiveValue.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { runOnMainThread, useMainThreadRef, useMemo } from '@lynx-js/react'\nimport type { MainThreadRef } from '@lynx-js/react'\n\nimport type {\n ReactiveValueAPI,\n ReactiveValueOptions,\n Subscriber,\n Unsubscribe,\n} from '../types'\n\nexport type ReactiveValue<T> = ReturnType<\n typeof createMainThreadReactiveValue<T>\n>\n\nexport function createMainThreadReactiveValue<T>(\n initialValue: T,\n options: ReactiveValueOptions = {},\n) {\n 'main thread'\n class ReactiveValue<T> implements ReactiveValueAPI<T> {\n _value: T\n _subscribers = new Set<Subscriber<T>>()\n _options: ReactiveValueOptions\n _isDestroyed = false\n\n constructor(initialValue: T, options: ReactiveValueOptions = {}) {\n this._value = initialValue\n this._options = options\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._isDestroyed) return\n\n if (this._value !== newValue) {\n this._value = newValue\n this._notifySubscribers()\n }\n }\n\n get(): T {\n return this._value\n }\n\n set(newValue: T): void {\n this.value = newValue\n }\n\n subscribe(callback: Subscriber<T>): Unsubscribe {\n // eslint-disable-next-line @typescript-eslint/no-empty-function -- intentional no-op cleanup\n if (this._isDestroyed) return () => {}\n\n this._subscribers.add(callback)\n\n // Call immediately with current value\n callback(this._value)\n\n return () => this.unsubscribe(callback)\n }\n\n unsubscribe(callback: Subscriber<T>): void {\n this._subscribers.delete(callback)\n }\n\n addListener(callback: Subscriber<T>): Unsubscribe {\n return this.subscribe(callback)\n }\n\n removeListener(callback: Subscriber<T>): void {\n this.unsubscribe(callback)\n }\n\n removeAllListeners(): void {\n this._subscribers.clear()\n }\n\n destroy(): void {\n this._isDestroyed = true\n this._subscribers.clear()\n }\n\n _notifySubscribers(): void {\n if (this._isDestroyed) return\n\n for (const subscriber of this._subscribers) {\n try {\n subscriber(this._value)\n } catch (error) {\n if (this._options.debug) {\n console.error(\n `[ReactiveValue${\n this._options.label ? ` ${this._options.label}` : ''\n }]: Error in subscriber:`,\n error,\n )\n }\n }\n }\n }\n }\n return new ReactiveValue(initialValue, options)\n}\n\nexport function useReactiveValue<T>(\n initialValue: T,\n options: ReactiveValueOptions = {},\n): MainThreadRef<ReactiveValue<T>> {\n const mtRef = useMainThreadRef<ReactiveValue<T>>({} as ReactiveValue<T>)\n\n function initReactiveValue() {\n 'main thread'\n mtRef.current = createMainThreadReactiveValue(initialValue, options)\n }\n\n useMemo(() => {\n if (__BACKGROUND__) {\n runOnMainThread(initReactiveValue)()\n } else {\n // Kept for preventing tree shaking\n void initReactiveValue\n }\n }, [])\n\n return mtRef\n}\n"],"names":["createMainThreadReactiveValue","initialValue","options","ReactiveValue","Set","newValue","callback","subscriber","error","console","useReactiveValue","mtRef","useMainThreadRef","initReactiveValue","useMemo","__BACKGROUND__","runOnMainThread"],"mappings":";AAkBO,SAASA,8BACdC,YAAe,EACfC,UAAgC,CAAC,CAAC;IAElC;IACA,MAAMC;QACJ,OAAS;QACT,eAAe,IAAIC,MAAoB;QACvC,SAA8B;QAC9B,eAAe,MAAK;QAEpB,YAAYH,YAAe,EAAEC,UAAgC,CAAC,CAAC,CAAE;YAC/D,IAAI,CAAC,MAAM,GAAGD;YACd,IAAI,CAAC,QAAQ,GAAGC;QAClB;QAEA,IAAI,QAAW;YACb,OAAO,IAAI,CAAC,MAAM;QACpB;QAEA,IAAI,MAAMG,QAAW,EAAE;YACrB,IAAI,IAAI,CAAC,YAAY,EAAE;YAEvB,IAAI,IAAI,CAAC,MAAM,KAAKA,UAAU;gBAC5B,IAAI,CAAC,MAAM,GAAGA;gBACd,IAAI,CAAC,kBAAkB;YACzB;QACF;QAEA,MAAS;YACP,OAAO,IAAI,CAAC,MAAM;QACpB;QAEA,IAAIA,QAAW,EAAQ;YACrB,IAAI,CAAC,KAAK,GAAGA;QACf;QAEA,UAAUC,QAAuB,EAAe;YAE9C,IAAI,IAAI,CAAC,YAAY,EAAE,OAAO,KAAO;YAErC,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA;YAGtBA,SAAS,IAAI,CAAC,MAAM;YAEpB,OAAO,IAAM,IAAI,CAAC,WAAW,CAACA;QAChC;QAEA,YAAYA,QAAuB,EAAQ;YACzC,IAAI,CAAC,YAAY,CAAC,MAAM,CAACA;QAC3B;QAEA,YAAYA,QAAuB,EAAe;YAChD,OAAO,IAAI,CAAC,SAAS,CAACA;QACxB;QAEA,eAAeA,QAAuB,EAAQ;YAC5C,IAAI,CAAC,WAAW,CAACA;QACnB;QAEA,qBAA2B;YACzB,IAAI,CAAC,YAAY,CAAC,KAAK;QACzB;QAEA,UAAgB;YACd,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,YAAY,CAAC,KAAK;QACzB;QAEA,qBAA2B;YACzB,IAAI,IAAI,CAAC,YAAY,EAAE;YAEvB,KAAK,MAAMC,cAAc,IAAI,CAAC,YAAY,CACxC,IAAI;gBACFA,WAAW,IAAI,CAAC,MAAM;YACxB,EAAE,OAAOC,OAAO;gBACd,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,EACrBC,QAAQ,KAAK,CACX,CAAC,cAAc,EACb,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,GACnD,uBAAuB,CAAC,EACzBD;YAGN;QAEJ;IACF;IACA,OAAO,IAAIL,cAAcF,cAAcC;AACzC;AAEO,SAASQ,iBACdT,YAAe,EACfC,UAAgC,CAAC,CAAC;IAElC,MAAMS,QAAQC,iBAAmC,CAAC;IAElD,SAASC;QACP;QACAF,MAAM,OAAO,GAAGX,8BAA8BC,cAAcC;IAC9D;IAEAY,QAAQ;QACN,IAAIC,gBACFC,gBAAgBH;IAKpB,GAAG,EAAE;IAEL,OAAOF;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScrollEndEvent, ScrollEvent, ScrollToLowerEvent, ScrollToUpperEvent } from '@lynx-js/types';
|
|
2
2
|
export interface BaseScrollEvents {
|
|
3
3
|
/**
|
|
4
4
|
* Being triggered when scrolling occurs.
|
|
@@ -16,7 +16,7 @@ export interface BaseScrollEvents {
|
|
|
16
16
|
* @Android
|
|
17
17
|
* @iOS
|
|
18
18
|
*/
|
|
19
|
-
onScrollEnd?: (e:
|
|
19
|
+
onScrollEnd?: (e: ScrollEndEvent) => void;
|
|
20
20
|
/**
|
|
21
21
|
* Being triggered when scrolling to upper.
|
|
22
22
|
* @zh 滚动到顶部时触发。
|
|
@@ -25,7 +25,7 @@ export interface BaseScrollEvents {
|
|
|
25
25
|
* @Android
|
|
26
26
|
* @iOS
|
|
27
27
|
*/
|
|
28
|
-
onScrollToUpper?: (e:
|
|
28
|
+
onScrollToUpper?: (e: ScrollToUpperEvent) => void;
|
|
29
29
|
/**
|
|
30
30
|
* Being triggered when scrolling to lower.
|
|
31
31
|
* @zh 滚动到底部时触发。
|
|
@@ -34,6 +34,6 @@ export interface BaseScrollEvents {
|
|
|
34
34
|
* @Android
|
|
35
35
|
* @iOS
|
|
36
36
|
*/
|
|
37
|
-
onScrollToLower?: (e:
|
|
37
|
+
onScrollToLower?: (e: ScrollToLowerEvent) => void;
|
|
38
38
|
}
|
|
39
39
|
//# sourceMappingURL=BaseScrollEvents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseScrollEvents.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/BaseScrollEvents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"BaseScrollEvents.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/BaseScrollEvents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IACnC;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAA;IACzC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAA;IACjD;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAA;CAClD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/getEventDetail.jsx","sources":["../../src/utils/getEventDetail.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * A type representing event details that may contain layout and positioning information.\n * It includes optional properties for dimensions and coordinates, and allows for other properties.\n */\nexport type EventDetailWithLayout = {\n left?: number\n top?: number\n right?: number\n bottom?: number\n width?: number\n height?: number\n} & Record<string, unknown>\n\n/**\n * Safely retrieves detailed information from an event object.\n * It attempts to access `event.detail` first. If `detail` is not available,\n * it falls back to `event.params`. This is useful for maintaining\n * compatibility across different event structures on different platforms and versions.\n *\n * @param event The event object, which can be of any type.\n * @returns The `detail` or `params` object from the event, or an empty object if neither is found.\n */\nexport function getEventDetail<\n T extends EventDetailWithLayout = EventDetailWithLayout,\n> //
|
|
1
|
+
{"version":3,"file":"utils/getEventDetail.jsx","sources":["../../src/utils/getEventDetail.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * A type representing event details that may contain layout and positioning information.\n * It includes optional properties for dimensions and coordinates, and allows for other properties.\n */\nexport type EventDetailWithLayout = {\n left?: number\n top?: number\n right?: number\n bottom?: number\n width?: number\n height?: number\n} & Record<string, unknown>\n\n/**\n * Safely retrieves detailed information from an event object.\n * It attempts to access `event.detail` first. If `detail` is not available,\n * it falls back to `event.params`. This is useful for maintaining\n * compatibility across different event structures on different platforms and versions.\n *\n * @param event The event object, which can be of any type.\n * @returns The `detail` or `params` object from the event, or an empty object if neither is found.\n */\nexport function getEventDetail<\n T extends EventDetailWithLayout = EventDetailWithLayout,\n> // eslint-disable-next-line @typescript-eslint/no-explicit-any -- accept any event type\n(event: any): T {\n if (!event) {\n return {} as T\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return (event.detail ?? event.params ?? {}) as T\n}\n"],"names":["getEventDetail","event"],"mappings":"AA0BO,SAASA,eAGfC,KAAU;IACT,IAAI,CAACA,OACH,OAAO,CAAC;IAGV,OAAQA,MAAM,MAAM,IAAIA,MAAM,MAAM,IAAI,CAAC;AAC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/selector.jsx","sources":["../../src/utils/selector.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RefObject } from '@lynx-js/react'\n\nimport type { AnyObject, MainThread, NodesRef } from '@lynx-js/types'\n\nexport class InvokeRejectError extends Error {\n errorCode: number\n detail?: object | string\n constructor(errorCode: number, errorMsg?: string) {\n super(typeof errorMsg === 'string' ? errorMsg : 'unknown error')\n this.errorCode = errorCode\n this.detail = errorMsg\n }\n}\n\nexport const setNativePropsByRef = (\n ref: RefObject<NodesRef> | undefined,\n //
|
|
1
|
+
{"version":3,"file":"utils/selector.jsx","sources":["../../src/utils/selector.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RefObject } from '@lynx-js/react'\n\nimport type { AnyObject, MainThread, NodesRef } from '@lynx-js/types'\n\nexport class InvokeRejectError extends Error {\n errorCode: number\n detail?: object | string\n constructor(errorCode: number, errorMsg?: string) {\n super(typeof errorMsg === 'string' ? errorMsg : 'unknown error')\n this.errorCode = errorCode\n this.detail = errorMsg\n }\n}\n\nexport const setNativePropsByRef = (\n ref: RefObject<NodesRef> | undefined,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result\n props: Record<string, any>,\n) => {\n ref?.current?.setNativeProps(props).exec()\n}\n\nexport const setNativePropsById = (\n id: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result\n props: Record<string, any>,\n) => {\n lynx.createSelectorQuery().select(`#${id}`).setNativeProps(props).exec()\n}\n\nexport const setNativeProps = (\n target: {\n ref?: RefObject<NodesRef>\n id?: string\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result\n props: Record<string, any>,\n) =>\n target.id\n ? setNativePropsById(target.id, props)\n : setNativePropsByRef(target.ref, props)\n\nexport const invokeByRef = (\n ref: RefObject<NodesRef> | undefined,\n method: string,\n params?: AnyObject,\n): Promise<unknown> =>\n new Promise((resolve, reject) => {\n if (!ref?.current) {\n reject(new InvokeRejectError(2, 'no node found for the ref'))\n return\n }\n ref?.current\n ?.invoke({\n method,\n params,\n success: (res) => {\n resolve(res)\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result\n fail: (res: { code: number, data?: any }) => {\n reject(new InvokeRejectError(res.code, JSON.stringify(res.data)))\n },\n })\n .exec()\n })\n\nexport const invokeById = (\n id: string,\n method: string,\n params?: AnyObject,\n): Promise<unknown> =>\n new Promise((resolve, reject) => {\n lynx\n .createSelectorQuery()\n .select(`#${id}`)\n .invoke({\n method,\n params,\n success: (res) => {\n resolve(res)\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result\n fail: (res: { code: number, data?: any }) => {\n reject(new InvokeRejectError(res.code, JSON.stringify(res.data)))\n },\n })\n .exec()\n })\n\nexport const invoke = (\n target: {\n ref?: RefObject<NodesRef>\n id?: string\n },\n method: string,\n params?: AnyObject,\n): Promise<unknown> =>\n target.id\n ? invokeById(target.id, method, params)\n : invokeByRef(target.ref, method, params)\n\nexport interface GetRectPromise {\n left: number\n top: number\n width: number\n height: number\n bottom: number\n right: number\n}\n\nexport const getRectByRef = (\n ref?: RefObject<NodesRef>,\n relativeToScreen = false,\n relativeTo = '',\n): Promise<GetRectPromise> =>\n new Promise((resolve, reject) => {\n invokeByRef(ref, 'boundingClientRect', {\n relativeTo: relativeToScreen ? 'screen' : relativeTo,\n // Match the standard getBoundingClientRect behavior: transforms are\n // included in the returned rect. Keep this enabled by default across\n // platforms to avoid incorrect bounds for transformed nodes, such as\n // scaled views. A few animation-related cases may opt out explicitly.\n androidEnableTransformProps: true,\n iosEnableTransformProps: true,\n harmonyEnableTransformProps: true,\n })\n .then((res) => {\n resolve(\n res as {\n left: number\n top: number\n width: number\n height: number\n bottom: number\n right: number\n },\n )\n })\n .catch((error: InvokeRejectError) => {\n reject(error)\n })\n })\n\nexport const getRootRect = (\n relativeToScreen = false,\n relativeTo = '',\n): Promise<GetRectPromise> =>\n new Promise((resolve, reject) => {\n lynx\n .createSelectorQuery()\n .selectRoot()\n .invoke({\n method: 'boundingClientRect',\n params: {\n relativeTo: relativeToScreen ? 'screen' : relativeTo,\n // Match the standard getBoundingClientRect behavior: transforms are\n // included in the returned rect. Keep this enabled by default across\n // platforms to avoid incorrect bounds for transformed nodes, such as\n // scaled views. A few animation-related cases may opt out explicitly.\n androidEnableTransformProps: true,\n iosEnableTransformProps: true,\n harmonyEnableTransformProps: true,\n },\n success: (res) => {\n resolve(\n res as {\n left: number\n top: number\n width: number\n height: number\n bottom: number\n right: number\n },\n )\n },\n fail: (res: { code: number, data?: object }) => {\n reject(new InvokeRejectError(res.code, JSON.stringify(res.data)))\n },\n })\n .exec()\n })\n\nexport const getRectById = (\n id: string,\n relativeToScreen = false,\n relativeTo = '',\n): Promise<GetRectPromise> =>\n new Promise((resolve, reject) => {\n invokeById(id, 'boundingClientRect', {\n relativeTo: relativeToScreen ? 'screen' : relativeTo,\n // Match the standard getBoundingClientRect behavior: transforms are\n // included in the returned rect. Keep this enabled by default across\n // platforms to avoid incorrect bounds for transformed nodes, such as\n // scaled views. A few animation-related cases may opt out explicitly.\n androidEnableTransformProps: true,\n iosEnableTransformProps: true,\n harmonyEnableTransformProps: true,\n })\n .then((res) => {\n resolve(\n res as {\n left: number\n top: number\n width: number\n height: number\n bottom: number\n right: number\n },\n )\n })\n .catch((error: InvokeRejectError) => {\n reject(error)\n })\n })\n\nexport const getRect = (\n target: {\n ref?: RefObject<NodesRef>\n id?: string\n },\n relativeToScreen = false,\n): Promise<GetRectPromise> =>\n target.id\n ? getRectById(target.id, relativeToScreen)\n : getRectByRef(target.ref, relativeToScreen)\n\nexport const selectorMT: (selector: string) => MainThread.Element | null = (\n selector: string,\n) => {\n 'main thread'\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n\n return lynx.querySelector(`#${selector}`)\n}\n"],"names":["InvokeRejectError","Error","errorCode","errorMsg","setNativePropsByRef","ref","props","setNativePropsById","id","lynx","setNativeProps","target","invokeByRef","method","params","Promise","resolve","reject","res","JSON","invokeById","invoke","getRectByRef","relativeToScreen","relativeTo","error","getRootRect","getRectById","getRect","selectorMT","selector"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.142.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@lynx-js/react": ">=0.100.0",
|
|
40
40
|
"@lynx-js/types": "*",
|
|
41
|
-
"@types/react": "
|
|
41
|
+
"@types/react": ">=18"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { useCallback, useEffect, useMemo } from '@lynx-js/react'
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
type
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic type definition
|
|
8
|
+
type Noop = (...p: any) => void
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Use this hook to register events
|
|
@@ -14,7 +14,7 @@ type noop = (...p: any) => void
|
|
|
14
14
|
*/
|
|
15
15
|
export function useGlobalEventListener(
|
|
16
16
|
eventName: string,
|
|
17
|
-
handler:
|
|
17
|
+
handler: Noop,
|
|
18
18
|
deps?: readonly unknown[],
|
|
19
19
|
) {
|
|
20
20
|
const handlerFunc = useCallback(handler, deps ?? [])
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMemo, useRef } from '@lynx-js/react'
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
type
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic type definition
|
|
8
|
+
type Noop = (this: any, ...args: any[]) => any
|
|
9
9
|
|
|
10
|
-
type PickFunction<T extends
|
|
10
|
+
type PickFunction<T extends Noop> = (
|
|
11
11
|
this: ThisParameterType<T>,
|
|
12
12
|
...args: Parameters<T>
|
|
13
13
|
) => ReturnType<T>
|
|
@@ -16,7 +16,7 @@ type PickFunction<T extends noop> = (
|
|
|
16
16
|
* Hooks for persistent functions. In general, useMemoizedFn can be used instead of useCallback.
|
|
17
17
|
* In some scenarios, we need to use useCallback to cache a function, but when the second parameter deps changes, the function will be regenerated, causing the function reference to change.
|
|
18
18
|
*/
|
|
19
|
-
function useMemoizedFn<T extends
|
|
19
|
+
function useMemoizedFn<T extends Noop>(fn: T) {
|
|
20
20
|
const fnRef = useRef<T>(fn)
|
|
21
21
|
|
|
22
22
|
// why not write `fnRef.current = fn`?
|
|
@@ -18,14 +18,14 @@ const EMULATED_TOUCH_EVENT_NAMES = new Set([
|
|
|
18
18
|
])
|
|
19
19
|
|
|
20
20
|
const useMainThreadifyEvents = (
|
|
21
|
-
//
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map
|
|
22
22
|
events: Record<string, any>,
|
|
23
23
|
mainThreadEvents: Record<string, string>, // e.g.: { 'onScroll': bindscroll } -> { 'main-thread:bindscroll': main-thread:bindscroll }
|
|
24
24
|
) => {
|
|
25
|
-
//
|
|
26
|
-
type
|
|
27
|
-
const mainThreadifyEvents:
|
|
28
|
-
//
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map
|
|
26
|
+
type ReducedEventsType = Record<string, any>
|
|
27
|
+
const mainThreadifyEvents: ReducedEventsType = {}
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- main-thread marker
|
|
29
29
|
const dummyRef = useMainThreadRef()
|
|
30
30
|
for (const event of Object.keys(events)) {
|
|
31
31
|
if (event in mainThreadEvents) {
|
|
@@ -56,13 +56,13 @@ const useMainThreadifyEvents = (
|
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
58
|
export const useRegisteredEvents = (
|
|
59
|
-
//
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map
|
|
60
60
|
events: Record<string, any>,
|
|
61
61
|
registeredEventsMapping: Record<string, string>,
|
|
62
62
|
) => {
|
|
63
|
-
//
|
|
64
|
-
type
|
|
65
|
-
const reducedEvents:
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic event map
|
|
64
|
+
type ReducedEventsType = Record<string, any>
|
|
65
|
+
const reducedEvents: ReducedEventsType = {}
|
|
66
66
|
for (const event of Object.keys(events)) {
|
|
67
67
|
if (
|
|
68
68
|
event in registeredEventsMapping
|
|
@@ -54,7 +54,7 @@ export function createMainThreadReactiveValue<T>(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
subscribe(callback: Subscriber<T>): Unsubscribe {
|
|
57
|
-
//
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function -- intentional no-op cleanup
|
|
58
58
|
if (this._isDestroyed) return () => {}
|
|
59
59
|
|
|
60
60
|
this._subscribers.add(callback)
|
|
@@ -124,7 +124,7 @@ export function useReactiveValue<T>(
|
|
|
124
124
|
runOnMainThread(initReactiveValue)()
|
|
125
125
|
} else {
|
|
126
126
|
// Kept for preventing tree shaking
|
|
127
|
-
initReactiveValue
|
|
127
|
+
void initReactiveValue
|
|
128
128
|
}
|
|
129
129
|
}, [])
|
|
130
130
|
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
-
|
|
6
|
+
ScrollEndEvent,
|
|
7
7
|
ScrollEvent,
|
|
8
|
+
ScrollToLowerEvent,
|
|
9
|
+
ScrollToUpperEvent,
|
|
8
10
|
} from '@lynx-js/types'
|
|
9
11
|
|
|
10
12
|
export interface BaseScrollEvents {
|
|
@@ -24,7 +26,7 @@ export interface BaseScrollEvents {
|
|
|
24
26
|
* @Android
|
|
25
27
|
* @iOS
|
|
26
28
|
*/
|
|
27
|
-
onScrollEnd?: (e:
|
|
29
|
+
onScrollEnd?: (e: ScrollEndEvent) => void
|
|
28
30
|
/**
|
|
29
31
|
* Being triggered when scrolling to upper.
|
|
30
32
|
* @zh 滚动到顶部时触发。
|
|
@@ -33,7 +35,7 @@ export interface BaseScrollEvents {
|
|
|
33
35
|
* @Android
|
|
34
36
|
* @iOS
|
|
35
37
|
*/
|
|
36
|
-
onScrollToUpper?: (e:
|
|
38
|
+
onScrollToUpper?: (e: ScrollToUpperEvent) => void
|
|
37
39
|
/**
|
|
38
40
|
* Being triggered when scrolling to lower.
|
|
39
41
|
* @zh 滚动到底部时触发。
|
|
@@ -42,5 +44,5 @@ export interface BaseScrollEvents {
|
|
|
42
44
|
* @Android
|
|
43
45
|
* @iOS
|
|
44
46
|
*/
|
|
45
|
-
onScrollToLower?: (e:
|
|
47
|
+
onScrollToLower?: (e: ScrollToLowerEvent) => void
|
|
46
48
|
}
|
|
@@ -26,7 +26,7 @@ export type EventDetailWithLayout = {
|
|
|
26
26
|
*/
|
|
27
27
|
export function getEventDetail<
|
|
28
28
|
T extends EventDetailWithLayout = EventDetailWithLayout,
|
|
29
|
-
> //
|
|
29
|
+
> // eslint-disable-next-line @typescript-eslint/no-explicit-any -- accept any event type
|
|
30
30
|
(event: any): T {
|
|
31
31
|
if (!event) {
|
|
32
32
|
return {} as T
|
package/src/utils/selector.ts
CHANGED
|
@@ -18,7 +18,7 @@ export class InvokeRejectError extends Error {
|
|
|
18
18
|
|
|
19
19
|
export const setNativePropsByRef = (
|
|
20
20
|
ref: RefObject<NodesRef> | undefined,
|
|
21
|
-
//
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result
|
|
22
22
|
props: Record<string, any>,
|
|
23
23
|
) => {
|
|
24
24
|
ref?.current?.setNativeProps(props).exec()
|
|
@@ -26,7 +26,7 @@ export const setNativePropsByRef = (
|
|
|
26
26
|
|
|
27
27
|
export const setNativePropsById = (
|
|
28
28
|
id: string,
|
|
29
|
-
//
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result
|
|
30
30
|
props: Record<string, any>,
|
|
31
31
|
) => {
|
|
32
32
|
lynx.createSelectorQuery().select(`#${id}`).setNativeProps(props).exec()
|
|
@@ -37,7 +37,7 @@ export const setNativeProps = (
|
|
|
37
37
|
ref?: RefObject<NodesRef>
|
|
38
38
|
id?: string
|
|
39
39
|
},
|
|
40
|
-
//
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result
|
|
41
41
|
props: Record<string, any>,
|
|
42
42
|
) =>
|
|
43
43
|
target.id
|
|
@@ -61,7 +61,7 @@ export const invokeByRef = (
|
|
|
61
61
|
success: (res) => {
|
|
62
62
|
resolve(res)
|
|
63
63
|
},
|
|
64
|
-
//
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result
|
|
65
65
|
fail: (res: { code: number, data?: any }) => {
|
|
66
66
|
reject(new InvokeRejectError(res.code, JSON.stringify(res.data)))
|
|
67
67
|
},
|
|
@@ -84,7 +84,7 @@ export const invokeById = (
|
|
|
84
84
|
success: (res) => {
|
|
85
85
|
resolve(res)
|
|
86
86
|
},
|
|
87
|
-
//
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Lynx selector result
|
|
88
88
|
fail: (res: { code: number, data?: any }) => {
|
|
89
89
|
reject(new InvokeRejectError(res.code, JSON.stringify(res.data)))
|
|
90
90
|
},
|