@lynx-js/react 0.105.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 +250 -0
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/components/lib/Page.d.ts +3 -0
- package/components/lib/Page.js +56 -0
- package/components/lib/Page.js.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +5 -0
- package/components/lib/index.js.map +1 -0
- package/components/src/Page.ts +75 -0
- package/components/src/index.ts +5 -0
- package/package.json +162 -0
- package/refresh/.gitignore +1 -0
- package/refresh/.npmignore +3 -0
- package/refresh/.turbo/turbo-build.log +8 -0
- package/refresh/dist/index.js +311 -0
- package/refresh/package.json +21 -0
- package/refresh/src/index.ts +6 -0
- package/refresh/src/prefresh.d.ts +11 -0
- package/refresh/tsconfig.json +4 -0
- package/refresh/turbo.json +15 -0
- package/runtime/jsx-dev-runtime/index.d.ts +5 -0
- package/runtime/jsx-dev-runtime/index.js +4 -0
- package/runtime/jsx-runtime/index.d.ts +4 -0
- package/runtime/jsx-runtime/index.js +4 -0
- package/runtime/lazy/import.d.ts +1 -0
- package/runtime/lazy/import.js +55 -0
- package/runtime/lazy/internal.js +39 -0
- package/runtime/lazy/jsx-dev-runtime.js +12 -0
- package/runtime/lazy/jsx-runtime.js +12 -0
- package/runtime/lazy/legacy-react-runtime.js +20 -0
- package/runtime/lazy/react-lepus.js +9 -0
- package/runtime/lazy/react.js +46 -0
- package/runtime/lazy/target.js +11 -0
- package/runtime/lepus/index.d.ts +4 -0
- package/runtime/lepus/index.js +43 -0
- package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
- package/runtime/lepus/jsx-runtime/index.js +66 -0
- package/runtime/lib/backgroundSnapshot.d.ts +23 -0
- package/runtime/lib/backgroundSnapshot.js +348 -0
- package/runtime/lib/backgroundSnapshot.js.map +1 -0
- package/runtime/lib/compat/componentIs.d.ts +4 -0
- package/runtime/lib/compat/componentIs.js +20 -0
- package/runtime/lib/compat/componentIs.js.map +1 -0
- package/runtime/lib/compat/initData.d.ts +43 -0
- package/runtime/lib/compat/initData.js +93 -0
- package/runtime/lib/compat/initData.js.map +1 -0
- package/runtime/lib/compat/lynxComponent.d.ts +5 -0
- package/runtime/lib/compat/lynxComponent.js +71 -0
- package/runtime/lib/compat/lynxComponent.js.map +1 -0
- package/runtime/lib/debug/debug.d.ts +2 -0
- package/runtime/lib/debug/debug.js +9 -0
- package/runtime/lib/debug/debug.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +3 -0
- package/runtime/lib/debug/printSnapshot.js +21 -0
- package/runtime/lib/debug/printSnapshot.js.map +1 -0
- package/runtime/lib/debug/profile.d.ts +1 -0
- package/runtime/lib/debug/profile.js +51 -0
- package/runtime/lib/debug/profile.js.map +1 -0
- package/runtime/lib/document.d.ts +4 -0
- package/runtime/lib/document.js +49 -0
- package/runtime/lib/document.js.map +1 -0
- package/runtime/lib/gesture/processGesture.d.ts +4 -0
- package/runtime/lib/gesture/processGesture.js +48 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -0
- package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
- package/runtime/lib/gesture/processGestureBagkround.js +16 -0
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
- package/runtime/lib/gesture/types.d.ts +34 -0
- package/runtime/lib/gesture/types.js +13 -0
- package/runtime/lib/gesture/types.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +26 -0
- package/runtime/lib/hooks/react.js +35 -0
- package/runtime/lib/hooks/react.js.map +1 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
- package/runtime/lib/hydrate.d.ts +18 -0
- package/runtime/lib/hydrate.js +271 -0
- package/runtime/lib/hydrate.js.map +1 -0
- package/runtime/lib/index.d.ts +9 -0
- package/runtime/lib/index.js +46 -0
- package/runtime/lib/index.js.map +1 -0
- package/runtime/lib/internal.d.ts +26 -0
- package/runtime/lib/internal.js +41 -0
- package/runtime/lib/internal.js.map +1 -0
- package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
- package/runtime/lib/legacy-react-runtime/index.js +34 -0
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
- package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
- package/runtime/lib/lifecycle/delayUnmount.js +68 -0
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
- package/runtime/lib/lifecycle/destroy.d.ts +2 -0
- package/runtime/lib/lifecycle/destroy.js +21 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -0
- package/runtime/lib/lifecycle/pass.d.ts +3 -0
- package/runtime/lib/lifecycle/pass.js +12 -0
- package/runtime/lib/lifecycle/pass.js.map +1 -0
- package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
- package/runtime/lib/lifecycle/patchUpdate.js +179 -0
- package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +3 -0
- package/runtime/lib/lifecycle/reload.js +63 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -0
- package/runtime/lib/lifecycle/render.d.ts +2 -0
- package/runtime/lib/lifecycle/render.js +44 -0
- package/runtime/lib/lifecycle/render.js.map +1 -0
- package/runtime/lib/lifecycleConstant.d.ts +12 -0
- package/runtime/lib/lifecycleConstant.js +17 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -0
- package/runtime/lib/list.d.ts +40 -0
- package/runtime/lib/list.js +305 -0
- package/runtime/lib/list.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.d.ts +2 -0
- package/runtime/lib/lynx/calledByNative.js +113 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -0
- package/runtime/lib/lynx/component.d.ts +1 -0
- package/runtime/lib/lynx/component.js +69 -0
- package/runtime/lib/lynx/component.js.map +1 -0
- package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
- package/runtime/lib/lynx/dynamic-js.js +31 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -0
- package/runtime/lib/lynx/env.d.ts +1 -0
- package/runtime/lib/lynx/env.js +92 -0
- package/runtime/lib/lynx/env.js.map +1 -0
- package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
- package/runtime/lib/lynx/injectLepusMethods.js +50 -0
- package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
- package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
- package/runtime/lib/lynx/lazy-bundle.js +119 -0
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
- package/runtime/lib/lynx/performance.d.ts +29 -0
- package/runtime/lib/lynx/performance.js +100 -0
- package/runtime/lib/lynx/performance.js.map +1 -0
- package/runtime/lib/lynx/tt.d.ts +4 -0
- package/runtime/lib/lynx/tt.js +193 -0
- package/runtime/lib/lynx/tt.js.map +1 -0
- package/runtime/lib/lynx-api.d.ts +311 -0
- package/runtime/lib/lynx-api.js +116 -0
- package/runtime/lib/lynx-api.js.map +1 -0
- package/runtime/lib/lynx.d.ts +2 -0
- package/runtime/lib/lynx.js +91 -0
- package/runtime/lib/lynx.js.map +1 -0
- package/runtime/lib/opcodes.d.ts +2 -0
- package/runtime/lib/opcodes.js +59 -0
- package/runtime/lib/opcodes.js.map +1 -0
- package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
- package/runtime/lib/renderToOpcodes/constants.js +23 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
- package/runtime/lib/renderToOpcodes/index.js +227 -0
- package/runtime/lib/renderToOpcodes/index.js.map +1 -0
- package/runtime/lib/root.d.ts +7 -0
- package/runtime/lib/root.js +17 -0
- package/runtime/lib/root.js.map +1 -0
- package/runtime/lib/snapshot/event.d.ts +3 -0
- package/runtime/lib/snapshot/event.js +24 -0
- package/runtime/lib/snapshot/event.js.map +1 -0
- package/runtime/lib/snapshot/gesture.d.ts +2 -0
- package/runtime/lib/snapshot/gesture.js +18 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
- package/runtime/lib/snapshot/platformInfo.js +35 -0
- package/runtime/lib/snapshot/platformInfo.js.map +1 -0
- package/runtime/lib/snapshot/ref.d.ts +10 -0
- package/runtime/lib/snapshot/ref.js +119 -0
- package/runtime/lib/snapshot/ref.js.map +1 -0
- package/runtime/lib/snapshot/spread.d.ts +5 -0
- package/runtime/lib/snapshot/spread.js +289 -0
- package/runtime/lib/snapshot/spread.js.map +1 -0
- package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
- package/runtime/lib/snapshot/workletEvent.js +22 -0
- package/runtime/lib/snapshot/workletEvent.js.map +1 -0
- package/runtime/lib/snapshot/workletRef.d.ts +5 -0
- package/runtime/lib/snapshot/workletRef.js +52 -0
- package/runtime/lib/snapshot/workletRef.js.map +1 -0
- package/runtime/lib/snapshot.d.ts +81 -0
- package/runtime/lib/snapshot.js +477 -0
- package/runtime/lib/snapshot.js.map +1 -0
- package/runtime/lib/snapshotPatch.d.ts +14 -0
- package/runtime/lib/snapshotPatch.js +31 -0
- package/runtime/lib/snapshotPatch.js.map +1 -0
- package/runtime/lib/snapshotPatchApply.d.ts +2 -0
- package/runtime/lib/snapshotPatchApply.js +110 -0
- package/runtime/lib/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/utils.d.ts +4 -0
- package/runtime/lib/utils.js +32 -0
- package/runtime/lib/utils.js.map +1 -0
- package/runtime/lib/worklet/ctx.d.ts +1 -0
- package/runtime/lib/worklet/ctx.js +17 -0
- package/runtime/lib/worklet/ctx.js.map +1 -0
- package/runtime/lib/worklet/execMap.d.ts +1 -0
- package/runtime/lib/worklet/execMap.js +42 -0
- package/runtime/lib/worklet/execMap.js.map +1 -0
- package/runtime/lib/worklet/functionality.d.ts +1 -0
- package/runtime/lib/worklet/functionality.js +11 -0
- package/runtime/lib/worklet/functionality.js.map +1 -0
- package/runtime/lib/worklet/hmr.d.ts +1 -0
- package/runtime/lib/worklet/hmr.js +21 -0
- package/runtime/lib/worklet/hmr.js.map +1 -0
- package/runtime/lib/worklet/indexMap.d.ts +8 -0
- package/runtime/lib/worklet/indexMap.js +17 -0
- package/runtime/lib/worklet/indexMap.js.map +1 -0
- package/runtime/lib/worklet/jsImpl.d.ts +11 -0
- package/runtime/lib/worklet/jsImpl.js +68 -0
- package/runtime/lib/worklet/jsImpl.js.map +1 -0
- package/runtime/lib/worklet/runWorklet.d.ts +14 -0
- package/runtime/lib/worklet/runWorklet.js +82 -0
- package/runtime/lib/worklet/runWorklet.js.map +1 -0
- package/runtime/lib/worklet/workletRef.d.ts +131 -0
- package/runtime/lib/worklet/workletRef.js +96 -0
- package/runtime/lib/worklet/workletRef.js.map +1 -0
- package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
- package/runtime/lib/worklet/workletRefPool.js +22 -0
- package/runtime/lib/worklet/workletRefPool.js.map +1 -0
- package/runtime/src/backgroundSnapshot.ts +452 -0
- package/runtime/src/compat/componentIs.ts +30 -0
- package/runtime/src/compat/initData.ts +140 -0
- package/runtime/src/compat/lynxComponent.ts +80 -0
- package/runtime/src/debug/debug.ts +9 -0
- package/runtime/src/debug/printSnapshot.ts +28 -0
- package/runtime/src/debug/profile.ts +54 -0
- package/runtime/src/document.ts +53 -0
- package/runtime/src/gesture/processGesture.ts +77 -0
- package/runtime/src/gesture/processGestureBagkround.ts +15 -0
- package/runtime/src/gesture/types.ts +39 -0
- package/runtime/src/hooks/react.ts +62 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
- package/runtime/src/hydrate.ts +364 -0
- package/runtime/src/index.ts +89 -0
- package/runtime/src/internal.ts +60 -0
- package/runtime/src/legacy-react-runtime/index.ts +40 -0
- package/runtime/src/lifecycle/delayUnmount.ts +77 -0
- package/runtime/src/lifecycle/destroy.ts +26 -0
- package/runtime/src/lifecycle/pass.ts +14 -0
- package/runtime/src/lifecycle/patchUpdate.ts +240 -0
- package/runtime/src/lifecycle/reload.ts +79 -0
- package/runtime/src/lifecycle/render.ts +46 -0
- package/runtime/src/lifecycleConstant.ts +16 -0
- package/runtime/src/list.ts +375 -0
- package/runtime/src/lynx/calledByNative.ts +132 -0
- package/runtime/src/lynx/component.ts +116 -0
- package/runtime/src/lynx/dynamic-js.ts +33 -0
- package/runtime/src/lynx/env.ts +110 -0
- package/runtime/src/lynx/injectLepusMethods.ts +53 -0
- package/runtime/src/lynx/lazy-bundle.ts +126 -0
- package/runtime/src/lynx/performance.ts +117 -0
- package/runtime/src/lynx/tt.ts +212 -0
- package/runtime/src/lynx-api.ts +374 -0
- package/runtime/src/lynx.ts +105 -0
- package/runtime/src/opcodes.ts +64 -0
- package/runtime/src/renderToOpcodes/constants.ts +24 -0
- package/runtime/src/renderToOpcodes/index.ts +301 -0
- package/runtime/src/root.ts +19 -0
- package/runtime/src/snapshot/event.ts +33 -0
- package/runtime/src/snapshot/gesture.ts +25 -0
- package/runtime/src/snapshot/platformInfo.ts +48 -0
- package/runtime/src/snapshot/ref.ts +151 -0
- package/runtime/src/snapshot/spread.ts +287 -0
- package/runtime/src/snapshot/workletEvent.ts +33 -0
- package/runtime/src/snapshot/workletRef.ts +63 -0
- package/runtime/src/snapshot.ts +576 -0
- package/runtime/src/snapshotPatch.ts +56 -0
- package/runtime/src/snapshotPatchApply.ts +117 -0
- package/runtime/src/utils.ts +35 -0
- package/runtime/src/worklet/ctx.ts +22 -0
- package/runtime/src/worklet/execMap.ts +50 -0
- package/runtime/src/worklet/functionality.ts +12 -0
- package/runtime/src/worklet/hmr.ts +26 -0
- package/runtime/src/worklet/indexMap.ts +20 -0
- package/runtime/src/worklet/jsImpl.ts +86 -0
- package/runtime/src/worklet/runWorklet.ts +88 -0
- package/runtime/src/worklet/workletRef.ts +229 -0
- package/runtime/src/worklet/workletRefPool.ts +25 -0
- package/transform/cjs/main.cjs +6 -0
- package/transform/cjs/main.d.cts +3 -0
- package/transform/cjs/package.json +3 -0
- package/transform/dist/wasm.cjs +8478 -0
- package/transform/index.d.ts +187 -0
- package/transform/main.js +15 -0
- package/types/react.d.ts +147 -0
- package/types/react.docs.d.ts +74 -0
- package/worklet-runtime/dist/dev.js +414 -0
- package/worklet-runtime/dist/dev.js.map +8 -0
- package/worklet-runtime/dist/main.js +414 -0
- package/worklet-runtime/dist/main.js.map +8 -0
- package/worklet-runtime/lib/api/element.d.ts +14 -0
- package/worklet-runtime/lib/api/element.js +71 -0
- package/worklet-runtime/lib/api/element.js.map +1 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
- package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
- package/worklet-runtime/lib/api/lynxApi.js +35 -0
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
- package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
- package/worklet-runtime/lib/bindings/bindings.js +61 -0
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
- package/worklet-runtime/lib/bindings/events.d.ts +7 -0
- package/worklet-runtime/lib/bindings/events.js +9 -0
- package/worklet-runtime/lib/bindings/events.js.map +1 -0
- package/worklet-runtime/lib/bindings/index.d.ts +4 -0
- package/worklet-runtime/lib/bindings/index.js +7 -0
- package/worklet-runtime/lib/bindings/index.js.map +1 -0
- package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
- package/worklet-runtime/lib/bindings/types.d.ts +35 -0
- package/worklet-runtime/lib/bindings/types.js +2 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +15 -0
- package/worklet-runtime/lib/global.js +2 -0
- package/worklet-runtime/lib/global.js.map +1 -0
- package/worklet-runtime/lib/index.d.ts +1 -0
- package/worklet-runtime/lib/index.js +12 -0
- package/worklet-runtime/lib/index.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
- package/worklet-runtime/lib/listeners.d.ts +2 -0
- package/worklet-runtime/lib/listeners.js +17 -0
- package/worklet-runtime/lib/listeners.js.map +1 -0
- package/worklet-runtime/lib/utils/profile.d.ts +1 -0
- package/worklet-runtime/lib/utils/profile.js +20 -0
- package/worklet-runtime/lib/utils/profile.js.map +1 -0
- package/worklet-runtime/lib/utils/version.d.ts +1 -0
- package/worklet-runtime/lib/utils/version.js +10 -0
- package/worklet-runtime/lib/utils/version.js.map +1 -0
- package/worklet-runtime/lib/workletRef.d.ts +12 -0
- package/worklet-runtime/lib/workletRef.js +50 -0
- package/worklet-runtime/lib/workletRef.js.map +1 -0
- package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
- package/worklet-runtime/lib/workletRuntime.js +128 -0
- package/worklet-runtime/lib/workletRuntime.js.map +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { useEffect, useMemo, useRef } from 'preact/hooks';
|
|
5
|
+
/**
|
|
6
|
+
* `useLynxGlobalEventListener` help you `addListener` as early as possible.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* Use this hooks to listen to event 'exposure' and event 'disexposure'
|
|
11
|
+
*
|
|
12
|
+
* ```jsx
|
|
13
|
+
* function App() {
|
|
14
|
+
* useLynxGlobalEventListener('exposure', (e) => {
|
|
15
|
+
* console.log("exposure", e)
|
|
16
|
+
* })
|
|
17
|
+
* useLynxGlobalEventListener('disexposure', (e) => {
|
|
18
|
+
* console.log("disexposure", e)
|
|
19
|
+
* })
|
|
20
|
+
* return (
|
|
21
|
+
* <view
|
|
22
|
+
* style='width: 100px; height: 100px; background-color: red;'
|
|
23
|
+
* exposure-id='a'
|
|
24
|
+
* />
|
|
25
|
+
* )
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param eventName - Event name to listen
|
|
30
|
+
* @param listener - Event handler
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export function useLynxGlobalEventListener(eventName, listener) {
|
|
34
|
+
'background only';
|
|
35
|
+
const previousArgsRef = useRef();
|
|
36
|
+
useMemo(() => {
|
|
37
|
+
if (previousArgsRef.current) {
|
|
38
|
+
const [eventName, listener] = previousArgsRef.current;
|
|
39
|
+
lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
|
|
40
|
+
}
|
|
41
|
+
lynx.getJSModule('GlobalEventEmitter').addListener(eventName, listener);
|
|
42
|
+
previousArgsRef.current = [eventName, listener];
|
|
43
|
+
}, [eventName, listener]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
return () => {
|
|
46
|
+
if (previousArgsRef.current) {
|
|
47
|
+
const [eventName, listener] = previousArgsRef.current;
|
|
48
|
+
lynx.getJSModule('GlobalEventEmitter').removeListener(eventName, listener);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=useLynxGlobalEventListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLynxGlobalEventListener.js","sourceRoot":"","sources":["../../src/hooks/useLynxGlobalEventListener.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D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number>;
|
|
7
|
+
}
|
|
8
|
+
export interface Typed {
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function isEmptyDiffResult<K>(diffResult: DiffResult<K>): boolean;
|
|
12
|
+
export declare function diffArrayLepus<A extends Typed, B extends Typed>(before: A[], after: B[], isSameType: (a: A, b: B) => boolean, onDiffChildren: (a: A, b: B, oldIndex: number, newIndex: number) => void): DiffResult<B>;
|
|
13
|
+
export declare function diffArrayAction<T, K>(before: T[], diffResult: DiffResult<K>, onInsert: (node: K, target: T | undefined) => T, onRemove: (node: T) => void, onMove: (node: T, target: T | undefined) => void): T[];
|
|
14
|
+
export interface HydrationOptions {
|
|
15
|
+
skipUnRef?: boolean;
|
|
16
|
+
swap?: Record<number, number>;
|
|
17
|
+
}
|
|
18
|
+
export declare function hydrate(before: SnapshotInstance, after: SnapshotInstance, options?: HydrationOptions): void;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { __pendingListUpdates, componentAtIndexFactory, enqueueComponentFactory } from './list.js';
|
|
5
|
+
import { unref } from './snapshot/ref.js';
|
|
6
|
+
import { DynamicPartType, SnapshotInstance } from './snapshot.js';
|
|
7
|
+
import { isEmptyObject } from './utils.js';
|
|
8
|
+
export function isEmptyDiffResult(diffResult) {
|
|
9
|
+
const hasChanged = !isEmptyObject(diffResult.i)
|
|
10
|
+
|| !isEmptyObject(diffResult.m) || diffResult.r.length > 0;
|
|
11
|
+
return !hasChanged;
|
|
12
|
+
}
|
|
13
|
+
export function diffArrayLepus(before, after, isSameType, onDiffChildren) {
|
|
14
|
+
let lastPlacedIndex = 0;
|
|
15
|
+
const result = {
|
|
16
|
+
$$diff: true,
|
|
17
|
+
i: {},
|
|
18
|
+
r: [],
|
|
19
|
+
m: {},
|
|
20
|
+
};
|
|
21
|
+
const beforeMap = {};
|
|
22
|
+
for (let i = 0; i < before.length; i++) {
|
|
23
|
+
const node = before[i];
|
|
24
|
+
(beforeMap[node.type] ??= new Set()).add([node, i]);
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < after.length; i++) {
|
|
27
|
+
const afterNode = after[i];
|
|
28
|
+
const beforeNodes = beforeMap[afterNode.type];
|
|
29
|
+
let beforeNode;
|
|
30
|
+
if (beforeNodes
|
|
31
|
+
&& beforeNodes.size > 0
|
|
32
|
+
// @ts-expect-error TS does not know about iterator :)
|
|
33
|
+
&& (([beforeNode] = beforeNodes), beforeNode)
|
|
34
|
+
&& isSameType(beforeNode[0], afterNode)) {
|
|
35
|
+
// Reuse old node
|
|
36
|
+
beforeNodes.delete(beforeNode);
|
|
37
|
+
const oldIndex = beforeNode[1];
|
|
38
|
+
onDiffChildren(beforeNode[0], afterNode, oldIndex, i);
|
|
39
|
+
if (oldIndex < lastPlacedIndex) {
|
|
40
|
+
result.m[oldIndex] = i;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
lastPlacedIndex = oldIndex;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Create new node
|
|
49
|
+
result.i[i] = afterNode;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Delete
|
|
53
|
+
for (const k in beforeMap) {
|
|
54
|
+
for (const [, i] of beforeMap[k]) {
|
|
55
|
+
result.r.push(i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
// export function diffIterableLepus<A extends Typed, B extends Typed>(
|
|
61
|
+
// before: A[],
|
|
62
|
+
// after: Iterable<B>,
|
|
63
|
+
// isSameType: (a: A, b: B) => boolean,
|
|
64
|
+
// onDiffChildren: (a: A, b: B) => void
|
|
65
|
+
// ): DiffResult<B> {
|
|
66
|
+
// let returnResult = EMPTY_DIFF_RESULT as DiffResult<B>;
|
|
67
|
+
// let lastPlacedIndex = 0;
|
|
68
|
+
// const result: DiffResult<B> = {
|
|
69
|
+
// $$diff: true,
|
|
70
|
+
// i: {},
|
|
71
|
+
// r: [],
|
|
72
|
+
// m: {},
|
|
73
|
+
// };
|
|
74
|
+
// const beforeMap: Record<string, Set<[A, number]>> = {};
|
|
75
|
+
// for (let i = 0; i < before.length; i++) {
|
|
76
|
+
// let node = before[i];
|
|
77
|
+
// (beforeMap[node.type] ??= new Set()).add([node, i]);
|
|
78
|
+
// }
|
|
79
|
+
// let i = 0;
|
|
80
|
+
// for (const afterNode of after) {
|
|
81
|
+
// const beforeNodes = beforeMap[afterNode.type];
|
|
82
|
+
// let beforeNode: [A, number];
|
|
83
|
+
// if (beforeNodes && (([beforeNode] = beforeNodes), beforeNode) && isSameType(beforeNode[0], afterNode)) {
|
|
84
|
+
// // Reuse old node
|
|
85
|
+
// beforeNodes.delete(beforeNode);
|
|
86
|
+
// const oldIndex = beforeNode[1];
|
|
87
|
+
// onDiffChildren(beforeNode[0], afterNode);
|
|
88
|
+
// if (oldIndex < lastPlacedIndex) {
|
|
89
|
+
// result.m[oldIndex] = i;
|
|
90
|
+
// returnResult = result;
|
|
91
|
+
// i++;
|
|
92
|
+
// continue;
|
|
93
|
+
// } else {
|
|
94
|
+
// lastPlacedIndex = oldIndex;
|
|
95
|
+
// }
|
|
96
|
+
// } else {
|
|
97
|
+
// // Create new node
|
|
98
|
+
// result.i[i] = afterNode;
|
|
99
|
+
// returnResult = result;
|
|
100
|
+
// }
|
|
101
|
+
// i++;
|
|
102
|
+
// }
|
|
103
|
+
// // delete
|
|
104
|
+
// for (const k in beforeMap) {
|
|
105
|
+
// for (const [, i] of beforeMap[k]) {
|
|
106
|
+
// result.r.push(i);
|
|
107
|
+
// returnResult = result;
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
// return result;
|
|
111
|
+
// }
|
|
112
|
+
export function diffArrayAction(before, diffResult, onInsert, onRemove, onMove) {
|
|
113
|
+
if (isEmptyDiffResult(diffResult)) {
|
|
114
|
+
return before;
|
|
115
|
+
}
|
|
116
|
+
const deleteSet = new Set(diffResult.r);
|
|
117
|
+
const { i: insertMap, m: placementMap } = diffResult;
|
|
118
|
+
const moveTempMap = new Map();
|
|
119
|
+
let old;
|
|
120
|
+
let k = 0;
|
|
121
|
+
old = before[k];
|
|
122
|
+
// let current: T | null | undefined = null;
|
|
123
|
+
const result = [];
|
|
124
|
+
let i = 0; // index of the old list
|
|
125
|
+
let j = 0; // index of the new list
|
|
126
|
+
let remain = Object.keys(insertMap).length;
|
|
127
|
+
while (old || remain > 0) {
|
|
128
|
+
let keep = false;
|
|
129
|
+
if (old && deleteSet.has(j)) {
|
|
130
|
+
// delete
|
|
131
|
+
onRemove(old);
|
|
132
|
+
}
|
|
133
|
+
else if (old && placementMap[j] !== undefined) {
|
|
134
|
+
// save node to re-use
|
|
135
|
+
moveTempMap.set(placementMap[j], old);
|
|
136
|
+
remain++;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// insert node
|
|
140
|
+
let newNode = old;
|
|
141
|
+
if (moveTempMap.has(i)) {
|
|
142
|
+
// insert re-used node
|
|
143
|
+
newNode = moveTempMap.get(i);
|
|
144
|
+
keep = true;
|
|
145
|
+
onMove(newNode, old);
|
|
146
|
+
remain--;
|
|
147
|
+
}
|
|
148
|
+
else if (insertMap[i] !== undefined) {
|
|
149
|
+
// insert new node
|
|
150
|
+
newNode = onInsert(insertMap[i], old);
|
|
151
|
+
keep = true;
|
|
152
|
+
remain--;
|
|
153
|
+
}
|
|
154
|
+
result.push(newNode);
|
|
155
|
+
i++;
|
|
156
|
+
}
|
|
157
|
+
if (old && !keep) {
|
|
158
|
+
old = before[++k];
|
|
159
|
+
j++;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
export function hydrate(before, after, options) {
|
|
165
|
+
after.__elements = before.__elements;
|
|
166
|
+
after.__element_root = before.__element_root;
|
|
167
|
+
if (!(options?.skipUnRef)) {
|
|
168
|
+
unref(before, false);
|
|
169
|
+
}
|
|
170
|
+
let swap;
|
|
171
|
+
if (swap = options?.swap) {
|
|
172
|
+
swap[before.__id] = after.__id;
|
|
173
|
+
}
|
|
174
|
+
after.__values?.forEach((value, index) => {
|
|
175
|
+
const old = before.__values[index];
|
|
176
|
+
if (value !== old) {
|
|
177
|
+
after.__values[index] = old;
|
|
178
|
+
after.setAttribute(index, value);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const { slot } = after.__snapshot_def;
|
|
182
|
+
if (!slot) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const beforeChildNodes = before.childNodes;
|
|
186
|
+
const afterChildNodes = after.childNodes;
|
|
187
|
+
slot.forEach(([type, elementIndex], index) => {
|
|
188
|
+
switch (type) {
|
|
189
|
+
case DynamicPartType.Slot:
|
|
190
|
+
case DynamicPartType.MultiChildren: {
|
|
191
|
+
// TODO: the following null assertions are not 100% safe
|
|
192
|
+
const v1 = beforeChildNodes[index];
|
|
193
|
+
const v2 = afterChildNodes[index];
|
|
194
|
+
hydrate(v1, v2, options);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case DynamicPartType.Children: {
|
|
198
|
+
const diffResult = diffArrayLepus(beforeChildNodes, afterChildNodes, (a, b) => a.type === b.type, (a, b) => {
|
|
199
|
+
hydrate(a, b, options);
|
|
200
|
+
});
|
|
201
|
+
diffArrayAction(beforeChildNodes, diffResult, (node, target) => {
|
|
202
|
+
node.ensureElements();
|
|
203
|
+
__InsertElementBefore(before.__elements[elementIndex], node.__element_root, target?.__element_root);
|
|
204
|
+
return node;
|
|
205
|
+
}, node => {
|
|
206
|
+
__RemoveElement(before.__elements[elementIndex], node.__element_root);
|
|
207
|
+
}, (node, target) => {
|
|
208
|
+
__RemoveElement(before.__elements[elementIndex], node.__element_root);
|
|
209
|
+
__InsertElementBefore(before.__elements[elementIndex], node.__element_root, target?.__element_root);
|
|
210
|
+
});
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case DynamicPartType.ListChildren: {
|
|
214
|
+
const removals = [];
|
|
215
|
+
const insertions = [];
|
|
216
|
+
const updateAction = [];
|
|
217
|
+
const diffResult = diffArrayLepus(beforeChildNodes, afterChildNodes, (a, b) => a.type === b.type, (a, b, oldIndex, newIndex) => {
|
|
218
|
+
if (JSON.stringify(a.__listItemPlatformInfo)
|
|
219
|
+
!== JSON.stringify(b.__listItemPlatformInfo)) {
|
|
220
|
+
updateAction.push({
|
|
221
|
+
...b.__listItemPlatformInfo,
|
|
222
|
+
from: newIndex,
|
|
223
|
+
to: newIndex,
|
|
224
|
+
// no flush
|
|
225
|
+
flush: false,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// Mark list-item which is rendered (has `__elements`) as DELETE
|
|
229
|
+
// so list platform will call `enqueueComponent` on it
|
|
230
|
+
// and will call `componentAtIndex` on the inserted one
|
|
231
|
+
// In this way:
|
|
232
|
+
// 1. we make sure `<list/>` for hydrate is like a leaf node
|
|
233
|
+
// 2. we avoid hydrate so modifying recycleMap can be avoid
|
|
234
|
+
// 3. the delete list-item is recycled for later use, so no waste
|
|
235
|
+
if (a.__elements) {
|
|
236
|
+
removals.push(oldIndex);
|
|
237
|
+
insertions.push(newIndex);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
for (const i of diffResult.r) {
|
|
241
|
+
removals.push(i);
|
|
242
|
+
}
|
|
243
|
+
for (const i in diffResult.i) {
|
|
244
|
+
insertions.push(Number(i));
|
|
245
|
+
}
|
|
246
|
+
for (const i in diffResult.m) {
|
|
247
|
+
removals.push(Number(i));
|
|
248
|
+
insertions.push(diffResult.m[i]);
|
|
249
|
+
}
|
|
250
|
+
insertions.sort((a, b) => a - b);
|
|
251
|
+
removals.sort((a, b) => a - b);
|
|
252
|
+
const info = {
|
|
253
|
+
insertAction: insertions.map((it) => ({
|
|
254
|
+
position: it,
|
|
255
|
+
type: afterChildNodes[it].type,
|
|
256
|
+
...afterChildNodes[it].__listItemPlatformInfo,
|
|
257
|
+
})),
|
|
258
|
+
removeAction: removals,
|
|
259
|
+
updateAction,
|
|
260
|
+
};
|
|
261
|
+
const listElement = before.__elements[elementIndex];
|
|
262
|
+
__SetAttribute(listElement, 'update-list-info', info);
|
|
263
|
+
__UpdateListCallbacks(listElement, componentAtIndexFactory(afterChildNodes), enqueueComponentFactory());
|
|
264
|
+
// The `before` & `after` target to the same list element, so we need to
|
|
265
|
+
// avoid the newly created list's (behind snapshot instance `after`) "update-list-info" being recorded.
|
|
266
|
+
delete __pendingListUpdates.values[after.__id];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=hydrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAgB3C,MAAM,UAAU,iBAAiB,CAAI,UAAyB;IAC5D,MAAM,UAAU,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;WAC1C,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7D,OAAO,CAAC,UAAU,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MAAW,EACX,KAAU,EACV,UAAmC,EACnC,cAAwE;IAExE,IAAI,e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E,EAAE,EAAE,CAAC,CAAC;wBACpC,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,eAAe,CAAC,EAAE,CAAE,CAAC,IAAI;wBAC/B,GAAG,eAAe,CAAC,EAAE,CAAE,CAAC,sBAAsB;qBAC/C,CAAC,CAAC;oBACH,YAAY,EAAE,QAAQ;oBACtB,YAAY;iBACb,CAAC;gBAEF,MAAM,WAAW,GAAG,MAAM,CAAC,UAAW,CAAC,YAAY,CAAE,CAAC;gBACtD,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;gBACtD,qBAAqB,CACnB,WAAW,EACX,uBAAuB,CAAC,eAAe,CAAC,EACxC,uBAAuB,EAAE,CAC1B,CAAC;gBAEF,wEAAwE;gBACxE,uGAAuG;gBACvG,OAAO,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './lynx.js';
|
|
2
|
+
import './lynx/component.js';
|
|
3
|
+
import { Children, Fragment, Suspense, createElement, createRef, forwardRef, isValidElement, memo, useSyncExternalStore } from 'preact/compat';
|
|
4
|
+
export { Component, createContext } from 'preact';
|
|
5
|
+
export { PureComponent } from 'preact/compat';
|
|
6
|
+
export * from './hooks/react.js';
|
|
7
|
+
declare const lazy: typeof import('preact/compat').lazy;
|
|
8
|
+
export { Children, createRef, Fragment, isValidElement, memo, forwardRef, Suspense, lazy, createElement, useSyncExternalStore, };
|
|
9
|
+
export * from './lynx-api.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import './lynx.js';
|
|
5
|
+
import './lynx/component.js';
|
|
6
|
+
import { Children, Component, Fragment, PureComponent, Suspense, lazy as backgroundLazy, createContext, createElement, createRef, forwardRef, isValidElement, memo, useSyncExternalStore, } from 'preact/compat';
|
|
7
|
+
import { useCallback, useContext, useDebugValue, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, } from './hooks/react.js';
|
|
8
|
+
import { mainThreadLazy } from './lynx/lazy-bundle.js';
|
|
9
|
+
export { Component, createContext } from 'preact';
|
|
10
|
+
export { PureComponent } from 'preact/compat';
|
|
11
|
+
export * from './hooks/react.js';
|
|
12
|
+
const lazy = __LEPUS__
|
|
13
|
+
? mainThreadLazy
|
|
14
|
+
: backgroundLazy;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export default {
|
|
19
|
+
// hooks
|
|
20
|
+
useState,
|
|
21
|
+
useReducer,
|
|
22
|
+
useEffect,
|
|
23
|
+
useLayoutEffect,
|
|
24
|
+
useRef,
|
|
25
|
+
useImperativeHandle,
|
|
26
|
+
useMemo,
|
|
27
|
+
useCallback,
|
|
28
|
+
useContext,
|
|
29
|
+
useDebugValue,
|
|
30
|
+
useSyncExternalStore,
|
|
31
|
+
createContext,
|
|
32
|
+
createRef,
|
|
33
|
+
Fragment,
|
|
34
|
+
isValidElement,
|
|
35
|
+
Children,
|
|
36
|
+
Component,
|
|
37
|
+
PureComponent,
|
|
38
|
+
memo,
|
|
39
|
+
forwardRef,
|
|
40
|
+
Suspense,
|
|
41
|
+
lazy,
|
|
42
|
+
createElement,
|
|
43
|
+
};
|
|
44
|
+
export { Children, createRef, Fragment, isValidElement, memo, forwardRef, Suspense, lazy, createElement, useSyncExternalStore, };
|
|
45
|
+
export * from './lynx-api.js';
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,WAA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
3
|
+
import { DynamicPartType, SnapshotInstance, snapshotManager, __page, __pageId, createSnapshot } from './snapshot.js';
|
|
4
|
+
export { __page, __pageId, __root };
|
|
5
|
+
export { SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager };
|
|
6
|
+
export declare const __DynamicPartSlot: DynamicPartType;
|
|
7
|
+
export declare const __DynamicPartMultiChildren: DynamicPartType;
|
|
8
|
+
export declare const __DynamicPartChildren: DynamicPartType;
|
|
9
|
+
export declare const __DynamicPartListChildren: DynamicPartType;
|
|
10
|
+
export declare const __DynamicPartChildren_0: [DynamicPartType, number][];
|
|
11
|
+
export { updateSpread } from './snapshot/spread.js';
|
|
12
|
+
export { updateEvent } from './snapshot/event.js';
|
|
13
|
+
export { updateRef, transformRef } from './snapshot/ref.js';
|
|
14
|
+
export { updateWorkletEvent } from './snapshot/workletEvent.js';
|
|
15
|
+
export { updateWorkletRef } from './snapshot/workletRef.js';
|
|
16
|
+
export { updateGesture } from './snapshot/gesture.js';
|
|
17
|
+
export { updateListItemPlatformInfo } from './snapshot/platformInfo.js';
|
|
18
|
+
export { options, Component, } from 'preact';
|
|
19
|
+
export type { Options } from 'preact';
|
|
20
|
+
export { loadDynamicJS, __dynamicImport } from './lynx/dynamic-js.js';
|
|
21
|
+
export { withInitDataInState } from './compat/initData.js';
|
|
22
|
+
export { wrapWithLynxComponent } from './compat/lynxComponent.js';
|
|
23
|
+
export { loadLazyBundle } from './lynx/lazy-bundle.js';
|
|
24
|
+
export { transformToWorklet } from './worklet/runWorklet.js';
|
|
25
|
+
export { registerWorkletOnBackground } from './worklet/hmr.js';
|
|
26
|
+
export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { Suspense, createElement, lazy } from 'preact/compat';
|
|
5
|
+
import { factory as factory2 } from './compat/componentIs.js';
|
|
6
|
+
import { useMemo } from './hooks/react.js';
|
|
7
|
+
import { snapshotCreateList } from './list.js';
|
|
8
|
+
import { loadLazyBundle } from './lynx/lazy-bundle.js';
|
|
9
|
+
import { __root } from './root.js';
|
|
10
|
+
import { DynamicPartType, SnapshotInstance, snapshotManager, __page, __pageId, createSnapshot } from './snapshot.js';
|
|
11
|
+
export { __page, __pageId, __root };
|
|
12
|
+
export { SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager };
|
|
13
|
+
export const __DynamicPartSlot = DynamicPartType.Slot;
|
|
14
|
+
export const __DynamicPartMultiChildren = DynamicPartType.MultiChildren;
|
|
15
|
+
export const __DynamicPartChildren = DynamicPartType.Children;
|
|
16
|
+
export const __DynamicPartListChildren = DynamicPartType.ListChildren;
|
|
17
|
+
export const __DynamicPartChildren_0 = [[DynamicPartType.Children, 0]];
|
|
18
|
+
export { updateSpread } from './snapshot/spread.js';
|
|
19
|
+
export { updateEvent } from './snapshot/event.js';
|
|
20
|
+
export { updateRef, transformRef } from './snapshot/ref.js';
|
|
21
|
+
export { updateWorkletEvent } from './snapshot/workletEvent.js';
|
|
22
|
+
export { updateWorkletRef } from './snapshot/workletRef.js';
|
|
23
|
+
export { updateGesture } from './snapshot/gesture.js';
|
|
24
|
+
export { updateListItemPlatformInfo } from './snapshot/platformInfo.js';
|
|
25
|
+
export { options,
|
|
26
|
+
// Component is not an internal API, but refresh needs it from 'react/internal'
|
|
27
|
+
Component, } from 'preact';
|
|
28
|
+
export { loadDynamicJS, __dynamicImport } from './lynx/dynamic-js.js';
|
|
29
|
+
export { withInitDataInState } from './compat/initData.js';
|
|
30
|
+
export { wrapWithLynxComponent } from './compat/lynxComponent.js';
|
|
31
|
+
/**
|
|
32
|
+
* @internal a polyfill for <component is=? />
|
|
33
|
+
*/
|
|
34
|
+
export const __ComponentIsPolyfill = /* @__PURE__ */ factory2(
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
36
|
+
{ Suspense, lazy, createElement, useMemo }, loadLazyBundle);
|
|
37
|
+
export { loadLazyBundle } from './lynx/lazy-bundle.js';
|
|
38
|
+
export { transformToWorklet } from './worklet/runWorklet.js';
|
|
39
|
+
export { registerWorkletOnBackground } from './worklet/hmr.js';
|
|
40
|
+
export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
|
|
41
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC;AAEjF,MAAM,CAAC,MAAM,iBAAiB,GAAoB,eAAe,CAAC,IAAI,CAAC;AACvE,MAAM,CAAC,MAAM,0BAA0B,GAAoB,eAAe,CAAC,aAAa,CAAC;AACzF,MAAM,CAAC,MAAM,qBAAqB,GAAoB,eAAe,CAAC,QAAQ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T>(value: T): T | undefined | null;
|
|
2
|
+
export { ComponentFromReactRuntime as Component } from '../compat/lynxComponent.js';
|
|
3
|
+
export { ComponentFromReactRuntime as PureComponent } from '../compat/lynxComponent.js';
|
|
4
|
+
export { createContext } from 'preact';
|
|
5
|
+
export { lazy } from 'preact/compat';
|
|
6
|
+
export { useState, useReducer, useEffect, useMemo, useCallback } from '../hooks/react.js';
|
|
7
|
+
export { __runInJS };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { createContext } from 'preact';
|
|
5
|
+
import { lazy } from 'preact/compat';
|
|
6
|
+
import { ComponentFromReactRuntime as Component, ComponentFromReactRuntime as PureComponent, } from '../compat/lynxComponent.js';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useReducer, useState } from '../hooks/react.js';
|
|
8
|
+
/* v8 ignore next 3 */
|
|
9
|
+
function __runInJS(value) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
// should mirror @lynx-js/react-runtime's exports
|
|
13
|
+
export { ComponentFromReactRuntime as Component } from '../compat/lynxComponent.js';
|
|
14
|
+
export { ComponentFromReactRuntime as PureComponent } from '../compat/lynxComponent.js';
|
|
15
|
+
export { createContext } from 'preact';
|
|
16
|
+
export { lazy } from 'preact/compat';
|
|
17
|
+
export { useState, useReducer, useEffect, useMemo, useCallback /*, useInstance */ } from '../hooks/react.js';
|
|
18
|
+
export { __runInJS };
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export default {
|
|
23
|
+
Component,
|
|
24
|
+
PureComponent,
|
|
25
|
+
createContext,
|
|
26
|
+
lazy,
|
|
27
|
+
useState,
|
|
28
|
+
useReducer,
|
|
29
|
+
useEffect,
|
|
30
|
+
useMemo,
|
|
31
|
+
useCallback,
|
|
32
|
+
__runInJS,
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/legacy-react-runtime/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EACL,yBAAyB,IAAI,SAAS,EACtC,yBAAyB,IAAI,aAAa,GAC3C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE1F,sBAAsB;AACtB,SAAS,SAAS,CAAI,KAAQ;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iDAAiD;AACjD,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB;;GAEG;AACH,eAAe;IACb,SAAS;IACT,aAAa;IACb,aAAa;IACb,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,SAAS;IACT,OAAO;IACP,WAAW;IACX,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type DelayedUnmounts = (() => void)[];
|
|
2
|
+
declare function takeDelayedUnmounts(): DelayedUnmounts;
|
|
3
|
+
declare function runDelayedUnmounts(delayedUnmounts: DelayedUnmounts): void;
|
|
4
|
+
/**
|
|
5
|
+
* Delay `componentWillUnmount` until main thread patching finishes.
|
|
6
|
+
*/
|
|
7
|
+
declare function initDelayUnmount(): void;
|
|
8
|
+
export { initDelayUnmount, takeDelayedUnmounts, runDelayedUnmounts };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { options } from 'preact';
|
|
5
|
+
import { CATCH_ERROR, COMPONENT, DIFF, VNODE } from '../renderToOpcodes/constants.js';
|
|
6
|
+
let delayedUnmounts = [];
|
|
7
|
+
let parentVNode;
|
|
8
|
+
function takeDelayedUnmounts() {
|
|
9
|
+
const ret = delayedUnmounts;
|
|
10
|
+
delayedUnmounts = [];
|
|
11
|
+
// not clearing `parentVNode` here, which would be cleared before next diff in `options[DIFF]`
|
|
12
|
+
return ret;
|
|
13
|
+
}
|
|
14
|
+
function runDelayedUnmounts(delayedUnmounts) {
|
|
15
|
+
for (const fn of delayedUnmounts) {
|
|
16
|
+
fn();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Delay `componentWillUnmount` until main thread patching finishes.
|
|
21
|
+
*/
|
|
22
|
+
function initDelayUnmount() {
|
|
23
|
+
const oldUnmount = options.unmount;
|
|
24
|
+
options.unmount = (vnode) => {
|
|
25
|
+
if (!parentVNode) {
|
|
26
|
+
// `parentVNode` is the first vnode to unmount,
|
|
27
|
+
// which is needed to find proper error boundary when running `componentWillUnmount`.
|
|
28
|
+
// Shallow copy vnode to prevent modification to vnode in preact unmounting process.
|
|
29
|
+
parentVNode = { ...vnode };
|
|
30
|
+
const oldDiff = options[DIFF];
|
|
31
|
+
options[DIFF] = (vnode) => {
|
|
32
|
+
// A new diff indicates that the unmounting process of parentVNode is finished.
|
|
33
|
+
parentVNode = undefined;
|
|
34
|
+
options[DIFF] = oldDiff;
|
|
35
|
+
oldDiff?.(vnode);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const component = vnode[COMPONENT];
|
|
39
|
+
if (component) {
|
|
40
|
+
if (oldUnmount) {
|
|
41
|
+
const vnode_clone = { ...vnode };
|
|
42
|
+
delayedUnmounts.push(() => {
|
|
43
|
+
const v = vnode_clone[COMPONENT][VNODE];
|
|
44
|
+
vnode_clone[COMPONENT][VNODE] = vnode_clone;
|
|
45
|
+
oldUnmount?.(vnode_clone);
|
|
46
|
+
vnode_clone[COMPONENT][VNODE] = v;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (component.componentWillUnmount) {
|
|
50
|
+
const unmount = component.componentWillUnmount;
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
component.componentWillUnmount = undefined;
|
|
53
|
+
const parentVNode_ = parentVNode;
|
|
54
|
+
delayedUnmounts.push(() => {
|
|
55
|
+
try {
|
|
56
|
+
component.componentWillUnmount = unmount;
|
|
57
|
+
component.componentWillUnmount();
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
options[CATCH_ERROR](e, parentVNode_);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export { initDelayUnmount, takeDelayedUnmounts, runDelayedUnmounts };
|
|
68
|
+
//# sourceMappingURL=delayUnmount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delayUnmount.js","sourceRoot":"","sources":["../../src/lifecycle/delayUnmount.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAA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