@djvlc/runtime-host-react 1.1.2 → 1.1.4

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.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as _djvlc_runtime_core from '@djvlc/runtime-core';
1
2
  import { RuntimeOptions, DjvlcRuntime, RuntimePhase, PageResolveResult, RuntimeError, HostAPI, RuntimeState } from '@djvlc/runtime-core';
2
3
  export { HostAPI, PageResolveResult, RuntimeError, RuntimeOptions, RuntimePhase, RuntimeState } from '@djvlc/runtime-core';
3
4
  import * as react from 'react';
@@ -8,12 +9,31 @@ import react__default, { ReactNode } from 'react';
8
9
  * 将核心运行时封装为 React 友好的 API
9
10
  */
10
11
 
12
+ /**
13
+ * 性能指标
14
+ */
15
+ interface ReactRuntimeMetrics {
16
+ /** 初始化耗时 */
17
+ initTime: number;
18
+ /** 加载耗时 */
19
+ loadTime: number;
20
+ /** 渲染耗时 */
21
+ renderTime: number;
22
+ /** 总耗时 */
23
+ totalTime: number;
24
+ /** 初始化时间戳 */
25
+ initTimestamp: number | null;
26
+ /** 就绪时间戳 */
27
+ readyTimestamp: number | null;
28
+ }
11
29
  /**
12
30
  * React 运行时选项
13
31
  */
14
32
  interface ReactRuntimeOptions extends Omit<RuntimeOptions, 'container'> {
15
33
  /** 容器元素引用 */
16
34
  containerRef?: React.RefObject<HTMLElement>;
35
+ /** 启用性能追踪 */
36
+ enableMetrics?: boolean;
17
37
  }
18
38
  /**
19
39
  * React 运行时返回值
@@ -31,6 +51,12 @@ interface ReactRuntimeReturn {
31
51
  error: RuntimeError | null;
32
52
  /** Host API */
33
53
  hostApi: HostAPI | null;
54
+ /** 是否就绪 */
55
+ isReady: boolean;
56
+ /** 是否有错误 */
57
+ hasError: boolean;
58
+ /** 性能指标 */
59
+ metrics: ReactRuntimeMetrics;
34
60
  /** 初始化 */
35
61
  init: () => Promise<void>;
36
62
  /** 加载页面 */
@@ -39,10 +65,18 @@ interface ReactRuntimeReturn {
39
65
  render: () => Promise<void>;
40
66
  /** 销毁 */
41
67
  destroy: () => void;
68
+ /** 重新加载 */
69
+ reload: () => Promise<void>;
42
70
  /** 设置变量 */
43
71
  setVariable: (key: string, value: unknown) => void;
72
+ /** 批量设置变量 */
73
+ setVariables: (variables: Record<string, unknown>) => void;
74
+ /** 获取变量 */
75
+ getVariable: <T = unknown>(key: string) => T | undefined;
44
76
  /** 刷新数据 */
45
77
  refreshData: (queryId: string) => Promise<void>;
78
+ /** 执行动作 */
79
+ executeAction: <T = unknown>(actionType: string, params?: Record<string, unknown>) => Promise<T | undefined>;
46
80
  }
47
81
  /**
48
82
  * 使用 React 运行时 Hook
@@ -118,21 +152,31 @@ interface DJVRendererProps {
118
152
  onError?: (error: RuntimeError) => void;
119
153
  /** 就绪回调 */
120
154
  onReady?: () => void;
155
+ /** 阶段变化回调 */
156
+ onPhaseChange?: (phase: string) => void;
121
157
  /** 加载中显示 */
122
158
  loadingComponent?: ReactNode;
123
159
  /** 错误显示 */
124
- errorComponent?: ReactNode | ((error: RuntimeError) => ReactNode);
160
+ errorComponent?: ReactNode | ((error: RuntimeError, retry: () => void) => ReactNode);
161
+ /** 空状态显示 */
162
+ emptyComponent?: ReactNode;
125
163
  /** 子元素 */
