@djvlc/runtime-host-vue 1.0.1 → 1.0.3

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,21 +1,39 @@
1
1
  import * as vue from 'vue';
2
- import { Ref, ShallowRef, PropType, InjectionKey, Plugin } from 'vue';
2
+ import { Ref, ShallowRef, ComputedRef, PropType, VNode, InjectionKey, Plugin } from 'vue';
3
3
  import * as _djvlc_runtime_core from '@djvlc/runtime-core';
4
4
  import { RuntimeOptions, DjvlcRuntime, RuntimePhase, PageResolveResult, RuntimeError, HostAPI, RuntimeState } from '@djvlc/runtime-core';
5
5
  export { HostAPI, PageResolveResult, RuntimeError, RuntimeOptions, RuntimePhase, RuntimeState } from '@djvlc/runtime-core';
6
- import * as _djvlc_contracts_types from '@djvlc/contracts-types';
7
6
 
8
7
  /**
9
8
  * Vue 运行时封装
10
9
  * 将核心运行时封装为 Vue 友好的 API
11
10
  */
12
11
 
12
+ /**
13
+ * 性能指标
14
+ */
15
+ interface VueRuntimeMetrics {
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
+ }
13
29
  /**
14
30
  * Vue 运行时选项
15
31
  */
16
32
  interface VueRuntimeOptions extends Omit<RuntimeOptions, 'container'> {
17
33
  /** 容器元素引用 */
18
34
  containerRef?: Ref<HTMLElement | null>;
35
+ /** 启用性能追踪 */
36
+ enableMetrics?: boolean;
19
37
  }
20
38
  /**
21
39
  * Vue 运行时返回值
@@ -33,6 +51,12 @@ interface VueRuntimeReturn {
33
51
  error: ShallowRef<RuntimeError | null>;
34
52
  /** Host API */
35
53
  hostApi: ShallowRef<HostAPI | null>;
54
+ /** 是否就绪 */
55
+ isReady: ComputedRef<boolean>;
56
+ /** 是否有错误 */
57
+ hasError: ComputedRef<boolean>;
58
+ /** 性能指标 */
59
+ metrics: ShallowRef<VueRuntimeMetrics>;
36
60
  /** 初始化 */
37
61
  init: () => Promise<void>;
38
62
  /** 加载页面 */
@@ -41,10 +65,18 @@ interface VueRuntimeReturn {
41
65
  render: () => Promise<void>;
42
66
  /** 销毁 */
43
67
  destroy: () => void;
68
+ /** 重新加载 */
69
+ reload: () => Promise<void>;
44
70
  /** 设置变量 */
45
71
  setVariable: (key: string, value: unknown) => void;
72
+ /** 批量设置变量 */
73
+ setVariables: (variables: Record<string, unknown>) => void;
74
+ /** 获取变量 */
75
+ getVariable: <T = unknown>(key: string) => T | undefined;
46
76
  /** 刷新数据 */
47
77
  refreshData: (queryId: string) => Promise<void>;
78
+ /** 执行动作 */
79
+ executeAction: <T = unknown>(actionType: string, params?: Record<string, unknown>) => Promise<T | undefined>;
48
80
  }
49
81
  /**
50
82
  * 创建 Vue 运行时
@@ -75,6 +107,12 @@ interface DJVRendererProps {
75
107
  debug?: boolean;
76
108
  /** 是否启用 SRI */
77
109
  enableSRI?: boolean;
110
+ /** 重试次数(默认 3) */
111
+ retryCount?: number;
112
+ /** 重试延迟(默认 1000ms) */
113
+ retryDelay?: number;
114
+ /** 超时时间(默认 30000ms) */
115
+ timeout?: number;
78
116
  }
