@lytjs/core-vnode 6.8.0 → 6.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -100,7 +100,7 @@ function createApp(rootComponent, rootProps = null, _options) {
100
100
  instance.appContext = context;
101
101
  if (context.provides) {
102
102
  const rootProvides = instance.provides;
103
- for (const key in context.provides) {
103
+ for (const key of Object.keys(context.provides)) {
104
104
  if (!(key in rootProvides)) {
105
105
  rootProvides[key] = context.provides[key];
106
106
  }
@@ -109,7 +109,21 @@ function createApp(rootComponent, rootProps = null, _options) {
109
109
  component.setupComponent(instance);
110
110
  rootVNode.component = instance;
111
111
  context._instance = instance;
112
- const renderer$1 = renderer.createDOMRenderer();
112
+ const renderer$1 = renderer.createDOMRenderer({
113
+ setupChildComponent(childVNode, parentComponent) {
114
+ const childInstance = component.createComponentInstance(childVNode, parentComponent);
115
+ if (parentComponent) {
116
+ childInstance.appContext = parentComponent.appContext;
117
+ } else {
118
+ childInstance.appContext = context;
119
+ }
120
+ component.setupComponent(childInstance);
121
+ childVNode.component = childInstance;
122
+ },
123
+ normalizeProps(inst, rawProps) {
124
+ component.initProps(inst, rawProps);
125
+ }
126
+ });
113
127
  context.renderer = renderer$1;
114
128
  context._vnode = rootVNode;
115
129
  renderer$1.mount(rootVNode, container);
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { createVNode, cloneVNode, EMPTY_OBJ } from '@lytjs/vdom';
2
2
  export { Comment, Fragment, Text, cloneVNode, createVNode, mergeProps } from '@lytjs/vdom';
3
3
  import { createDOMRenderer } from '@lytjs/renderer';
4
4
  import { error } from '@lytjs/common-error';
5
- import { defineComponent as defineComponent$1, getCurrentInstance, createComponentInstance, setupComponent, createComponentPublicInstance, onBeforeUnmount, createAppContext as createAppContext$1, callUnmountedHook } from '@lytjs/component';
5
+ import { defineComponent as defineComponent$1, getCurrentInstance, createComponentInstance, setupComponent, initProps, createComponentPublicInstance, onBeforeUnmount, createAppContext as createAppContext$1, callUnmountedHook } from '@lytjs/component';
6
6
  export { onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated } from '@lytjs/component';
7
7
  import { shallowRef, ref, computed } from '@lytjs/reactivity';
8
8
  export { computed, effect, reactive, ref, watch, watchEffect } from '@lytjs/reactivity';
@@ -101,7 +101,7 @@ function createApp(rootComponent, rootProps = null, _options) {
101
101
  instance.appContext = context;
102
102
  if (context.provides) {
103
103
  const rootProvides = instance.provides;
104
- for (const key in context.provides) {
104
+ for (const key of Object.keys(context.provides)) {
105
105
  if (!(key in rootProvides)) {
106
106
  rootProvides[key] = context.provides[key];
107
107
  }
@@ -110,7 +110,21 @@ function createApp(rootComponent, rootProps = null, _options) {
110
110
  setupComponent(instance);
111
111
  rootVNode.component = instance;
112
112
  context._instance = instance;
113
- const renderer = createDOMRenderer();
113
+ const renderer = createDOMRenderer({
114
+ setupChildComponent(childVNode, parentComponent) {
115
+ const childInstance = createComponentInstance(childVNode, parentComponent);
116
+ if (parentComponent) {
117
+ childInstance.appContext = parentComponent.appContext;
118
+ } else {
119
+ childInstance.appContext = context;
120
+ }
121
+ setupComponent(childInstance);
122
+ childVNode.component = childInstance;
123
+ },
124
+ normalizeProps(inst, rawProps) {
125
+ initProps(inst, rawProps);
126
+ }
127
+ });
114
128
  context.renderer = renderer;
115
129
  context._vnode = rootVNode;
116
130
  renderer.mount(rootVNode, container);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lytjs/core-vnode",
3
- "version": "6.8.0",
3
+ "version": "6.9.1",
4
4
  "description": "Lyt.js Core - VNode rendering mode only",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -32,8 +32,8 @@
32
32
  "@lytjs/shared-types": "workspace:*"
33
33
  },
34
34
  "devDependencies": {
35
- "tsup": "^8.0.0",
36
- "typescript": "^5.4.0"
35
+ "tsup": "^8.5.1",
36
+ "typescript": "^5.8.2"
37
37
  },
38
38
  "license": "MIT",
39
39
  "repository": {
package/dist/index.d.cts DELETED
@@ -1,146 +0,0 @@
1
- import { VNode, Fragment, Text, Comment, VNodeChildren } from '@lytjs/vdom';
2
- export { Comment, Fragment, Text, VNode, VNodeChildren, cloneVNode, createVNode, mergeProps } from '@lytjs/vdom';
3
- import { BaseAppConfig, Directive, DebuggerEvent, DirectiveArguments } from '@lytjs/shared-types';
4
- export { DebuggerEvent, Directive, DirectiveArguments, DirectiveBinding, Renderer } from '@lytjs/shared-types';
5
- import { ComponentPublicInstance, ComponentOptions, InternalSlots } from '@lytjs/component';
6
- export { ComponentOptions, ComponentPublicInstance, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated } from '@lytjs/component';
7
- export { nextTick } from '@lytjs/common-scheduler';
8
- import { WritableComputedRef } from '@lytjs/reactivity';
9
- export { computed, effect, reactive, ref, watch, watchEffect } from '@lytjs/reactivity';
10
- export { compile } from '@lytjs/compiler';
11
-
12
- /** 插件安装函数签名 */
13
- type PluginInstallFunction<T = unknown> = (app: App, ...options: T[]) => void;
14
- interface App<HostElement = Element> {
15
- config: AppConfig;
16
- use(plugin: Plugin | PluginInstallFunction, ...options: unknown[]): App;
17
- mount(rootContainer: HostElement | string): ComponentPublicInstance | null;
18
- unmount(): void;
19
- provide<T = unknown>(key: string | symbol, value: T): App;
20
- inject<T = unknown>(key: string | symbol): T | undefined;
21
- component(name: string, component: Component): App;
22
- directive(name: string, directive: Directive): App;
23
- mixin(mixin: ComponentOptions): App;
24
- errorHandler?: (err: unknown, instance: ComponentPublicInstance | null, info: string) => void;
25
- warnHandler?: (msg: string, instance: ComponentPublicInstance | null, trace: string) => void;
26
- }
27
- interface AppConfig extends BaseAppConfig {
28
- performance: boolean;
29
- globalProperties: Record<string, unknown>;
30
- isCustomElement?: (tag: string) => boolean;
31
- compilerOptions?: Record<string, unknown>;
32
- }
33
- /** createApp 的配置选项(VNode 模式固定使用 vnode 渲染,忽略 rendererMode) */
34
- interface AppOptions {
35
- /** VNode 模式下此选项被忽略,始终使用 VNode 渲染 */
36
- rendererMode?: 'vnode';
37
- }
38
- interface Plugin {
39
- install: PluginInstallFunction;
40
- }
41
- type Component = ComponentOptions | (() => VNode);
42
-
43
- type AsyncComponentLoader = () => Promise<Component>;
44
- interface AsyncComponentOptions {
45
- loader: AsyncComponentLoader;
46
- loadingComponent?: Component;
47
- errorComponent?: Component;
48
- delay?: number;
49
- timeout?: number;
50
- suspensible?: boolean;
51
- onError?: (error: Error, retry: () => void, fail: () => void, attempts: number) => void;
52
- }
53
-
54
- type ErrorCapturedHook = (err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void;
55
- type DebuggerHook = (event: DebuggerEvent) => void;
56
-
57
- declare function createApp(rootComponent: Component, rootProps?: Record<string, unknown> | null, _options?: AppOptions): App;
58
-
59
- /**
60
- * 创建 VNode
61
- */
62
- declare function h(type: string | Component | typeof Fragment | typeof Text | typeof Comment, props?: Record<string, unknown> | null, ...children: VNodeChildren[]): VNode;
63
-
64
- /**
65
- * 定义组件(re-export from @lytjs/component)
66
- *
67
- * 权威实现在 @lytjs/component 中,此处统一返回类型为 ComponentOptions。
68
- * 由于 Component = ComponentOptions | (() => any),
69
- * 返回 ComponentOptions 是 Component 的子集,完全兼容。
70
- */
71
- declare const defineComponent: (options: ComponentOptions) => ComponentOptions;
72
- /**
73
- * 定义异步组件
74
- */
75
- declare function defineAsyncComponent(source: AsyncComponentLoader | AsyncComponentOptions): Component;
76
-
77
- /**
78
- * 解析组件:从当前组件实例的 components 选项和全局注册中查找
79
- */
80
- declare function resolveComponent(name: string): Component | undefined;
81
- /**
82
- * 解析指令:从当前组件实例的 directives 选项和全局注册中查找
83
- */
84
- declare function resolveDirective(name: string): Directive | undefined;
85
-
86
- /**
87
- * 将指令应用到 VNode 上
88
- */
89
- declare function withDirectives(vnode: VNode, directives: DirectiveArguments): VNode;
90
- /** Memo 缓存条目 */
91
- interface MemoEntry {
92
- memo: unknown[];
93
- result: VNode;
94
- }
95
- /**
96
- * 带缓存的渲染辅助
97
- */
98
- declare function withMemo(memo: unknown[], render: () => VNode, cache: MemoEntry[], index: number): VNode;
99
-
100
- /**
101
- * 获取当前组件的 slots
102
- */
103
- declare function useSlots(): InternalSlots;
104
- /**
105
- * 获取当前组件的 attrs
106
- */
107
- declare function useAttrs(): Record<string, unknown>;
108
- /**
109
- * 双向绑定辅助(v-model 的 composition API 版本)
110
- */
111
- declare function useModel<T>(props: Record<string, T | undefined>, key: string): WritableComputedRef<T>;
112
-
113
- /**
114
- * defineCustomElement 的配置选项
115
- */
116
- interface DefineCustomElementOptions {
117
- /** 是否使用 Shadow DOM(默认 true) */
118
- shadowRoot?: boolean;
119
- /** Custom Element 标签名(默认使用组件 name) */
120
- name?: string;
121
- /** CSS 样式(注入到 Shadow DOM) */
122
- css?: string;
123
- }
124
- /**
125
- * 将 LytJS 组件包装为 Custom Element
126
- */
127
- declare function defineCustomElement(componentOptions: ComponentOptions, options?: DefineCustomElementOptions): CustomElementConstructor;
128
- /**
129
- * 在 setup 中获取当前 Custom Element 的 Shadow Root
130
- */
131
- declare function useShadowRoot(): ShadowRoot | null;
132
- /**
133
- * 在 setup 中获取当前 Custom Element 的宿主元素
134
- */
135
- declare function useHost(): HTMLElement | null;
136
- /**
137
- * 在 setup 中获取 slot 变化通知(MutationObserver)
138
- * 返回一个注册回调的函数
139
- */
140
- declare function useWebComponentSlots(onChange: () => void): void;
141
- /**
142
- * 向 Shadow DOM 注入样式
143
- */
144
- declare function injectChildStyles(styles: string): void;
145
-
146
- export { type App, type AppConfig, type AppOptions, type AsyncComponentLoader, type AsyncComponentOptions, type Component, type DebuggerHook, type DefineCustomElementOptions, type ErrorCapturedHook, type Plugin, createApp, h as createElement, defineAsyncComponent, defineComponent, defineCustomElement, h, injectChildStyles, resolveComponent, resolveDirective, useAttrs, useHost, useModel, useShadowRoot, useSlots, useWebComponentSlots, withDirectives, withMemo };
package/dist/index.d.ts DELETED
@@ -1,146 +0,0 @@
1
- import { VNode, Fragment, Text, Comment, VNodeChildren } from '@lytjs/vdom';
2
- export { Comment, Fragment, Text, VNode, VNodeChildren, cloneVNode, createVNode, mergeProps } from '@lytjs/vdom';
3
- import { BaseAppConfig, Directive, DebuggerEvent, DirectiveArguments } from '@lytjs/shared-types';
4
- export { DebuggerEvent, Directive, DirectiveArguments, DirectiveBinding, Renderer } from '@lytjs/shared-types';
5
- import { ComponentPublicInstance, ComponentOptions, InternalSlots } from '@lytjs/component';
6
- export { ComponentOptions, ComponentPublicInstance, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated } from '@lytjs/component';
7
- export { nextTick } from '@lytjs/common-scheduler';
8
- import { WritableComputedRef } from '@lytjs/reactivity';
9
- export { computed, effect, reactive, ref, watch, watchEffect } from '@lytjs/reactivity';
10
- export { compile } from '@lytjs/compiler';
11
-
12
- /** 插件安装函数签名 */
13
- type PluginInstallFunction<T = unknown> = (app: App, ...options: T[]) => void;
14
- interface App<HostElement = Element> {
15
- config: AppConfig;
16
- use(plugin: Plugin | PluginInstallFunction, ...options: unknown[]): App;
17
- mount(rootContainer: HostElement | string): ComponentPublicInstance | null;
18
- unmount(): void;
19
- provide<T = unknown>(key: string | symbol, value: T): App;
20
- inject<T = unknown>(key: string | symbol): T | undefined;
21
- component(name: string, component: Component): App;
22
- directive(name: string, directive: Directive): App;
23
- mixin(mixin: ComponentOptions): App;
24
- errorHandler?: (err: unknown, instance: ComponentPublicInstance | null, info: string) => void;
25
- warnHandler?: (msg: string, instance: ComponentPublicInstance | null, trace: string) => void;
26
- }
27
- interface AppConfig extends BaseAppConfig {
28
- performance: boolean;
29
- globalProperties: Record<string, unknown>;
30
- isCustomElement?: (tag: string) => boolean;
31
- compilerOptions?: Record<string, unknown>;
32
- }
33
- /** createApp 的配置选项(VNode 模式固定使用 vnode 渲染,忽略 rendererMode) */
34
- interface AppOptions {
35
- /** VNode 模式下此选项被忽略,始终使用 VNode 渲染 */
36
- rendererMode?: 'vnode';
37
- }
38
- interface Plugin {
39
- install: PluginInstallFunction;
40
- }
41
- type Component = ComponentOptions | (() => VNode);
42
-
43
- type AsyncComponentLoader = () => Promise<Component>;
44
- interface AsyncComponentOptions {
45
- loader: AsyncComponentLoader;
46
- loadingComponent?: Component;
47
- errorComponent?: Component;
48
- delay?: number;
49
- timeout?: number;
50
- suspensible?: boolean;
51
- onError?: (error: Error, retry: () => void, fail: () => void, attempts: number) => void;
52
- }
53
-
54
- type ErrorCapturedHook = (err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void;
55
- type DebuggerHook = (event: DebuggerEvent) => void;
56
-
57
- declare function createApp(rootComponent: Component, rootProps?: Record<string, unknown> | null, _options?: AppOptions): App;
58
-
59
- /**
60
- * 创建 VNode
61
- */
62
- declare function h(type: string | Component | typeof Fragment | typeof Text | typeof Comment, props?: Record<string, unknown> | null, ...children: VNodeChildren[]): VNode;
63
-
64
- /**
65
- * 定义组件(re-export from @lytjs/component)
66
- *
67
- * 权威实现在 @lytjs/component 中,此处统一返回类型为 ComponentOptions。
68
- * 由于 Component = ComponentOptions | (() => any),
69
- * 返回 ComponentOptions 是 Component 的子集,完全兼容。
70
- */
71
- declare const defineComponent: (options: ComponentOptions) => ComponentOptions;
72
- /**
73
- * 定义异步组件
74
- */
75
- declare function defineAsyncComponent(source: AsyncComponentLoader | AsyncComponentOptions): Component;
76
-
77
- /**
78
- * 解析组件:从当前组件实例的 components 选项和全局注册中查找
79
- */
80
- declare function resolveComponent(name: string): Component | undefined;
81
- /**
82
- * 解析指令:从当前组件实例的 directives 选项和全局注册中查找
83
- */
84
- declare function resolveDirective(name: string): Directive | undefined;
85
-
86
- /**
87
- * 将指令应用到 VNode 上
88
- */
89
- declare function withDirectives(vnode: VNode, directives: DirectiveArguments): VNode;
90
- /** Memo 缓存条目 */
91
- interface MemoEntry {
92
- memo: unknown[];
93
- result: VNode;
94
- }
95
- /**
96
- * 带缓存的渲染辅助
97
- */
98
- declare function withMemo(memo: unknown[], render: () => VNode, cache: MemoEntry[], index: number): VNode;
99
-
100
- /**
101
- * 获取当前组件的 slots
102
- */
103
- declare function useSlots(): InternalSlots;
104
- /**
105
- * 获取当前组件的 attrs
106
- */
107
- declare function useAttrs(): Record<string, unknown>;
108
- /**
109
- * 双向绑定辅助(v-model 的 composition API 版本)
110
- */
111
- declare function useModel<T>(props: Record<string, T | undefined>, key: string): WritableComputedRef<T>;
112
-
113
- /**
114
- * defineCustomElement 的配置选项
115
- */
116
- interface DefineCustomElementOptions {
117
- /** 是否使用 Shadow DOM(默认 true) */
118
- shadowRoot?: boolean;
119
- /** Custom Element 标签名(默认使用组件 name) */
120
- name?: string;
121
- /** CSS 样式(注入到 Shadow DOM) */
122
- css?: string;
123
- }
124
- /**
125
- * 将 LytJS 组件包装为 Custom Element
126
- */
127
- declare function defineCustomElement(componentOptions: ComponentOptions, options?: DefineCustomElementOptions): CustomElementConstructor;
128
- /**
129
- * 在 setup 中获取当前 Custom Element 的 Shadow Root
130
- */
131
- declare function useShadowRoot(): ShadowRoot | null;
132
- /**
133
- * 在 setup 中获取当前 Custom Element 的宿主元素
134
- */
135
- declare function useHost(): HTMLElement | null;
136
- /**
137
- * 在 setup 中获取 slot 变化通知(MutationObserver)
138
- * 返回一个注册回调的函数
139
- */
140
- declare function useWebComponentSlots(onChange: () => void): void;
141
- /**
142
- * 向 Shadow DOM 注入样式
143
- */
144
- declare function injectChildStyles(styles: string): void;
145
-
146
- export { type App, type AppConfig, type AppOptions, type AsyncComponentLoader, type AsyncComponentOptions, type Component, type DebuggerHook, type DefineCustomElementOptions, type ErrorCapturedHook, type Plugin, createApp, h as createElement, defineAsyncComponent, defineComponent, defineCustomElement, h, injectChildStyles, resolveComponent, resolveDirective, useAttrs, useHost, useModel, useShadowRoot, useSlots, useWebComponentSlots, withDirectives, withMemo };