126
164
  children?: ReactNode;
127
165
  /** 容器类名 */
128
166
  className?: string;
129
167
  /** 容器样式 */
130
168
  style?: react__default.CSSProperties;
169
+ /** 重试次数(默认 3) */
170
+ retryCount?: number;
171
+ /** 重试延迟(默认 1000ms) */
172
+ retryDelay?: number;
173
+ /** 超时时间(默认 30000ms) */
174
+ timeout?: number;
131
175
  }
132
176
  /**
133
177
  * DJV 渲染器组件
134
178
  */
135
- declare function DJVRenderer({ pageUid, apiBaseUrl, cdnBaseUrl, channel, userId, deviceId, authToken, previewToken, debug, enableSRI, onLoad, onError, onReady, loadingComponent, errorComponent, children, className, style, }: DJVRendererProps): JSX.Element;
179
+ declare function DJVRenderer({ pageUid, apiBaseUrl, cdnBaseUrl, channel, userId, deviceId, authToken, previewToken, debug, enableSRI, onLoad, onError, onReady, onPhaseChange, loadingComponent, errorComponent, emptyComponent, children, className, style, retryCount, retryDelay, timeout, }: DJVRendererProps): JSX.Element;
136
180
 
137
181
  /**
138
182
  * DJV Provider 组件
@@ -149,17 +193,22 @@ interface DJVProviderProps {
149
193
  hostApi: HostAPI | null;
150
194
  /** 子元素 */
151
195
  children: ReactNode;
196
+ /** 容器类名 */
197
+ className?: string;
198
+ /** 是否显示调试信息 */
199
+ debug?: boolean;
200
+ /** 状态变更回调 */
201
+ onStateChange?: (state: RuntimeState) => void;
202
+ /** 阶段变更回调 */
203
+ onPhaseChange?: (phase: RuntimePhase) => void;
204
+ /** 错误回调 */
205
+ onError?: (error: RuntimeError) => void;
152
206
  }
153
207
  /**
154
208
  * DJV Provider 组件
155
209
  * 用于手动控制运行时时使用
156
210
  */
157
- declare function DJVProvider({ runtime, hostApi, children, }: DJVProviderProps): JSX.Element;
158
-
159
- /**
160
- * React Hooks
161
- * 运行时相关的 React Hooks
162
- */
211
+ declare function DJVProvider({ runtime, hostApi, children, className, debug, onStateChange, onPhaseChange, onError, }: DJVProviderProps): JSX.Element;
163
212
 
164
213
  /**
165
214
  * 使用 DJV 运行时
@@ -171,6 +220,12 @@ declare function useDJVRuntime(): {
171
220
  phase: RuntimePhase;
172
221
  error: RuntimeError | null;
173
222
  page: PageResolveResult | null;
223
+ /** 是否已就绪 */
224
+ isReady: boolean;
225
+ /** 是否有错误 */
226
+ hasError: boolean;
227
+ /** 重新加载 */
228
+ reload: () => Promise<void>;
174
229
  };
175
230
  /**
176
231
  * 使用 Host API
@@ -187,35 +242,157 @@ declare function useRuntimeStateWritable<T = unknown>(key: string, defaultValue?
187
242
  /**
188
243
  * 使用查询结果
189
244
  */
