@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,301 @@
|
|
|
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
|
+
|
|
5
|
+
// modified from preact-render-to-string@6.0.3
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
|
|
8
|
+
import { Fragment, h, options } from 'preact';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
CHILDREN,
|
|
12
|
+
COMMIT,
|
|
13
|
+
COMPONENT,
|
|
14
|
+
DIFF,
|
|
15
|
+
DIFFED,
|
|
16
|
+
DIRTY,
|
|
17
|
+
NEXT_STATE,
|
|
18
|
+
PARENT,
|
|
19
|
+
RENDER,
|
|
20
|
+
SKIP_EFFECTS,
|
|
21
|
+
VNODE,
|
|
22
|
+
} from './constants.js';
|
|
23
|
+
|
|
24
|
+
/** @typedef {import('preact').VNode} VNode */
|
|
25
|
+
|
|
26
|
+
const EMPTY_ARR = [];
|
|
27
|
+
const isArray = /* @__PURE__ */ Array.isArray;
|
|
28
|
+
const assign = /* @__PURE__ */ Object.assign;
|
|
29
|
+
|
|
30
|
+
// Global state for the current render pass
|
|
31
|
+
let beforeDiff, afterDiff, renderHook, ummountHook;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Render Preact JSX + Components to an HTML string.
|
|
35
|
+
* @param {VNode} vnode JSX Element / VNode to render
|
|
36
|
+
* @param {object} [context] Initial root context object
|
|
37
|
+
*/
|
|
38
|
+
export function renderToString(vnode: any, context: any): any[] {
|
|
39
|
+
// Performance optimization: `renderToString` is synchronous and we
|
|
40
|
+
// therefore don't execute any effects. To do that we pass an empty
|
|
41
|
+
// array to `options._commit` (`__c`). But we can go one step further
|
|
42
|
+
// and avoid a lot of dirty checks and allocations by setting
|
|
43
|
+
// `options._skipEffects` (`__s`) too.
|
|
44
|
+
const previousSkipEffects = options[SKIP_EFFECTS];
|
|
45
|
+
options[SKIP_EFFECTS] = true;
|
|
46
|
+
|
|
47
|
+
// store options hooks once before each synchronous render call
|
|
48
|
+
beforeDiff = options[DIFF];
|
|
49
|
+
afterDiff = options[DIFFED];
|
|
50
|
+
renderHook = options[RENDER];
|
|
51
|
+
ummountHook = options.unmount;
|
|
52
|
+
|
|
53
|
+
const parent = h(Fragment, null);
|
|
54
|
+
parent[CHILDREN] = [vnode];
|
|
55
|
+
|
|
56
|
+
const opcodes = [];
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
_renderToString(
|
|
60
|
+
vnode,
|
|
61
|
+
context || EMPTY_OBJ,
|
|
62
|
+
false,
|
|
63
|
+
undefined,
|
|
64
|
+
parent,
|
|
65
|
+
opcodes,
|
|
66
|
+
);
|
|
67
|
+
} finally {
|
|
68
|
+
// options._commit, we don't schedule any effects in this library right now,
|
|
69
|
+
// so we can pass an empty queue to this hook.
|
|
70
|
+
if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);
|
|
71
|
+
options[SKIP_EFFECTS] = previousSkipEffects;
|
|
72
|
+
EMPTY_ARR.length = 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return opcodes;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Installed as setState/forceUpdate for function components
|
|
79
|
+
function markAsDirty() {
|
|
80
|
+
this.__d = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const EMPTY_OBJ = {};
|
|
84
|
+
|
|
85
|
+
export const __OpBegin = 0;
|
|
86
|
+
export const __OpEnd = 1;
|
|
87
|
+
export const __OpAttr = 2;
|
|
88
|
+
export const __OpText = 3;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {VNode} vnode
|
|
92
|
+
* @param {Record<string, unknown>} context
|
|
93
|
+
*/
|
|
94
|
+
function renderClassComponent(vnode, context) {
|
|
95
|
+
let type = /** @type {import("preact").ComponentClass<typeof vnode.props>} */ (vnode.type);
|
|
96
|
+
|
|
97
|
+
let c = new type(vnode.props, context);
|
|
98
|
+
|
|
99
|
+
vnode[COMPONENT] = c;
|
|
100
|
+
c[VNODE] = vnode;
|
|
101
|
+
|
|
102
|
+
c.props = vnode.props;
|
|
103
|
+
c.context = context;
|
|
104
|
+
// turn off stateful re-rendering:
|
|
105
|
+
c[DIRTY] = true;
|
|
106
|
+
|
|
107
|
+
if (c.state == null) c.state = EMPTY_OBJ;
|
|
108
|
+
|
|
109
|
+
if (c[NEXT_STATE] == null) {
|
|
110
|
+
c[NEXT_STATE] = c.state;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (type.getDerivedStateFromProps) {
|
|
114
|
+
c.state = assign(
|
|
115
|
+
{},
|
|
116
|
+
c.state,
|
|
117
|
+
type.getDerivedStateFromProps(c.props, c.state),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (renderHook) renderHook(vnode);
|
|
122
|
+
|
|
123
|
+
return c.render(c.props, c.state, context);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Recursively render VNodes to HTML.
|
|
128
|
+
* @param {VNode|any} vnode
|
|
129
|
+
* @param {any} context
|
|
130
|
+
* @param {boolean} isSvgMode
|
|
131
|
+
* @param {any} selectValue
|
|
132
|
+
* @param {VNode} parent
|
|
133
|
+
* @param opcodes
|
|
134
|
+
*/
|
|
135
|
+
function _renderToString(
|
|
136
|
+
vnode,
|
|
137
|
+
context,
|
|
138
|
+
isSvgMode,
|
|
139
|
+
selectValue,
|
|
140
|
+
parent,
|
|
141
|
+
opcodes,
|
|
142
|
+
) {
|
|
143
|
+
// Ignore non-rendered VNodes/values
|
|
144
|
+
if (vnode == null || vnode === true || vnode === false || vnode === '') {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Text VNodes: escape as HTML
|
|
149
|
+
if (typeof vnode !== 'object') {
|
|
150
|
+
if (typeof vnode === 'function') return;
|
|
151
|
+
|
|
152
|
+
opcodes.push(__OpText, vnode + '');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Recurse into children / Arrays
|
|
157
|
+
if (isArray(vnode)) {
|
|
158
|
+
parent[CHILDREN] = vnode;
|
|
159
|
+
for (let i = 0; i < vnode.length; i++) {
|
|
160
|
+
let child = vnode[i];
|
|
161
|
+
if (child == null || typeof child === 'boolean') continue;
|
|
162
|
+
|
|
163
|
+
_renderToString(child, context, isSvgMode, selectValue, parent, opcodes);
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// VNodes have {constructor:undefined} to prevent JSON injection:
|
|
169
|
+
// if (vnode.constructor !== undefined) return;
|
|
170
|
+
|
|
171
|
+
vnode[PARENT] = parent;
|
|
172
|
+
if (beforeDiff) beforeDiff(vnode);
|
|
173
|
+
|
|
174
|
+
let type = vnode.type,
|
|
175
|
+
props = vnode.props,
|
|
176
|
+
cctx = context,
|
|
177
|
+
contextType,
|
|
178
|
+
rendered,
|
|
179
|
+
component;
|
|
180
|
+
|
|
181
|
+
// Invoke rendering on Components
|
|
182
|
+
if (typeof type === 'function') {
|
|
183
|
+
if (type === Fragment) {
|
|
184
|
+
rendered = props.children;
|
|
185
|
+
} else {
|
|
186
|
+
contextType = type.contextType;
|
|
187
|
+
if (contextType != null) {
|
|
188
|
+
let provider = context[contextType.__c];
|
|
189
|
+
cctx = provider ? provider.props.value : contextType.__;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (type.prototype && typeof type.prototype.render === 'function') {
|
|
193
|
+
rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx);
|
|
194
|
+
component = vnode[COMPONENT];
|
|
195
|
+
} else {
|
|
196
|
+
component = {
|
|
197
|
+
__v: vnode,
|
|
198
|
+
props,
|
|
199
|
+
context: cctx,
|
|
200
|
+
// silently drop state updates
|
|
201
|
+
setState: markAsDirty,
|
|
202
|
+
forceUpdate: markAsDirty,
|
|
203
|
+
__d: true,
|
|
204
|
+
// hooks
|
|
205
|
+
__h: [],
|
|
206
|
+
};
|
|
207
|
+
vnode[COMPONENT] = component;
|
|
208
|
+
component.constructor = type;
|
|
209
|
+
component.render = doRender;
|
|
210
|
+
|
|
211
|
+
// If a hook invokes setState() to invalidate the component during rendering,
|
|
212
|
+
// re-render it up to 25 times to allow "settling" of memoized states.
|
|
213
|
+
// Note:
|
|
214
|
+
// This will need to be updated for Preact 11 to use internal.flags rather than component._dirty:
|
|
215
|
+
// https://github.com/preactjs/preact/blob/d4ca6fdb19bc715e49fd144e69f7296b2f4daa40/src/diff/component.js#L35-L44
|
|
216
|
+
let count = 0;
|
|
217
|
+
while (component[DIRTY] && count++ < 25) {
|
|
218
|
+
component[DIRTY] = false;
|
|
219
|
+
|
|
220
|
+
if (renderHook) renderHook(vnode);
|
|
221
|
+
|
|
222
|
+
rendered = component.render(props, component.state, cctx);
|
|
223
|
+
}
|
|
224
|
+
component[DIRTY] = true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (component.getChildContext != null) {
|
|
228
|
+
context = assign({}, context, component.getChildContext());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// When a component returns a Fragment node we flatten it in core, so we
|
|
233
|
+
// need to mirror that logic here too
|
|
234
|
+
let isTopLevelFragment = rendered != null && rendered.type === Fragment
|
|
235
|
+
&& rendered.key == null;
|
|
236
|
+
rendered = isTopLevelFragment ? rendered.props.children : rendered;
|
|
237
|
+
|
|
238
|
+
// Recurse into children before invoking the after-diff hook
|
|
239
|
+
_renderToString(rendered, context, isSvgMode, selectValue, vnode, opcodes);
|
|
240
|
+
if (afterDiff) afterDiff(vnode);
|
|
241
|
+
vnode[PARENT] = undefined;
|
|
242
|
+
|
|
243
|
+
if (ummountHook) ummountHook(vnode);
|
|
244
|
+
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
let children;
|
|
249
|
+
|
|
250
|
+
opcodes.push(__OpBegin, vnode);
|
|
251
|
+
|
|
252
|
+
for (let name in props) {
|
|
253
|
+
let v = props[name];
|
|
254
|
+
|
|
255
|
+
switch (name) {
|
|
256
|
+
case 'children':
|
|
257
|
+
children = v;
|
|
258
|
+
continue;
|
|
259
|
+
|
|
260
|
+
// VDOM-specific props
|
|
261
|
+
/* c8 ignore next 5 */
|
|
262
|
+
case 'key':
|
|
263
|
+
case 'ref':
|
|
264
|
+
case '__self':
|
|
265
|
+
case '__source':
|
|
266
|
+
continue;
|
|
267
|
+
|
|
268
|
+
default: {}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// write this attribute to the buffer
|
|
272
|
+
if (v != null && v !== false && typeof v !== 'function') {
|
|
273
|
+
opcodes.push(__OpAttr, name, v);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (typeof children === 'string') {
|
|
278
|
+
// single text child
|
|
279
|
+
opcodes.push(__OpText, children);
|
|
280
|
+
} else if (children != null && children !== false && children !== true) {
|
|
281
|
+
// recurse into this element VNode's children
|
|
282
|
+
_renderToString(children, context, false, selectValue, vnode, opcodes);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (afterDiff) afterDiff(vnode);
|
|
286
|
+
vnode[PARENT] = undefined;
|
|
287
|
+
if (ummountHook) ummountHook(vnode);
|
|
288
|
+
|
|
289
|
+
opcodes.push(__OpEnd);
|
|
290
|
+
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** The `.render()` method for a PFC backing instance. */
|
|
295
|
+
function doRender(props, state, context) {
|
|
296
|
+
return this.constructor(props, context);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export default renderToString;
|
|
300
|
+
export const render: typeof renderToString = renderToString;
|
|
301
|
+
export const renderToStaticMarkup: typeof renderToString = renderToString;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
|
|
5
|
+
import { SnapshotInstance } from './snapshot.js';
|
|
6
|
+
|
|
7
|
+
let __root: (SnapshotInstance | BackgroundSnapshotInstance) & { __jsx?: React.ReactNode };
|
|
8
|
+
|
|
9
|
+
function setRoot(root: typeof __root): void {
|
|
10
|
+
__root = root;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (__LEPUS__) {
|
|
14
|
+
setRoot(new SnapshotInstance('root'));
|
|
15
|
+
} else if (__JS__) {
|
|
16
|
+
setRoot(new BackgroundSnapshotInstance('root'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { __root, setRoot };
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { SnapshotInstance } from '../snapshot.js';
|
|
5
|
+
|
|
6
|
+
function updateEvent(
|
|
7
|
+
snapshot: SnapshotInstance,
|
|
8
|
+
expIndex: number,
|
|
9
|
+
_oldValue: any,
|
|
10
|
+
elementIndex: number,
|
|
11
|
+
eventType: string,
|
|
12
|
+
eventName: string,
|
|
13
|
+
spreadKey: string,
|
|
14
|
+
): void {
|
|
15
|
+
const value = snapshot.__values![expIndex];
|
|
16
|
+
let event;
|
|
17
|
+
if (!value) {
|
|
18
|
+
event = undefined;
|
|
19
|
+
} else if (typeof value === 'string') {
|
|
20
|
+
event = value;
|
|
21
|
+
} else {
|
|
22
|
+
event = `${snapshot.__id}:${expIndex}:${spreadKey}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// todo: reuseId?
|
|
26
|
+
|
|
27
|
+
snapshot.__values![expIndex] = event;
|
|
28
|
+
if (snapshot.__elements) {
|
|
29
|
+
__AddEvent(snapshot.__elements[elementIndex]!, eventType, eventName, event);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { updateEvent };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SnapshotInstance } from '../snapshot.js';
|
|
2
|
+
import { processGesture } from '../gesture/processGesture.js';
|
|
3
|
+
|
|
4
|
+
export function updateGesture(
|
|
5
|
+
snapshot: SnapshotInstance,
|
|
6
|
+
expIndex: number,
|
|
7
|
+
_oldValue: any,
|
|
8
|
+
elementIndex: number,
|
|
9
|
+
workletType: string,
|
|
10
|
+
): void {
|
|
11
|
+
if (!snapshot.__elements) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (__PROFILE__) {
|
|
15
|
+
console.profile('updateGesture');
|
|
16
|
+
}
|
|
17
|
+
const value = snapshot.__values![expIndex];
|
|
18
|
+
|
|
19
|
+
if (workletType === 'main-thread') {
|
|
20
|
+
processGesture(snapshot.__elements[elementIndex]!, value);
|
|
21
|
+
}
|
|
22
|
+
if (__PROFILE__) {
|
|
23
|
+
console.profileEnd();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __pendingListUpdates, ListUpdateInfoRecording } from '../list.js';
|
|
2
|
+
import { SnapshotInstance } from '../snapshot.js';
|
|
3
|
+
|
|
4
|
+
const platformInfoVirtualAttributes: Set<string> = /* @__PURE__ */ new Set<string>(['reuse-identifier']);
|
|
5
|
+
const platformInfoAttributes: Set<string> = /* @__PURE__ */ new Set<string>([
|
|
6
|
+
'reuse-identifier',
|
|
7
|
+
'full-span',
|
|
8
|
+
'item-key',
|
|
9
|
+
'sticky-top',
|
|
10
|
+
'sticky-bottom',
|
|
11
|
+
'estimated-height',
|
|
12
|
+
'estimated-height-px',
|
|
13
|
+
'estimated-main-axis-size-px',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
function updateListItemPlatformInfo(
|
|
17
|
+
ctx: SnapshotInstance,
|
|
18
|
+
index: number,
|
|
19
|
+
oldValue: any,
|
|
20
|
+
elementIndex: number,
|
|
21
|
+
): void {
|
|
22
|
+
const newValue = ctx.__listItemPlatformInfo = ctx.__values![index];
|
|
23
|
+
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const list = ctx.__parent;
|
|
26
|
+
if (list?.__snapshot_def.isListHolder) {
|
|
27
|
+
(__pendingListUpdates.values[list.__id] ??= new ListUpdateInfoRecording(list)).onSetAttribute(
|
|
28
|
+
ctx,
|
|
29
|
+
newValue,
|
|
30
|
+
oldValue,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// In this updater, unlike `updateSpread`, the shape of the value is guaranteed to be an fixed object.
|
|
35
|
+
// No adding / removing keys.
|
|
36
|
+
if (ctx.__elements) {
|
|
37
|
+
const e = ctx.__elements[elementIndex]!;
|
|
38
|
+
const value = ctx.__values![index];
|
|
39
|
+
for (const k in value) {
|
|
40
|
+
if (platformInfoVirtualAttributes.has(k)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
__SetAttribute(e, k, value[k]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { updateListItemPlatformInfo, platformInfoAttributes };
|
|
@@ -0,0 +1,151 @@
|
|
|
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 type { Worklet, WorkletRef } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
|
+
|
|
6
|
+
import { nextCommitTaskId } from '../lifecycle/patchUpdate.js';
|
|
7
|
+
import { SnapshotInstance, backgroundSnapshotInstanceManager } from '../snapshot.js';
|
|
8
|
+
import { workletUnRef } from './workletRef.js';
|
|
9
|
+
|
|
10
|
+
let globalRefPatch: Record<string, number | null> = {};
|
|
11
|
+
let globalRefsToRemove: Map</* commitId */ number, Map</* sign */ string, /* ref */ any>> = /* @__PURE__ */ new Map();
|
|
12
|
+
let globalRefsToSet: Map</* commitId */ number, Record<string, number>> = /* @__PURE__ */ new Map();
|
|
13
|
+
let nextRefId = 1;
|
|
14
|
+
|
|
15
|
+
function unref(snapshot: SnapshotInstance, recursive: boolean): void {
|
|
16
|
+
snapshot.__ref_set?.forEach(v => {
|
|
17
|
+
globalRefPatch[v] = null;
|
|
18
|
+
});
|
|
19
|
+
snapshot.__ref_set?.clear();
|
|
20
|
+
|
|
21
|
+
snapshot.__worklet_ref_set?.forEach(v => {
|
|
22
|
+
if (v) {
|
|
23
|
+
workletUnRef(v as Worklet | WorkletRef<unknown>);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
snapshot.__worklet_ref_set?.clear();
|
|
27
|
+
|
|
28
|
+
if (recursive) {
|
|
29
|
+
snapshot.childNodes.forEach(it => {
|
|
30
|
+
unref(it, recursive);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function applyRef(ref: any, value: any) {
|
|
36
|
+
// TODO: ref: exceptions thrown in user functions should be able to be caught by an Error Boundary
|
|
37
|
+
if (typeof ref == 'function') {
|
|
38
|
+
let hasRefUnmount = typeof ref._unmount == 'function';
|
|
39
|
+
if (hasRefUnmount) {
|
|
40
|
+
// @ts-ignore TS doesn't like moving narrowing checks into variables
|
|
41
|
+
ref._unmount();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!hasRefUnmount || value != null) {
|
|
45
|
+
// Store the cleanup function on the function
|
|
46
|
+
// instance object itself to avoid shape
|
|
47
|
+
// transitioning vnode
|
|
48
|
+
ref._unmount = ref(value);
|
|
49
|
+
}
|
|
50
|
+
} else ref.current = value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function updateBackgroundRefs(commitId: number): void {
|
|
54
|
+
const oldRefMap = globalRefsToRemove.get(commitId);
|
|
55
|
+
if (oldRefMap) {
|
|
56
|
+
globalRefsToRemove.delete(commitId);
|
|
57
|
+
for (let ref of oldRefMap.values()) {
|
|
58
|
+
applyRef(ref, null);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const newRefMap = globalRefsToSet.get(commitId);
|
|
62
|
+
if (newRefMap) {
|
|
63
|
+
globalRefsToSet.delete(commitId);
|
|
64
|
+
for (const sign in newRefMap) {
|
|
65
|
+
const ref = backgroundSnapshotInstanceManager.getValueBySign(sign);
|
|
66
|
+
if (ref) {
|
|
67
|
+
// TODO: ref: support __REF_FIRE_IMMEDIATELY__
|
|
68
|
+
const v = newRefMap[sign]
|
|
69
|
+
&& lynx.createSelectorQuery().selectUniqueID(
|
|
70
|
+
newRefMap[sign],
|
|
71
|
+
);
|
|
72
|
+
applyRef(ref, v);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function updateRef(
|
|
79
|
+
snapshot: SnapshotInstance,
|
|
80
|
+
expIndex: number,
|
|
81
|
+
oldValue: any,
|
|
82
|
+
elementIndex: number,
|
|
83
|
+
spreadKey: string,
|
|
84
|
+
): void {
|
|
85
|
+
const value = snapshot.__values![expIndex];
|
|
86
|
+
let ref;
|
|
87
|
+
if (!value) {
|
|
88
|
+
ref = undefined;
|
|
89
|
+
} else if (typeof value === 'string') {
|
|
90
|
+
ref = value;
|
|
91
|
+
} else {
|
|
92
|
+
ref = `${snapshot.__id}:${expIndex}:${spreadKey}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
snapshot.__values![expIndex] = ref;
|
|
96
|
+
if (snapshot.__elements && ref) {
|
|
97
|
+
__SetAttribute(snapshot.__elements[elementIndex]!, 'has-react-ref', true);
|
|
98
|
+
const uid = __GetElementUniqueID(snapshot.__elements[elementIndex]!);
|
|
99
|
+
globalRefPatch[ref] = uid;
|
|
100
|
+
snapshot.__ref_set ??= new Set();
|
|
101
|
+
snapshot.__ref_set.add(ref);
|
|
102
|
+
}
|
|
103
|
+
if (oldValue !== ref) {
|
|
104
|
+
snapshot.__ref_set?.delete(oldValue);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function takeGlobalRefPatchMap(): Record<string, number | null> {
|
|
109
|
+
const patch = globalRefPatch;
|
|
110
|
+
globalRefPatch = {};
|
|
111
|
+
return patch;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function transformRef(ref: unknown): Function | (object & Record<'current', unknown>) | null | undefined {
|
|
115
|
+
if (ref === undefined || ref === null) {
|
|
116
|
+
return ref;
|
|
117
|
+
}
|
|
118
|
+
if (typeof ref === 'function' || (typeof ref === 'object' && 'current' in ref)) {
|
|
119
|
+
if ('__ref' in ref) {
|
|
120
|
+
return ref;
|
|
121
|
+
}
|
|
122
|
+
return Object.defineProperty(ref, '__ref', { value: nextRefId++ });
|
|
123
|
+
}
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Elements' "ref" property should be a function, or an object created `
|
|
126
|
+
+ `by createRef(), but got [${typeof ref}] instead`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function markRefToRemove(sign: string, ref: unknown): void {
|
|
131
|
+
if (!ref) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
let oldRefs = globalRefsToRemove.get(nextCommitTaskId);
|
|
135
|
+
if (!oldRefs) {
|
|
136
|
+
oldRefs = new Map();
|
|
137
|
+
globalRefsToRemove.set(nextCommitTaskId, oldRefs);
|
|
138
|
+
}
|
|
139
|
+
oldRefs.set(sign, ref);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
updateRef,
|
|
144
|
+
takeGlobalRefPatchMap,
|
|
145
|
+
updateBackgroundRefs,
|
|
146
|
+
unref,
|
|
147
|
+
transformRef,
|
|
148
|
+
globalRefsToRemove,
|
|
149
|
+
globalRefsToSet,
|
|
150
|
+
markRefToRemove,
|
|
151
|
+
};
|