79
117
  /**
80
118
  * DJV 渲染器组件
@@ -108,9 +146,21 @@ declare const DJVRenderer: vue.DefineComponent<vue.ExtractPropTypes<{
108
146
  type: BooleanConstructor;
109
147
  default: boolean;
110
148
  };
111
- }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
149
+ retryCount: {
150
+ type: NumberConstructor;
151
+ default: number;
152
+ };
153
+ retryDelay: {
154
+ type: NumberConstructor;
155
+ default: number;
156
+ };
157
+ timeout: {
158
+ type: NumberConstructor;
159
+ default: number;
160
+ };
161
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
112
162
  [key: string]: any;
113
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("ready" | "error" | "load")[], "ready" | "error" | "load", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
163
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("ready" | "error" | "load" | "phase-change")[], "ready" | "error" | "load" | "phase-change", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
114
164
  pageUid: {
115
165
  type: StringConstructor;
116
166
  required: true;
@@ -139,14 +189,30 @@ declare const DJVRenderer: vue.DefineComponent<vue.ExtractPropTypes<{
139
189
  type: BooleanConstructor;
140
190
  default: boolean;
141
191
  };
192
+ retryCount: {
193
+ type: NumberConstructor;
194
+ default: number;
195
+ };
196
+ retryDelay: {
197
+ type: NumberConstructor;
198
+ default: number;
199
+ };
200
+ timeout: {
201
+ type: NumberConstructor;
202
+ default: number;
203
+ };
142
204
  }>> & Readonly<{
143
205
  onError?: ((...args: any[]) => any) | undefined;
144
- onReady?: ((...args: any[]) => any) | undefined;
145
206
  onLoad?: ((...args: any[]) => any) | undefined;
207
+ onReady?: ((...args: any[]) => any) | undefined;
208
+ "onPhase-change"?: ((...args: any[]) => any) | undefined;
146
209
  }>, {
147
210
  channel: "preview" | "prod" | "gray";
148
211
  debug: boolean;
149
212
  enableSRI: boolean;
213
+ retryCount: number;
214
+ retryDelay: number;
215
+ timeout: number;
150
216
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
151
217
 
152
218
  /**
@@ -157,6 +223,10 @@ interface DJVProviderProps {
157
223
  runtime: DjvlcRuntime | null;
158
224
  /** Host API */
159
225
  hostApi: HostAPI | null;
226
+ /** 容器类名 */
227
+ class?: string;
228
+ /** 是否显示调试信息 */
229
+ debug?: boolean;
160
230
  }
161
231
  /**
162
232
  * DJV Provider 组件
@@ -171,9 +241,17 @@ declare const DJVProvider: vue.DefineComponent<vue.ExtractPropTypes<{
171
241
  type: PropType<HostAPI | null>;
172
242
  default: null;
173
243
  };
244
+ class: {
245
+ type: StringConstructor;
246
+ default: string;
247
+ };
248
+ debug: {
249
+ type: BooleanConstructor;
250
+ default: boolean;
251
+ };
174
252
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
175
253
  [key: string]: any;
176
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
254
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("error" | "phase-change" | "state-change")[], "error" | "phase-change" | "state-change", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
177
255
  runtime: {
178
256
  type: PropType<DjvlcRuntime | null>;
179
257
  default: null;
@@ -182,7 +260,21 @@ declare const DJVProvider: vue.DefineComponent<vue.ExtractPropTypes<{
182
260
  type: PropType<HostAPI | null>;
183
261
  default: null;
184
262
  };
185
- }>> & Readonly<{}>, {
263
+ class: {
264
+ type: StringConstructor;
265
+ default: string;
266
+ };
267
+ debug: {
268
+ type: BooleanConstructor;
269
+ default: boolean;
270
+ };
271
+ }>> & Readonly<{
272
+ onError?: ((...args: any[]) => any) | undefined;
273
+ "onPhase-change"?: ((...args: any[]) => any) | undefined;
274
+ "onState-change"?: ((...args: any[]) => any) | undefined;
275
+ }>, {
276
+ debug: boolean;
277
+ class: string;
186
278
  runtime: DjvlcRuntime | null;
187
279
  hostApi: HostAPI | null;
188
280
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
@@ -215,8 +307,11 @@ declare function useDJVRuntime(): {
215
307
  state: vue.ComputedRef<RuntimeState>;
216
308
  loading: vue.ComputedRef<boolean>;
217
309
  phase: vue.ComputedRef<_djvlc_runtime_core.RuntimePhase>;
218
- error: vue.ComputedRef<_djvlc_contracts_types.RuntimeError | null>;
219
- page: vue.ComputedRef<_djvlc_contracts_types.PageResolveResult | null>;
310
+ error: vue.ComputedRef<_djvlc_runtime_core.RuntimeError | null>;
311
+ page: vue.ComputedRef<_djvlc_runtime_core.PageResolveResult | null>;
312
+ isReady: vue.ComputedRef<boolean>;
313
+ hasError: vue.ComputedRef<boolean>;
314
+ reload: () => Promise<void>;
220
315
  };
221
316
  /**
222
317
  * 使用 Host API
@@ -233,55 +328,189 @@ declare function useRuntimeStateWritable<T = unknown>(key: string, defaultValue?
233
328
  /**
234
329
  * 使用查询结果
235
330
  */