190
- declare function useQuery<T = unknown>(queryId: string): {
245
+ declare function useQuery<T = unknown>(queryId: string, options?: {
246
+ /** 自动刷新间隔(毫秒) */
247
+ refreshInterval?: number;
248
+ /** 挂载时自动刷新 */
249
+ refreshOnMount?: boolean;
250
+ /** 窗口获得焦点时刷新 */
251
+ refreshOnFocus?: boolean;
252
+ }): {
191
253
  data: T | undefined;
192
254
  loading: boolean;
193
255
  error: Error | null;
194
256
  refetch: () => Promise<void>;
257
+ /** 上次刷新时间 */
258
+ lastUpdated: number | null;
195
259
  };
196
260
  /**
197
261
  * 使用动作
198
262
  */
199
- declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string): {
263
+ declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string, options?: {
264
+ /** 执行成功回调 */
265
+ onSuccess?: (data: T) => void;
266
+ /** 执行失败回调 */
267
+ onError?: (error: Error) => void;
268
+ /** 重试次数 */
269
+ retryCount?: number;
270
+ /** 重试延迟(毫秒) */
271
+ retryDelay?: number;
272
+ }): {
200
273
  execute: (params?: P) => Promise<T | undefined>;
201
274
  loading: boolean;
202
275
  result: T | undefined;
203
276
  error: Error | null;
277
+ /** 重置状态 */
278
+ reset: () => void;
279
+ /** 执行次数 */
280
+ executionCount: number;
204
281
  };
205
282
  /**
206
283
  * 使用数据请求
207
284
  */
208
285
  declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: P, options?: {
286
+ /** 立即执行(默认 true) */
209
287
  immediate?: boolean;
288
+ /** 自动刷新间隔(毫秒) */
289
+ refreshInterval?: number;
290
+ /** 参数变化时重新请求 */
291
+ refreshOnParamsChange?: boolean;
292
+ /** 成功回调 */
293
+ onSuccess?: (data: T) => void;
294
+ /** 失败回调 */
295
+ onError?: (error: Error) => void;
210
296
  }): {
211
297
  data: T | undefined;
212
298
  loading: boolean;
213
299
  error: Error | null;
214
300
  refetch: (newParams?: P) => Promise<void>;
301
+ /** 是否已获取过数据 */
302
+ isFetched: boolean;
215
303
  };
216
304
  /**
217
305
  * 使用事件监听
218
306
  */
219
307
  declare function useRuntimeEvent<T = unknown>(eventType: string, handler: (data: T) => void): void;
308
+ /**
309
+ * 使用页面信息
310
+ */
311
+ declare function usePageInfo(): {
312
+ /** 页面 UID */
313
+ pageUid: string | undefined;
314
+ /** 页面版本 ID */
315
+ pageVersionId: string | undefined;
316
+ /** Schema 版本 */
317
+ schemaVersion: "1.0.0" | undefined;
318
+ /** 页面标题 */
319
+ title: string | undefined;
320
+ /** 页面配置 */
321
+ config: Record<string, unknown> | undefined;
322
+ /** 页面是否已加载 */
323
+ isLoaded: boolean;
324
+ };
325
+ /**
326
+ * 使用组件状态
327
+ */
328
+ declare function useComponentState(componentId: string): {
329
+ /** 组件是否已加载 */
330
+ isLoaded: boolean;
331
+ /** 组件是否加载中 */
332
+ isLoading: boolean;
333
+ /** 组件是否加载失败 */
334
+ hasError: boolean;
335
+ /** 加载耗时 */
336
+ loadTime: number | undefined;
337
+ /** 组件信息 */
338
+ info: _djvlc_runtime_core.ComponentLoadResult | undefined;
339
+ };
340
+ /**
341
+ * 使用生命周期钩子
342
+ */
343
+ declare function useLifecycle(options?: {
344
+ onMounted?: () => void | Promise<void>;
345
+ onReady?: () => void | Promise<void>;
346
+ onError?: (error: unknown) => void;
347
+ onPhaseChange?: (phase: string) => void;
348
+ }): {
349
+ /** 当前阶段 */
350
+ phase: RuntimePhase;
351
+ /** 是否已 mounted */
352
+ hasMounted: boolean;
353
+ /** 是否已 ready */
354
+ hasReady: boolean;
355
+ };
356
+ /**
357
+ * 使用条件执行
358
+ * 当条件满足时执行回调
359
+ */
360
+ declare function useWhen(condition: boolean, callback: () => void | Promise<void>, options?: {
361
+ /** 是否只执行一次 */
362
+ once?: boolean;
363
+ }): {
364
+ /** 是否已执行 */
365
+ executed: boolean;
366
+ };
367
+ /**
368
+ * 使用防抖动作
369
+ */
370
+ declare function useDebouncedAction<T = unknown, P = Record<string, unknown>>(actionType: string, delay?: number): {
371
+ execute: (params?: P) => void;
372
+ loading: boolean;
373
+ result: T | undefined;
374
+ error: Error | null;
375
+ cancel: () => void;
376
+ };
377
+ /**
378
+ * 使用异步操作
379
+ */
380
+ declare function useAsync<T>(asyncFn: () => Promise<T>, deps?: React.DependencyList, options?: {
381
+ /** 立即执行 */
382
+ immediate?: boolean;
383
+ /** 成功回调 */
384
+ onSuccess?: (data: T) => void;
385
+ /** 失败回调 */
386
+ onError?: (error: Error) => void;
387
+ }): {
388
+ data: T | undefined;
389
+ loading: boolean;
390
+ error: Error | null;
391
+ execute: () => Promise<T | undefined>;
392
+ };
393
+ /**
394
+ * 使用前一个值
395
+ */
396
+ declare function usePrevious<T>(value: T): T | undefined;
220
397
 
