@lynx-js/react 0.126.1 → 0.126.2
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 +22 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +3 -3
- package/refresh/dist/index.js +1 -2
- package/refresh/package.json +1 -1
- package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
- package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
- package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
- package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
- package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
- package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
- package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
- package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
- package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
- package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
- package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
- package/runtime/__test__/element-template/native/reload.test.ts +10 -26
- package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
- package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
- package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
- package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
- package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
- package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
- package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
- package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
- package/runtime/__test__/element-template/vitest.config.ts +2 -1
- package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
- package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
- package/runtime/__test__/snapshot/lazy.test.js +44 -9
- package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
- package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
- package/runtime/__test__/snapshot/spread.test.jsx +22 -15
- package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
- package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
- package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +3 -2
- package/runtime/lazy/element-template-import.js +0 -4
- package/runtime/lazy/element-template-internal.js +18 -8
- package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
- package/runtime/lazy/element-template-jsx-runtime.js +1 -3
- package/runtime/lazy/element-template.js +1 -3
- package/runtime/lazy/import.js +0 -4
- package/runtime/lazy/internal.js +15 -1
- package/runtime/lazy/target.js +0 -21
- package/runtime/lib/core/hooks/react.d.ts +2 -0
- package/runtime/lib/core/hooks/react.js +2 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
- package/runtime/lib/core/lynx/runtime-version.js +51 -0
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
- package/runtime/lib/element-template/background/document.d.ts +1 -1
- package/runtime/lib/element-template/background/document.js +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +51 -19
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js +5 -6
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js +38 -22
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +4 -1
- package/runtime/lib/element-template/internal.js +6 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +4 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
- package/runtime/lib/element-template/runtime/list/list.js +3 -0
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
- package/runtime/lib/element-template/runtime/render/host.js +25 -0
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
- package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
- package/runtime/lib/element-template/runtime/template/handle.js +12 -4
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.js +13 -0
- package/runtime/lib/element-template/runtime-marker.js.map +1 -0
- package/runtime/lib/index.d.ts +1 -1
- package/runtime/lib/index.js +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +3 -1
- package/runtime/lib/internal.js +5 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +15 -6
- package/runtime/lib/lynx-api.js +13 -4
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/runtime-marker.js +13 -0
- package/runtime/lib/runtime-marker.js.map +1 -0
- package/runtime/lib/shared/component-stack.js +5 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/element.js +2 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +5 -14
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/src/core/hooks/react.ts +2 -0
- package/runtime/src/core/lynx/runtime-version.ts +62 -0
- package/runtime/src/element-template/background/document.ts +3 -3
- package/runtime/src/element-template/background/hydrate.ts +61 -29
- package/runtime/src/element-template/background/instance.ts +5 -6
- package/runtime/src/element-template/debug/profile.ts +48 -36
- package/runtime/src/element-template/index.ts +1 -1
- package/runtime/src/element-template/internal.ts +12 -1
- package/runtime/src/element-template/native/index.ts +4 -0
- package/runtime/src/element-template/runtime/list/list.ts +4 -0
- package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
- package/runtime/src/element-template/runtime/render/host.ts +51 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
- package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
- package/runtime/src/element-template/runtime/template/handle.ts +17 -7
- package/runtime/src/element-template/runtime-marker.ts +17 -0
- package/runtime/src/index.ts +1 -1
- package/runtime/src/internal.ts +10 -1
- package/runtime/src/lynx-api.ts +15 -6
- package/runtime/src/runtime-marker.ts +17 -0
- package/runtime/src/shared/component-stack.ts +5 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
- package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
- package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
- package/runtime/src/snapshot/lynx/element.ts +2 -0
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +1 -1
- package/runtime/src/worklet-runtime/hydrate.ts +1 -1
- package/runtime/src/worklet-runtime/workletRuntime.ts +5 -14
- package/runtime/types/types.d.ts +2 -0
- package/runtime/worklet-runtime/dev.js +4 -16
- package/runtime/worklet-runtime/main.js +1 -1
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +2 -2
- package/testing-library/dist/index.d.ts +2 -2
- package/testing-library/dist/plugins/index.js +1 -1
- package/testing-library/dist/pure.js +45 -44
- package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
- package/testing-library/node_modules/.bin/rsbuild +19 -6
- package/testing-library/node_modules/.bin/rspeedy +17 -4
- package/testing-library/node_modules/.bin/rstest +19 -6
- package/testing-library/package.json +2 -2
- package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
- package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
- package/testing-library/types/entry.d.ts +2 -2
- package/transform/.turbo/turbo-build$colon$wasm.log +68 -56
- package/transform/__test__/fixture.spec.js +17 -20
- package/transform/__test__/text.spec.js +75 -0
- package/transform/crates/swc_plugin_compat/lib.rs +4 -3
- package/transform/crates/swc_plugin_compat/napi.rs +4 -3
- package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
- package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
- package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
- package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
- package/transform/crates/swc_plugin_shake/lib.rs +1 -1
- package/transform/crates/swc_plugin_shake/napi.rs +1 -1
- package/transform/crates/swc_plugin_text/lib.rs +57 -16
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
- package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +7 -6
- package/transform/node_modules/.bin/esbuild +17 -4
- package/transform/node_modules/.bin/napi +17 -4
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +310 -114
- package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +10 -208
- package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
- package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
- package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
- package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
- package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
- package/runtime/lib/runtime-backend-marker.js +0 -6
- package/runtime/lib/runtime-backend-marker.js.map +0 -1
- package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
- package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
- package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
- package/runtime/src/runtime-backend-marker.ts +0 -7
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
- /package/runtime/lib/element-template/{runtime-backend-marker.d.ts → runtime-marker.d.ts} +0 -0
- /package/runtime/lib/{runtime-backend-marker.d.ts → runtime-marker.d.ts} +0 -0
|
@@ -1,313 +0,0 @@
|
|
|
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
|
-
import { __OpAttr, __OpBegin, __OpEnd, __OpPageEnd, __OpPageStart, __OpSlot, __OpText } from './render-to-opcodes.js';
|
|
6
|
-
import { elementTemplateIdentityKey, parseElementTemplateType } from '../../protocol/template-type.js';
|
|
7
|
-
import type {
|
|
8
|
-
RuntimeTypedElementAttributes,
|
|
9
|
-
SerializableValue,
|
|
10
|
-
TypedElementAttributesCommand,
|
|
11
|
-
} from '../../protocol/types.js';
|
|
12
|
-
import {
|
|
13
|
-
composeElementTemplateListAttributes,
|
|
14
|
-
createElementTemplateListState,
|
|
15
|
-
registerElementTemplateListItem,
|
|
16
|
-
registerElementTemplateListState,
|
|
17
|
-
} from '../list/list.js';
|
|
18
|
-
import type { ETListItemPlatformInfo } from '../list/list.js';
|
|
19
|
-
import { __etAttrPlanMap, hasMainThreadRefAttrSlot } from '../template/attr-slot-plan.js';
|
|
20
|
-
import type { EtAttrAdapter } from '../template/attr-slot-plan.js';
|
|
21
|
-
import {
|
|
22
|
-
createElementTemplateWithReservedHandle,
|
|
23
|
-
createTypedElementTemplateWithReservedHandle,
|
|
24
|
-
reserveElementTemplateId,
|
|
25
|
-
} from '../template/handle.js';
|
|
26
|
-
import type { MainThreadDynamicAttrSubtreeHandle } from '../template/main-thread-dynamic-attr-state.js';
|
|
27
|
-
import { prepareTypedElementAttributes } from '../template/typed-attributes.js';
|
|
28
|
-
|
|
29
|
-
const BUILTIN_RAW_TEXT_TEMPLATE_KEY = '_et_builtin_raw_text';
|
|
30
|
-
const TYPED_LIST_HOST_TYPE = 'list';
|
|
31
|
-
const EMPTY_LIST_ITEM_UIDS: readonly number[] = [];
|
|
32
|
-
|
|
33
|
-
type RenderAttributes = SerializableValue[] | RuntimeTypedElementAttributes | undefined;
|
|
34
|
-
|
|
35
|
-
export interface MainThreadCreateResult {
|
|
36
|
-
pageAttributes: TypedElementAttributesCommand | null;
|
|
37
|
-
rootRefs: ElementTemplateHandle[];
|
|
38
|
-
rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function appendChildToParent(
|
|
42
|
-
parentTemplateKey: string | null,
|
|
43
|
-
parentActiveChildSlot: ElementTemplateHandle[] | undefined,
|
|
44
|
-
parentListItemUids: number[] | undefined,
|
|
45
|
-
rootRefs: ElementTemplateHandle[],
|
|
46
|
-
rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][],
|
|
47
|
-
elementRef: ElementTemplateHandle,
|
|
48
|
-
uid: number,
|
|
49
|
-
subtreeHandles: MainThreadDynamicAttrSubtreeHandle[],
|
|
50
|
-
): void {
|
|
51
|
-
if (parentTemplateKey === null) {
|
|
52
|
-
rootRefs.push(elementRef);
|
|
53
|
-
rootSubtreeHandles.push(subtreeHandles);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (__DEV__ && !parentActiveChildSlot) {
|
|
58
|
-
throw new Error(`Template '${parentTemplateKey}' received a child outside of any child slot.`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
parentActiveChildSlot!.push(elementRef);
|
|
62
|
-
parentListItemUids?.push(uid);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function renderOpcodesIntoElementTemplate(
|
|
66
|
-
opcodes: unknown[],
|
|
67
|
-
): MainThreadCreateResult {
|
|
68
|
-
const rootRefs: ElementTemplateHandle[] = [];
|
|
69
|
-
const rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][] = [];
|
|
70
|
-
let pageAttributes: TypedElementAttributesCommand | null | undefined;
|
|
71
|
-
let isInsideAuthoredPage = false;
|
|
72
|
-
const typeStack: Array<string | null> = [null];
|
|
73
|
-
// The host type determines whether its payload is compiled slots or typed attributes.
|
|
74
|
-
const attributesStack: RenderAttributes[] = [undefined];
|
|
75
|
-
const childSlotsStack: Array<Array<Array<ElementTemplateHandle>> | undefined> = [undefined];
|
|
76
|
-
const listItemUidsStack: Array<number[] | undefined> = [undefined];
|
|
77
|
-
const materializationHandlesStack: Array<MainThreadDynamicAttrSubtreeHandle[] | undefined> = [undefined];
|
|
78
|
-
const activeChildSlotStack: Array<ElementTemplateHandle[] | undefined> = [undefined];
|
|
79
|
-
const activeListItemUidsStack: Array<number[] | undefined> = [undefined];
|
|
80
|
-
const listItemPlatformInfoStack: Array<ETListItemPlatformInfo | undefined> = [undefined];
|
|
81
|
-
const deferredListItemMarkerStack: boolean[] = [false];
|
|
82
|
-
let stackTop = 0;
|
|
83
|
-
|
|
84
|
-
for (let i = 0; i < opcodes.length;) {
|
|
85
|
-
const opcode = opcodes[i];
|
|
86
|
-
switch (opcode) {
|
|
87
|
-
case __OpBegin: {
|
|
88
|
-
if (__DEV__ && stackTop === 0 && pageAttributes !== undefined && !isInsideAuthoredPage) {
|
|
89
|
-
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
90
|
-
}
|
|
91
|
-
const vnode = opcodes[i + 1] as { type: string; props?: Record<string, unknown> };
|
|
92
|
-
const props = vnode.props;
|
|
93
|
-
const parentType = typeStack[stackTop];
|
|
94
|
-
stackTop += 1;
|
|
95
|
-
typeStack[stackTop] = vnode.type;
|
|
96
|
-
attributesStack[stackTop] = undefined;
|
|
97
|
-
childSlotsStack[stackTop] = undefined;
|
|
98
|
-
listItemUidsStack[stackTop] = undefined;
|
|
99
|
-
materializationHandlesStack[stackTop] = stackTop === 1 || parentType === TYPED_LIST_HOST_TYPE
|
|
100
|
-
? []
|
|
101
|
-
: materializationHandlesStack[stackTop - 1];
|
|
102
|
-
activeChildSlotStack[stackTop] = undefined;
|
|
103
|
-
activeListItemUidsStack[stackTop] = undefined;
|
|
104
|
-
listItemPlatformInfoStack[stackTop] = props?.['__listItemPlatformInfo'] as ETListItemPlatformInfo | undefined;
|
|
105
|
-
deferredListItemMarkerStack[stackTop] = props?.['isReady'] !== undefined;
|
|
106
|
-
i += 2;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case __OpEnd: {
|
|
110
|
-
if (__DEV__ && stackTop === 0) {
|
|
111
|
-
throw new Error('Instruction mismatch: Popped root frame at __OpEnd');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const type = typeStack[stackTop];
|
|
115
|
-
const attributes = attributesStack[stackTop];
|
|
116
|
-
const childSlots = childSlotsStack[stackTop];
|
|
117
|
-
const listItemUids = listItemUidsStack[stackTop];
|
|
118
|
-
const materializationHandles = materializationHandlesStack[stackTop]!;
|
|
119
|
-
const listItemPlatformInfo = listItemPlatformInfoStack[stackTop];
|
|
120
|
-
const deferredListItemMarker = deferredListItemMarkerStack[stackTop];
|
|
121
|
-
stackTop -= 1;
|
|
122
|
-
|
|
123
|
-
const concreteType = type!;
|
|
124
|
-
|
|
125
|
-
const parentTemplateKey = stackTop === 0 ? null : typeStack[stackTop]!;
|
|
126
|
-
const parentActiveChildSlot = activeChildSlotStack[stackTop];
|
|
127
|
-
const parentListItemUids = activeListItemUidsStack[stackTop];
|
|
128
|
-
|
|
129
|
-
if (concreteType === TYPED_LIST_HOST_TYPE) {
|
|
130
|
-
const listChildren = childSlots?.[0] ?? [];
|
|
131
|
-
const handleId = reserveElementTemplateId();
|
|
132
|
-
const preparedTypedAttributes = prepareTypedElementAttributes(
|
|
133
|
-
handleId,
|
|
134
|
-
attributes as RuntimeTypedElementAttributes | undefined,
|
|
135
|
-
);
|
|
136
|
-
const listState = createElementTemplateListState(
|
|
137
|
-
listItemUids ?? EMPTY_LIST_ITEM_UIDS,
|
|
138
|
-
preparedTypedAttributes,
|
|
139
|
-
);
|
|
140
|
-
const attrsWithCallbacks = composeElementTemplateListAttributes(
|
|
141
|
-
undefined,
|
|
142
|
-
listState,
|
|
143
|
-
);
|
|
144
|
-
const elementRef = createTypedElementTemplateWithReservedHandle(
|
|
145
|
-
handleId,
|
|
146
|
-
TYPED_LIST_HOST_TYPE,
|
|
147
|
-
attrsWithCallbacks,
|
|
148
|
-
null,
|
|
149
|
-
{ listChildren },
|
|
150
|
-
);
|
|
151
|
-
registerElementTemplateListState(handleId, listState, true, elementRef);
|
|
152
|
-
appendChildToParent(
|
|
153
|
-
parentTemplateKey,
|
|
154
|
-
parentActiveChildSlot,
|
|
155
|
-
parentListItemUids,
|
|
156
|
-
rootRefs,
|
|
157
|
-
rootSubtreeHandles,
|
|
158
|
-
elementRef,
|
|
159
|
-
handleId,
|
|
160
|
-
[],
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
i += 1;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (__DEV__ && parentTemplateKey === TYPED_LIST_HOST_TYPE) {
|
|
168
|
-
if (deferredListItemMarker) {
|
|
169
|
-
throw new Error('Element Template typed list does not support deferred list items.');
|
|
170
|
-
}
|
|
171
|
-
if (listItemPlatformInfo === undefined) {
|
|
172
|
-
throw new Error('Element Template typed list received a non-list-item root in logical slot $0.');
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const attrPlan = __etAttrPlanMap[concreteType];
|
|
177
|
-
const handleId = reserveElementTemplateId();
|
|
178
|
-
const attributeSlots = attributes as SerializableValue[] | undefined;
|
|
179
|
-
let preparedAttributeSlots = attributeSlots ?? null;
|
|
180
|
-
if (attrPlan !== undefined) {
|
|
181
|
-
preparedAttributeSlots = attributeSlots?.slice() ?? [];
|
|
182
|
-
for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {
|
|
183
|
-
const attrSlotIndex = attrPlan[planIndex] as number;
|
|
184
|
-
const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;
|
|
185
|
-
preparedAttributeSlots[attrSlotIndex] = adapter(
|
|
186
|
-
handleId,
|
|
187
|
-
attrSlotIndex,
|
|
188
|
-
preparedAttributeSlots[attrSlotIndex],
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const nativeTemplate = parseElementTemplateType(concreteType);
|
|
193
|
-
const hasMainThreadRef = hasMainThreadRefAttrSlot(concreteType);
|
|
194
|
-
const elementRef = createElementTemplateWithReservedHandle(
|
|
195
|
-
handleId,
|
|
196
|
-
nativeTemplate.templateKey,
|
|
197
|
-
nativeTemplate.bundleUrl,
|
|
198
|
-
preparedAttributeSlots,
|
|
199
|
-
childSlots ?? null,
|
|
200
|
-
);
|
|
201
|
-
if (hasMainThreadRef) {
|
|
202
|
-
materializationHandles.push({
|
|
203
|
-
uid: handleId,
|
|
204
|
-
ref: elementRef,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if (listItemPlatformInfo !== undefined) {
|
|
208
|
-
registerElementTemplateListItem(handleId, elementRef, {
|
|
209
|
-
// The native list identifies items by the same identity the template
|
|
210
|
-
// was registered under (sentinel stripped for the main card), so the
|
|
211
|
-
// update path (`resolveTypedListItem`) stays consistent with it.
|
|
212
|
-
templateKey: elementTemplateIdentityKey(nativeTemplate.templateKey, nativeTemplate.bundleUrl),
|
|
213
|
-
platformInfo: listItemPlatformInfo,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
appendChildToParent(
|
|
217
|
-
parentTemplateKey,
|
|
218
|
-
parentActiveChildSlot,
|
|
219
|
-
parentListItemUids,
|
|
220
|
-
rootRefs,
|
|
221
|
-
rootSubtreeHandles,
|
|
222
|
-
elementRef,
|
|
223
|
-
handleId,
|
|
224
|
-
materializationHandles,
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
i += 1;
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case __OpAttr: {
|
|
231
|
-
attributesStack[stackTop] = opcodes[i + 1] as RenderAttributes;
|
|
232
|
-
i += 2;
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
case __OpPageStart: {
|
|
236
|
-
if (__DEV__ && stackTop !== 0) {
|
|
237
|
-
throw new Error('Element Template authored <page /> must be the outermost element.');
|
|
238
|
-
}
|
|
239
|
-
if (__DEV__ && pageAttributes !== undefined) {
|
|
240
|
-
throw new Error('Element Template does not support multiple authored <page /> elements.');
|
|
241
|
-
}
|
|
242
|
-
if (__DEV__ && rootRefs.length !== 0) {
|
|
243
|
-
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
244
|
-
}
|
|
245
|
-
pageAttributes = opcodes[i + 1] as TypedElementAttributesCommand | null;
|
|
246
|
-
isInsideAuthoredPage = true;
|
|
247
|
-
i += 2;
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
case __OpPageEnd: {
|
|
251
|
-
if (__DEV__) {
|
|
252
|
-
isInsideAuthoredPage = false;
|
|
253
|
-
}
|
|
254
|
-
i += 1;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case __OpSlot: {
|
|
258
|
-
const slotId = opcodes[i + 1] as number;
|
|
259
|
-
if (__DEV__ && typeStack[stackTop] === TYPED_LIST_HOST_TYPE && slotId !== 0) {
|
|
260
|
-
throw new Error('Element Template typed list only supports logical slot $0.');
|
|
261
|
-
}
|
|
262
|
-
const childSlots = childSlotsStack[stackTop] ?? (childSlotsStack[stackTop] = []);
|
|
263
|
-
const activeChildSlot = childSlots[slotId] = [];
|
|
264
|
-
activeChildSlotStack[stackTop] = activeChildSlot;
|
|
265
|
-
if (typeStack[stackTop] === TYPED_LIST_HOST_TYPE && slotId === 0) {
|
|
266
|
-
const activeListItemUids = listItemUidsStack[stackTop] = [];
|
|
267
|
-
activeListItemUidsStack[stackTop] = activeListItemUids;
|
|
268
|
-
} else {
|
|
269
|
-
activeListItemUidsStack[stackTop] = undefined;
|
|
270
|
-
}
|
|
271
|
-
i += 2;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
case __OpText: {
|
|
275
|
-
if (__DEV__ && stackTop === 0 && pageAttributes !== undefined && !isInsideAuthoredPage) {
|
|
276
|
-
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
277
|
-
}
|
|
278
|
-
const text = opcodes[i + 1] as string;
|
|
279
|
-
const parentTemplateKey = stackTop === 0 ? null : typeStack[stackTop]!;
|
|
280
|
-
if (__DEV__ && parentTemplateKey === TYPED_LIST_HOST_TYPE) {
|
|
281
|
-
throw new Error('Element Template typed list received text logical child.');
|
|
282
|
-
}
|
|
283
|
-
const handleId = reserveElementTemplateId();
|
|
284
|
-
const textRef = createElementTemplateWithReservedHandle(
|
|
285
|
-
handleId,
|
|
286
|
-
BUILTIN_RAW_TEXT_TEMPLATE_KEY,
|
|
287
|
-
null,
|
|
288
|
-
[String(text)],
|
|
289
|
-
[],
|
|
290
|
-
);
|
|
291
|
-
if (parentTemplateKey === null) {
|
|
292
|
-
rootRefs.push(textRef);
|
|
293
|
-
rootSubtreeHandles.push([]);
|
|
294
|
-
} else {
|
|
295
|
-
const activeChildSlot = activeChildSlotStack[stackTop];
|
|
296
|
-
if (__DEV__ && !activeChildSlot) {
|
|
297
|
-
throw new Error(`Template '${parentTemplateKey}' received a text child outside of any child slot.`);
|
|
298
|
-
}
|
|
299
|
-
activeChildSlot!.push(textRef);
|
|
300
|
-
}
|
|
301
|
-
i += 2;
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
default:
|
|
305
|
-
throw new Error(`Unknown opcode: ${opcode as string | number}`);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
pageAttributes: pageAttributes ?? null,
|
|
310
|
-
rootRefs,
|
|
311
|
-
rootSubtreeHandles,
|
|
312
|
-
};
|
|
313
|
-
}
|