236
- declare function useQuery<T = unknown>(queryId: string): {
331
+ declare function useQuery<T = unknown>(queryId: string, options?: {
332
+ /** 自动刷新间隔(毫秒) */
333
+ refreshInterval?: number;
334
+ /** 挂载时自动刷新 */
335
+ refreshOnMount?: boolean;
336
+ /** 窗口获得焦点时刷新 */
337
+ refreshOnFocus?: boolean;
338
+ }): {
237
339
  data: Ref<T | undefined>;
238
340
  loading: Ref<boolean>;
239
341
  error: Ref<Error | null>;
240
342
  refetch: () => Promise<void>;
343
+ lastUpdated: Ref<number | null>;
241
344
  };
242
345
  /**
243
346
  * 使用动作
244
347
  */
245
- declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string): {
348
+ declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string, options?: {
349
+ /** 执行成功回调 */
350
+ onSuccess?: (data: T) => void;
351
+ /** 执行失败回调 */
352
+ onError?: (error: Error) => void;
353
+ /** 重试次数 */
354
+ retryCount?: number;
355
+ /** 重试延迟(毫秒) */
356
+ retryDelay?: number;
357
+ }): {
246
358
  execute: (params?: P) => Promise<T | undefined>;
247
359
  loading: Ref<boolean>;
248
360
  result: Ref<T | undefined>;
249
361
  error: Ref<Error | null>;
362
+ reset: () => void;
363
+ executionCount: Ref<number>;
250
364
  };
251
365
  /**
252
366
  * 使用数据请求
253
367
  */
254
- declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: P, options?: {
368
+ declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: Ref<P> | P, options?: {
369
+ /** 立即执行(默认 true) */
255
370
  immediate?: boolean;
371
+ /** 自动刷新间隔(毫秒) */
372
+ refreshInterval?: number;
373
+ /** 参数变化时重新请求(默认 true) */
374
+ refreshOnParamsChange?: boolean;
375
+ /** 成功回调 */
376
+ onSuccess?: (data: T) => void;
377
+ /** 失败回调 */
378
+ onError?: (error: Error) => void;
256
379
  }): {
257
380
  data: Ref<T | undefined>;
258
381
  loading: Ref<boolean>;
259
382
  error: Ref<Error | null>;
260
383
  refetch: (newParams?: P) => Promise<void>;
384
+ isFetched: Ref<boolean>;
261
385
  };
262
386
  /**
263
387
  * 使用事件监听
264
388
  */
265
389
  declare function useRuntimeEvent<T = unknown>(eventType: string, handler: (data: T) => void): void;
390
+ /**
391
+ * 使用页面信息
392
+ */
393
+ declare function usePageInfo(): {
394
+ /** 页面 UID */
395
+ pageUid: vue.ComputedRef<string | undefined>;
396
+ /** 页面版本 ID */
397
+ pageVersionId: vue.ComputedRef<string | undefined>;
398
+ /** Schema 版本 */
399
+ schemaVersion: vue.ComputedRef<"1.0.0" | undefined>;
400
+ /** 页面标题 */
401
+ title: vue.ComputedRef<string | undefined>;
402
+ /** 页面配置 */
403
+ config: vue.ComputedRef<Record<string, unknown> | undefined>;
404
+ /** 页面是否已加载 */
405
+ isLoaded: vue.ComputedRef<boolean>;
406
+ };
407
+ /**
408
+ * 使用组件状态
409
+ */
410
+ declare function useComponentState(componentId: string): {
411
+ /** 组件是否已加载 */
412
+ isLoaded: vue.ComputedRef<boolean>;
413
+ /** 组件是否加载中 */
414
+ isLoading: vue.ComputedRef<boolean>;
415
+ /** 组件是否加载失败 */
416
+ hasError: vue.ComputedRef<boolean>;
417
+ /** 加载耗时 */
418
+ loadTime: vue.ComputedRef<number | undefined>;
419
+ /** 组件信息 */
420
+ info: vue.ComputedRef<_djvlc_runtime_core.ComponentLoadResult | undefined>;
421
+ };
422
+ /**
423
+ * 使用生命周期钩子
424
+ */
425
+ declare function useLifecycle(options?: {
426
+ onMounted?: () => void | Promise<void>;
427
+ onReady?: () => void | Promise<void>;
428
+ onError?: (error: unknown) => void;
429
+ onPhaseChange?: (phase: string) => void;
430
+ }): {
431
+ /** 当前阶段 */
432
+ phase: vue.ComputedRef<_djvlc_runtime_core.RuntimePhase>;
433
+ /** 是否已 mounted */
434
+ hasMounted: Readonly<Ref<boolean, boolean>>;
435
+ /** 是否已 ready */
436
+ hasReady: Readonly<Ref<boolean, boolean>>;
437
+ };
438
+ /**
439
+ * 使用条件执行
440
+ * 当条件满足时执行回调
441
+ */
442
+ declare function useWhen(condition: () => boolean, callback: () => void | Promise<void>, options?: {
443
+ /** 是否只执行一次 */
444
+ once?: boolean;
445
+ /** 是否立即检查 */
446
+ immediate?: boolean;
447
+ }): {
448
+ /** 是否已执行 */
449
+ executed: Readonly<Ref<boolean, boolean>>;
450
+ /** 手动停止监听 */
451
+ stop: vue.WatchHandle;
452
+ };
453
+ /**
454
+ * 使用防抖动作
455
+ */
456
+ declare function useDebouncedAction<T = unknown, P = Record<string, unknown>>(actionType: string, delay?: number): {
457
+ execute: (params?: P) => void;
458
+ loading: Ref<boolean>;
459
+ result: Ref<T | undefined>;
460
+ error: Ref<Error | null>;
461
+ cancel: () => void;
462
+ };
463
+ /**
464
+ * 使用全局配置
465
+ */
466
+ declare function useGlobalConfig(): Record<string, unknown>;
266
467
 