221
- export { DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, type ReactRuntimeOptions, type ReactRuntimeReturn, RuntimeContext, type RuntimeContextValue, RuntimeProvider, type RuntimeProviderProps, useAction, useDJVRuntime, useData, useHostApi, useQuery, useReactRuntime, useRuntimeContext, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable };
398
+ export { DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, type ReactRuntimeMetrics, type ReactRuntimeOptions, type ReactRuntimeReturn, RuntimeContext, type RuntimeContextValue, RuntimeProvider, type RuntimeProviderProps, useAction, useAsync, useComponentState, useDJVRuntime, useData, useDebouncedAction, useHostApi, useLifecycle, usePageInfo, usePrevious, useQuery, useReactRuntime, useRuntimeContext, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable, useWhen };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as _djvlc_runtime_core from '@djvlc/runtime-core';
1
2
  import { RuntimeOptions, DjvlcRuntime, RuntimePhase, PageResolveResult, RuntimeError, HostAPI, RuntimeState } from '@djvlc/runtime-core';
2
3
  export { HostAPI, PageResolveResult, RuntimeError, RuntimeOptions, RuntimePhase, RuntimeState } from '@djvlc/runtime-core';
3
4
  import * as react from 'react';
@@ -8,12 +9,31 @@ import react__default, { ReactNode } from 'react';
8
9
  * 将核心运行时封装为 React 友好的 API
9
10
  */
10
11
 
12
+ /**
13
+ * 性能指标
14
+ */
15
+ interface ReactRuntimeMetrics {
16
+ /** 初始化耗时 */
17
+ initTime: number;
18
+ /** 加载耗时 */
19
+ loadTime: number;
20
+ /** 渲染耗时 */
21
+ renderTime: number;
22
+ /** 总耗时 */
23
+ totalTime: number;
24
+ /** 初始化时间戳 */
25
+ initTimestamp: number | null;
26
+ /** 就绪时间戳 */
27
+ readyTimestamp: number | null;
28
+ }
11
29
  /**
12
30
  * React 运行时选项
13
31
  */
14
32
  interface ReactRuntimeOptions extends Omit<RuntimeOptions, 'container'> {
15
33
  /** 容器元素引用 */
16
34
  containerRef?: React.RefObject<HTMLElement>;
35
+ /** 启用性能追踪 */
36
+ enableMetrics?: boolean;
17
37
  }
18
38
  /**
19
39
  * React 运行时返回值
@@ -31,6 +51,12 @@ interface ReactRuntimeReturn {
31
51
  error: RuntimeError | null;
32
52
  /** Host API */
33
53
  hostApi: HostAPI | null;
54
+ /** 是否就绪 */
55
+ isReady: boolean;
56
+ /** 是否有错误 */
57
+ hasError: boolean;
58
+ /** 性能指标 */
59
+ metrics: ReactRuntimeMetrics;
34
60
  /** 初始化 */
35
61
  init: () => Promise<void>;
36
62
  /** 加载页面 */
@@ -39,10 +65,18 @@ interface ReactRuntimeReturn {
39
65
  render: () => Promise<void>;
40
66
  /** 销毁 */
41
67
  destroy: () => void;
68
+ /** 重新加载 */
69
+ reload: () => Promise<void>;
42
70
  /** 设置变量 */
43
71
  setVariable: (key: string, value: unknown) => void;
72
+ /** 批量设置变量 */
73
+ setVariables: (variables: Record<string, unknown>) => void;
74
+ /** 获取变量 */
75
+ getVariable: <T = unknown>(key: string) => T | undefined;
44
76
  /** 刷新数据 */
45
77
  refreshData: (queryId: string) => Promise<void>;
78
+ /** 执行动作 */
79
+ executeAction: <T = unknown>(actionType: string, params?: Record<string, unknown>) => Promise<T | undefined>;
46
80
  }
47
81
  /**
48
82
  * 使用 React 运行时 Hook
@@ -118,21 +152,31 @@ interface DJVRendererProps {
118
152
  onError?: (error: RuntimeError) => void;
119
153
  /** 就绪回调 */
120
154
  onReady?: () => void;
155
+ /** 阶段变化回调 */
156
+ onPhaseChange?: (phase: string) => void;
121
157
  /** 加载中显示 */
122
158
  loadingComponent?: ReactNode;
123
159
  /** 错误显示 */
124
- errorComponent?: ReactNode | ((error: RuntimeError) => ReactNode);
160
+ errorComponent?: ReactNode | ((error: RuntimeError, retry: () => void) => ReactNode);
161
+ /** 空状态显示 */
162
+ emptyComponent?: ReactNode;
125
163
  /** 子元素 */
126
164
  children?: ReactNode;
127
165
  /** 容器类名 */
128
166
  className?: string;
129
167
  /** 容器样式 */
130
168
  style?: react__default.CSSProperties;
169
+ /** 重试次数(默认 3) */
170
+ retryCount?: number;
171
+ /** 重试延迟(默认 1000ms) */
172
+ retryDelay?: number;
173
+ /** 超时时间(默认 30000ms) */
174
+ timeout?: number;
131
175
  }
132
176
  /**
133
177
  * DJV 渲染器组件
134
178
  */
135
- declare function DJVRenderer({ pageUid, apiBaseUrl, cdnBaseUrl, channel, userId, deviceId, authToken, previewToken, debug, enableSRI, onLoad, onError, onReady, loadingComponent, errorComponent, children, className, style, }: DJVRendererProps): JSX.Element;
179
+ declare function DJVRenderer({ pageUid, apiBaseUrl, cdnBaseUrl, channel, userId, deviceId, authToken, previewToken, debug, enableSRI, onLoad, onError, onReady, onPhaseChange, loadingComponent, errorComponent, emptyComponent, children, className, style, retryCount, retryDelay, timeout, }: DJVRendererProps): JSX.Element;
136
180
 
137
181
  /**
138
182
  * DJV Provider 组件
@@ -149,17 +193,22 @@ interface DJVProviderProps {
149
193
  hostApi: HostAPI | null;
150
194
  /** 子元素 */
151
195
  children: ReactNode;
196
+ /** 容器类名 */
197
+ className?: string;
198
+ /** 是否显示调试信息 */
199
+ debug?: boolean;
200
+ /** 状态变更回调 */
201
+ onStateChange?: (state: RuntimeState) => void;
202
+ /** 阶段变更回调 */
203
+ onPhaseChange?: (phase: RuntimePhase) => void;
204
+ /** 错误回调 */
205
+ onError?: (error: RuntimeError) => void;
152
206
  }