267
468
  /**
268
469
  * Vue 插件
269
- * 全局注册 DJVLC 组件
470
+ * 全局注册 DJVLC 组件和指令
270
471
  */
271
472
 
473
+ /**
474
+ * 全局配置 Key
475
+ */
476
+ declare const DJVLC_CONFIG_KEY = "djvlc-config";
477
+ /**
478
+ * 全局配置类型
479
+ */
480
+ interface DJVGlobalConfig {
481
+ /** API 基础 URL */
482
+ apiBaseUrl?: string;
483
+ /** CDN 基础 URL */
484
+ cdnBaseUrl?: string;
485
+ /** 渠道 */
486
+ channel?: 'preview' | 'prod' | 'gray';
487
+ /** 调试模式 */
488
+ debug?: boolean;
489
+ /** 启用 SRI */
490
+ enableSRI?: boolean;
491
+ /** 启用性能追踪 */
492
+ enableMetrics?: boolean;
493
+ /** 重试次数 */
494
+ retryCount?: number;
495
+ /** 重试延迟 */
496
+ retryDelay?: number;
497
+ /** 超时时间 */
498
+ timeout?: number;
499
+ }
272
500
  /**
273
501
  * 插件选项
274
502
  */
275
- interface DJVPluginOptions {
276
- /** 全局配置 */
277
- defaultApiBaseUrl?: string;
278
- defaultCdnBaseUrl?: string;
503
+ interface DJVPluginOptions extends DJVGlobalConfig {
279
504
  /** 是否注册全局组件 */
280
505
  registerComponents?: boolean;
506
+ /** 是否注册全局指令 */
507
+ registerDirectives?: boolean;
508
+ /** 组件前缀 */
509
+ componentPrefix?: string;
281
510
  }
282
511
  /**
283
512
  * DJVLC Vue 插件
284
513
  */
285
514
  declare const DJVPlugin: Plugin;
286
515
 
287
- export { DJVPlugin, type DJVPluginOptions, DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, RuntimeContextKey, type RuntimeContextValue, type VueRuntimeOptions, type VueRuntimeReturn, createVueRuntime, injectRuntime, provideRuntime, useAction, useDJVRuntime, useData, useHostApi, useQuery, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable };
516
+ export { type DJVGlobalConfig, DJVLC_CONFIG_KEY, DJVPlugin, type DJVPluginOptions, DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, RuntimeContextKey, type RuntimeContextValue, type VueRuntimeMetrics, type VueRuntimeOptions, type VueRuntimeReturn, createVueRuntime, injectRuntime, provideRuntime, useAction, useComponentState, useDJVRuntime, useData, useDebouncedAction, useGlobalConfig, useHostApi, useLifecycle, usePageInfo, useQuery, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable, useWhen };