153
207
  /**
154
208
  * DJV Provider 组件
155
209
  * 用于手动控制运行时时使用
156
210
  */
157
- declare function DJVProvider({ runtime, hostApi, children, }: DJVProviderProps): JSX.Element;
158
-
159
- /**
160
- * React Hooks
161
- * 运行时相关的 React Hooks
162
- */
211
+ declare function DJVProvider({ runtime, hostApi, children, className, debug, onStateChange, onPhaseChange, onError, }: DJVProviderProps): JSX.Element;
163
212
 
164
213
  /**
165
214
  * 使用 DJV 运行时
@@ -171,6 +220,12 @@ declare function useDJVRuntime(): {
171
220
  phase: RuntimePhase;
172
221
  error: RuntimeError | null;
173
222
  page: PageResolveResult | null;
223
+ /** 是否已就绪 */
224
+ isReady: boolean;
225
+ /** 是否有错误 */
226
+ hasError: boolean;
227
+ /** 重新加载 */
228
+ reload: () => Promise<void>;
174
229
  };
175
230
  /**
176
231
  * 使用 Host API
@@ -187,35 +242,157 @@ declare function useRuntimeStateWritable<T = unknown>(key: string, defaultValue?
187
242
  /**
188
243
  * 使用查询结果
189
244
  */
190
- declare function useQuery<T = unknown>(queryId: string): {
245
+ declare function useQuery<T = unknown>(queryId: string, options?: {
246
+ /** 自动刷新间隔(毫秒) */
247
+ refreshInterval?: number;
248
+ /** 挂载时自动刷新 */
249
+ refreshOnMount?: boolean;
250
+ /** 窗口获得焦点时刷新 */
251
+ refreshOnFocus?: boolean;
252
+ }): {
191
253
  data: T | undefined;
192
254
  loading: boolean;
193
255
  error: Error | null;
194
256
  refetch: () => Promise<void>;
257
+ /** 上次刷新时间 */
258
+ lastUpdated: number | null;
195
259
  };
196
260
  /**
197
261
  * 使用动作
198
262
  */
199
- declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string): {
263
+ declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string, options?: {
264
+ /** 执行成功回调 */
265
+ onSuccess?: (data: T) => void;
266
+ /** 执行失败回调 */
267
+ onError?: (error: Error) => void;
268
+ /** 重试次数 */
269
+ retryCount?: number;
270
+ /** 重试延迟(毫秒) */
271
+ retryDelay?: number;
272
+ }): {
200
273
  execute: (params?: P) => Promise<T | undefined>;
201
274
  loading: boolean;
202
275
  result: T | undefined;
203
276
  error: Error | null;
277
+ /** 重置状态 */
278
+ reset: () => void;
279
+ /** 执行次数 */
280
+ executionCount: number;
204
281
  };
205
282
  /**
206
283
  * 使用数据请求
207
284
  */
208
285
  declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: P, options?: {
286
+ /** 立即执行(默认 true) */
209
287
  immediate?: boolean;
288
+ /** 自动刷新间隔(毫秒) */
289
+ refreshInterval?: number;
290
+ /** 参数变化时重新请求 */
291
+ refreshOnParamsChange?: boolean;
292
+ /** 成功回调 */
293
+ onSuccess?: (data: T) => void;
294
+ /** 失败回调 */
295
+ onError?: (error: Error) => void;
210
296
  }): {
211
297
  data: T | undefined;
212
298
  loading: boolean;
213
299
  error: Error | null;
214
300
  refetch: (newParams?: P) => Promise<void>;
301
+ /** 是否已获取过数据 */
302
+ isFetched: boolean;
215
303
  };
216
304
  /**
217
305
  * 使用事件监听
218
306
  */
219
307
  declare function useRuntimeEvent<T = unknown>(eventType: string, handler: (data: T) => void): void;
308
+ /**
309
+ * 使用页面信息
310
+ */
311
+ declare function usePageInfo(): {
312
+ /** 页面 UID */
313
+ pageUid: string | undefined;
314
+ /** 页面版本 ID */
315
+ pageVersionId: string | undefined;
316
+ /** Schema 版本 */
317
+ schemaVersion: "1.0.0" | undefined;
318
+ /** 页面标题 */
319
+ title: string | undefined;
320
+ /** 页面配置 */
321
+ config: Record<string, unknown> | undefined;
322
+ /** 页面是否已加载 */
323
+ isLoaded: boolean;
324
+ };
325
+ /**
326
+ * 使用组件状态
327
+ */
328
+ declare function useComponentState(componentId: string): {
329
+ /** 组件是否已加载 */
330
+ isLoaded: boolean;
331
+ /** 组件是否加载中 */
332
+ isLoading: boolean;
333
+ /** 组件是否加载失败 */
334
+ hasError: boolean;
335
+ /** 加载耗时 */
336
+ loadTime: number | undefined;
337
+ /** 组件信息 */
338
+ info: _djvlc_runtime_core.ComponentLoadResult | undefined;
339
+ };
340
+ /**
341
+ * 使用生命周期钩子
342
+ */
343
+ declare function useLifecycle(options?: {
344
+ onMounted?: () => void | Promise<void>;
345
+ onReady?: () => void | Promise<void>;
346
+ onError?: (error: unknown) => void;
347
+ onPhaseChange?: (phase: string) => void;
348
+ }): {
349
+ /** 当前阶段 */
350
+ phase: RuntimePhase;
351
+ /** 是否已 mounted */
352
+ hasMounted: boolean;
353
+ /** 是否已 ready */
354
+ hasReady: boolean;
355
+ };
356
+ /**
357
+ * 使用条件执行
358
+ * 当条件满足时执行回调
359
+ */
360
+ declare function useWhen(condition: boolean, callback: () => void | Promise<void>, options?: {
361
+ /** 是否只执行一次 */
362
+ once?: boolean;
363
+ }): {
364
+ /** 是否已执行 */
365
+ executed: boolean;
366
+ };
367
+ /**
368
+ * 使用防抖动作
369
+ */
370
+ declare function useDebouncedAction<T = unknown, P = Record<string, unknown>>(actionType: string, delay?: number): {
371
+ execute: (params?: P) => void;
372
+ loading: boolean;
373
+ result: T | undefined;
374
+ error: Error | null;
375
+ cancel: () => void;
376
+ };
377
+ /**
378
+ * 使用异步操作
379
+ */
380
+ declare function useAsync<T>(asyncFn: () => Promise<T>, deps?: React.DependencyList, options?: {
381
+ /** 立即执行 */
382
+ immediate?: boolean;
383
+ /** 成功回调 */
384
+ onSuccess?: (data: T) => void;
385
+ /** 失败回调 */
386
+ onError?: (error: Error) => void;
387
+ }): {
388
+ data: T | undefined;
389
+ loading: boolean;
390
+ error: Error | null;
391
+ execute: () => Promise<T | undefined>;
392
+ };
393
+ /**
394
+ * 使用前一个值
395
+ */
396
+ declare function usePrevious<T>(value: T): T | undefined;
220
397
 
221
- export { DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, type ReactRuntimeOptions, type ReactRuntimeReturn, RuntimeContext, type RuntimeContextValue, RuntimeProvider, type RuntimeProviderProps, useAction, useDJVRuntime, useData, useHostApi, useQuery, useReactRuntime, useRuntimeContext, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable };
398
+ export { DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, type ReactRuntimeMetrics, type ReactRuntimeOptions, type ReactRuntimeReturn, RuntimeContext, type RuntimeContextValue, RuntimeProvider, type RuntimeProviderProps, useAction, useAsync, useComponentState, useDJVRuntime, useData, useDebouncedAction, useHostApi, useLifecycle, usePageInfo, usePrevious, useQuery, useReactRuntime, useRuntimeContext, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable, useWhen };