vue-popup-plus 1.3.4 → 1.5.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.
@@ -1,8 +1,14 @@
1
+ import { AllowedComponentProps } from 'vue';
1
2
  import { App } from 'vue';
3
+ import { AsyncComponentLoader } from 'vue';
2
4
  import { Component } from 'vue';
5
+ import { ComponentOptionsMixin } from 'vue';
6
+ import { ComponentProvideOptions } from 'vue';
3
7
  import { ComputedRef } from 'vue';
8
+ import { DefineComponent } from 'vue';
4
9
  import { InjectionKey } from 'vue';
5
- import { version } from '../package.json';
10
+ import { PublicProps } from 'vue';
11
+ import { VNodeProps } from 'vue';
6
12
 
7
13
  declare type Animation_2 = IAnimations[keyof IAnimations];
8
14
 
@@ -12,18 +18,25 @@ declare type Animation_2 = IAnimations[keyof IAnimations];
12
18
  declare type ComponentInjectKeys = {
13
19
  /**
14
20
  * 当前组件所在弹出层的实例ID
21
+ *
15
22
  * - 可用于销毁当前弹出层
16
23
  * - 使用示例:
24
+ *
17
25
  * ```ts
18
26
  * // 弹出层渲染的所有子代组件中
19
27
  * import { inject } from 'vue'
20
- * import { usePopup, POPUP_COMPONENT_INJECTS } from 'vue-popup-plus'
28
+ * import {
29
+ * usePopup,
30
+ * POPUP_COMPONENT_INJECTS,
31
+ * } from 'vue-popup-plus'
21
32
  *
22
33
  * // 获取弹出层控制器
23
34
  * const popup = usePopup()
24
35
  *
25
36
  * // 获取当前组件所在弹出层的实例ID
26
- * const instanceId = inject(POPUP_COMPONENT_INJECTS.INSTANCE_ID)
37
+ * const instanceId = inject(
38
+ * POPUP_COMPONENT_INJECTS.INSTANCE_ID
39
+ * )
27
40
  *
28
41
  * // 销毁当前弹出层
29
42
  * popup.destroy(instanceId)
@@ -32,21 +45,30 @@ declare type ComponentInjectKeys = {
32
45
  INSTANCE_ID: InjectionKey<InstanceId>;
33
46
  /**
34
47
  * 弹出层视图样式
48
+ *
35
49
  * - 可在弹出层内部组件内获取弹出层根级视图组件的样式
36
50
  * - 使用示例:
51
+ *
37
52
  * ```ts
38
53
  * // 弹出层渲染的所有子代组件中
39
54
  * import { inject } from 'vue'
40
- * import { usePopup, POPUP_COMPONENT_INJECTS } from 'vue-popup-plus'
55
+ * import {
56
+ * usePopup,
57
+ * POPUP_COMPONENT_INJECTS,
58
+ * } from 'vue-popup-plus'
41
59
  *
42
60
  * // 获取弹出层控制器
43
61
  * const popup = usePopup()
44
62
  *
45
63
  * // 获取当前组件所在弹出层的实例ID
46
- * const instanceId = inject(POPUP_COMPONENT_INJECTS.INSTANCE_ID)
64
+ * const instanceId = inject(
65
+ * POPUP_COMPONENT_INJECTS.INSTANCE_ID
66
+ * )
47
67
  *
48
68
  * // 获取弹出层根级视图组件的样式
49
- * const computedViewStyle = inject(POPUP_COMPONENT_INJECTS.COMPUTED_VIEW_STYLE)
69
+ * const computedViewStyle = inject(
70
+ * POPUP_COMPONENT_INJECTS.COMPUTED_VIEW_STYLE
71
+ * )
50
72
  * ```
51
73
  */
52
74
  COMPUTED_VIEW_STYLE: InjectionKey<PopupViewStyle>;
@@ -62,30 +84,36 @@ declare type ControllerPrototype = Record<string, string | boolean | number | sy
62
84
 
63
85
  declare type ControllerPrototypeFunctionValue = (this: IController, ...args: any[]) => any;
64
86
 
65
- declare type CoreConfig = Required<CoreOptions>;
87
+ declare type CoreConfig = Required<CreateOption>;
66
88
 
67
- export declare type CoreOptions = {
89
+ export declare type CreateOption = {
68
90
  /**
69
91
  * 弹出层 zIndex 基础值
70
- * - 默认为1000,每次生成弹出层时,除非 render() 方法传入 zIndex,否则使用此基础值,每次使用后会自动递增
92
+ *
93
+ * - 默认为1000,每次生成弹出层时,除非 render() 方法传入
94
+ * zIndex,否则使用此基础值,每次使用后会自动递增
71
95
  */
72
96
  zIndex?: number;
73
97
  /**
74
98
  * 是否自动禁用滚动
99
+ *
75
100
  * - 默认为 true
76
101
  * - 开启后,弹出层显示时会自动禁用页面滚动
77
102
  */
78
103
  autoDisableScroll?: boolean;
79
104
  /**
80
105
  * 弹出层控制器挂载在 Vue 实例上的属性名
81
- * - 默认为 $popup ,这在使用选项式API时可以在组件内通过this.$popup 访问控制器实例,可以使用该属性自定义挂载属性名
106
+ *
107
+ * - 默认为 $popup ,这在使用 选项式 API 时可以在组件内通过 this.$popup
108
+ * 访问控制器实例,可以使用该属性自定义挂载属性名
82
109
  * - 使用示例:
110
+ *
83
111
  * ```ts
84
112
  * // main.ts
85
113
  * import { createPopup } from 'vue-popup-plus'
86
114
  *
87
115
  * const popup = createPopup({
88
- * prototypeName: '$customPopup'
116
+ * prototypeName: '$customPopup',
89
117
  * })
90
118
  *
91
119
  * // 组件内
@@ -93,8 +121,11 @@ export declare type CoreOptions = {
93
121
  * component: Demo,
94
122
  * })
95
123
  * ```
96
- * - 注意,如果你使用 TypeScript,则自定义属性名称需要手动同步添加类型扩展,扩展代码可以放在一个 .ts 文件,或是一个影响整个项目的 *.d.ts 文件中。
124
+ *
125
+ * - 注意,如果你使用 TypeScript,则自定义属性名称需要手动同步添加类型扩展,扩展代码可以放在一个
126
+ * .ts 文件,或是一个影响整个项目的 *.d.ts 文件中。
97
127
  * - 扩展代码示例:
128
+ *
98
129
  * ```ts
99
130
  * // 扩展自定义属性名类型
100
131
  * declare module 'vue' {
@@ -102,25 +133,71 @@ export declare type CoreOptions = {
102
133
  * $customPopup: typeof popup
103
134
  * }
104
135
  * }
136
+ * ```
105
137
  */
106
138
  prototypeName?: string;
139
+ /**
140
+ * 日志器
141
+ *
142
+ * - 默认使用内置的日志器,仅会在开启调试模式时在控制台输出日志
143
+ * - 你可以自定义日志器,需要注意日志的接收将不会受到调试模式的影响,
144
+ * 无论调试模式是否开启,日志都将被传递给自定义的日志器。
145
+ */
146
+ logHandler?: ILogHandler;
107
147
  /**
108
148
  * 开启调试模式
149
+ *
109
150
  * - 默认为 false
110
- * - 开启后,会提供开发调试功能
151
+ * - 注意:开启调试模式可能会影响到性能,不建议在生产环境开启。
152
+ * - 开启后,将会在控制台输出日志,同时如果未注册根组件,调试模式下
153
+ * 将会使用 Vue App 实例渲染弹出层,方便开发者调试。
111
154
  */
112
155
  debugMode?: boolean;
113
156
  };
114
157
 
115
158
  /**
116
- * 创建一个弹出层控制器实例,该实例需要通过 app.use() 安装到Vue实例上才能使用
117
- * @param options 弹出层核心配置
159
+ * 创建一个弹出层控制器实例
160
+ *
161
+ * - 该实例需要被 Vue 的 app.use() 函数后才能使用
162
+ *
163
+ * @param options 创建配置,具体请参考 {@link CreateOption}
118
164
  * @returns 弹出层控制器实例
119
165
  */
120
- export declare function createPopup(options?: CoreOptions): IController;
166
+ export declare function createPopup(options?: CreateOption): IController;
121
167
 
122
168
  export declare const definePlugin: IDefinePlugin;
123
169
 
170
+ declare type ErrorOption = {
171
+ namespace: string;
172
+ caller: string;
173
+ message: string;
174
+ } | ILog;
175
+
176
+ /**
177
+ * 提取组件的 props 所允许的所有类型
178
+ *
179
+ * - 相较于 `ExtractComponentPropTypes` 返回的类型,还提供了底层对 `VNodeProps`
180
+ * 和 `AllowedComponentProps` 类型属性的支持
181
+ * - 支持同步组件和异步组件
182
+ * - 对于异步组件,除了支持 `defineAsyncComponent` 方法定义组件,还支持直接传入
183
+ * ()=>import() 函数。
184
+ */
185
+ declare type ExtractComponentAllPropTypes<TComponent extends Component = Component> = WithDefaultProps<TComponent extends new () => {
186
+ $props: infer TProps;
187
+ } ? TProps : TComponent extends AsyncComponentLoader ? InstanceType<Awaited<ReturnType<TComponent>>['default']>['$props'] : Record<string, any>>;
188
+
189
+ /**
190
+ * 提取组件的 props 类型
191
+ *
192
+ * - 包含组件自定义的属性类型以及通过 `ComponentCustomProps` 接口定义的全局属性类型
193
+ * - 支持同步组件和异步组件
194
+ * - 对于异步组件,除了支持 `defineAsyncComponent` 方法定义组件,还支持直接传入
195
+ * ()=>import() 函数。
196
+ */
197
+ export declare type ExtractComponentPropTypes<TComponent extends Component = Component> = Omit<ExtractComponentAllPropTypes<TComponent>, keyof (VNodeProps & AllowedComponentProps)>;
198
+
199
+ declare type ExtractPluginOption<TPlugin extends PopupPlugin> = TPlugin extends PopupPlugin<infer TOption> ? TOption : never;
200
+
124
201
  declare interface IAnimations extends PopupCustomAnimations {
125
202
  /**
126
203
  * 无动画
@@ -137,7 +214,7 @@ declare interface IAnimations extends PopupCustomAnimations {
137
214
  /**
138
215
  * 缩放缩小
139
216
  */
140
- readonly SCALE_SHRINK: 'scale-shrink';
217
+ readonly SCALE_REDUCE: 'scale-reduce';
141
218
  /**
142
219
  * 顶部飞入
143
220
  */
@@ -157,35 +234,48 @@ declare interface IAnimations extends PopupCustomAnimations {
157
234
  }
158
235
 
159
236
  declare interface IController extends PopupCustomProperties {
237
+ /**
238
+ * 版本号
239
+ */
240
+ readonly version: Version;
160
241
  /**
161
242
  * 安装插件
243
+ *
162
244
  * @param {App} app - Vue应用实例
163
- * @returns {void}
245
+ * @returns {any}
164
246
  */
165
- install(app: App): void;
247
+ install(app: App): any;
166
248
  /**
167
- * 安装插件
168
- * - 可安装使用 `definePlugin` 方法定义的插件
249
+ * 注册插件
250
+ *
251
+ * - 可注册使用 `definePlugin()` 方法定义的插件
252
+ * - 重复注册相同的插件,会被忽略
169
253
  * - 具体请参考{@link IDefinePlugin}
170
254
  */
171
- use(plugin: PopupPlugin): void;
255
+ use<TOption extends PluginOption, TPlugin extends PopupPlugin<TOption>>(plugin: TPlugin, options?: ExtractPluginOption<TPlugin>): void;
172
256
  /**
173
- * 渲染弹出层,返回弹出层实例id,可调用destroy(id)方法销毁弹出层
174
- * @param {RenderOptions} options - 渲染参数
175
- * @returns 弹出层实例id
257
+ * 渲染弹出层
258
+ *
259
+ * - 渲染参数 `component`
260
+ * 是唯一的必填项,其他渲染参数具体请参考{@link RenderOption}
261
+ * - 返回值是弹出层的实例 id ,用于调用 destroy() 方法销毁弹出层
176
262
  */
177
- render(options: RenderOptions): InstanceId;
263
+ render<TComponent extends Component = Component>(options: RenderOption<TComponent>): InstanceId;
178
264
  /**
179
- * 更新弹出层,可更新弹出层参数
180
- * @param {InstanceId} instanceId - 弹出层实例id
181
- * @param {UpdateOptions} options - 更新参数
265
+ * 更新弹出层
266
+ *
267
+ * - 主要用于更新弹出层的渲染参数
268
+ * - 第一个参数需要传入需要更新的弹出层的实例 id
269
+ * - 第二个参数需要传入更新的参数,仅支持部分渲染参数,具体请参考{@link UpdateOption}
182
270
  */
183
- update(instanceId: InstanceId, options: UpdateOptions): void;
271
+ update(instanceId: InstanceId, options: UpdateOption): void;
184
272
  /**
185
273
  * 销毁弹出层
186
- * @param {InstanceId} instanceId - 弹出层实例id
187
- * @param {any} payload - 自定义负载参数,会作为参数传递给创建弹出层时的onUnmounted回调函数
188
- * @returns {Promise<void>}
274
+ *
275
+ * - 传入弹出层的实例 id ,用于销毁指定的弹出层
276
+ * - 第二个参数是自定义负载参数,会作为参数传递给创建弹出层时的 onUnmounted 回调函数
277
+ * - 该函数返回一个 Promise 对象,用于等待弹出层关闭动画完成
278
+ * - 如果弹出层不存在,会在调试模式下打印警告日志
189
279
  */
190
280
  destroy(instanceId: InstanceId, payload?: any): void;
191
281
  }
@@ -193,17 +283,35 @@ declare interface IController extends PopupCustomProperties {
193
283
  declare interface IDefinePlugin {
194
284
  /**
195
285
  * 定义插件
196
- * - 插件是一个对象,包含插件名称和安装方法
197
- * - 安装方法接收一个可扩展自定义属性的控制器实例作为参数,用于扩展弹出层插件的原型属性
286
+ *
287
+ * - 该方法用于定义一个可以直接被 `popup.use` 方法注册的插件
288
+ * - 插件的名称 `name` 必须唯一
289
+ * - 插件的作者 `author` 可以是个人或组织名称
290
+ * - 插件的核心版本要求 `coreVersion` 可以指定插件所适配的最低和最高核心版本,
291
+ * 不符合要求的核心将无法注册该插件
292
+ * - 插件的安装函数 `install` 必须是一个函数,接收三个参数:
293
+ * - 第一个参数接收注册此插件的弹出层控制器实例
294
+ * - 第二个参数接收注册此插件的弹出层的创建配置
295
+ * - 第三个参数接收插件自定义选项,可自行定义,插件使用者可在调用
296
+ * `popup.use` 方法时传入
198
297
  * - 使用示例:
298
+ *
199
299
  * ```ts
200
300
  * import { createPopup, definePlugin } from 'vue-popup-plus'
201
301
  * const popup = createPopup()
302
+ *
303
+ * type TestPluginOption = {
304
+ * logEnable?: boolean
305
+ * }
306
+ *
202
307
  * const plugin = definePlugin({
203
- * // 插件名称,必须唯一
204
308
  * name: 'test',
205
- * // 插件安装时的回调函数,会将控制器实例作为参数传入
206
- * install(popup) {
309
+ * author: 'your name',
310
+ * coreVersionValidator(coreVersion){
311
+ * const requiredVersion = '1.5.0'
312
+ * return coreVersion >= requiredVersion
313
+ * },
314
+ * install(popup, config, { logEnable = false }: TestPluginOption = {}) {
207
315
  * popup.customProperties.test = function (message) {
208
316
  * this.render({
209
317
  * component: () => import('path/Demo.vue'),
@@ -211,12 +319,16 @@ declare interface IDefinePlugin {
211
319
  * message,
212
320
  * },
213
321
  * })
322
+ *
323
+ * if (logEnable) {
324
+ * console.log(message)
325
+ * }
214
326
  * }
215
327
  * },
216
328
  * })
217
329
  * ```
218
330
  */
219
- (options: PopupPlugin): PopupPlugin;
331
+ <TOption extends PluginOption>(options: PopupPlugin<TOption>): PopupPlugin<TOption>;
220
332
  }
221
333
 
222
334
  /**
@@ -230,8 +342,45 @@ declare interface IInstanceId {
230
342
  name: Readonly<string>;
231
343
  }
232
344
 
345
+ export declare interface ILog {
346
+ /**
347
+ * 命名空间
348
+ */
349
+ namespace: string;
350
+ /**
351
+ * 类型
352
+ */
353
+ type: LogType;
354
+ /**
355
+ * 调用者
356
+ */
357
+ caller: string;
358
+ /**
359
+ * 消息
360
+ */
361
+ message: string;
362
+ /**
363
+ * 日志组
364
+ */
365
+ group: LogGroup;
366
+ readonly hasCaller: boolean;
367
+ /**
368
+ * 是否有日志组
369
+ */
370
+ readonly hasGroup: boolean;
371
+ }
372
+
373
+ export declare interface ILogHandler {
374
+ /**
375
+ * 日志处理函数
376
+ *
377
+ * @param log 日志实例
378
+ */
379
+ (log: ILog): any;
380
+ }
381
+
233
382
  export declare class InstanceId implements IInstanceId {
234
- #private;
383
+ private _seed;
235
384
  get seed(): number;
236
385
  get name(): string;
237
386
  constructor(seed: number);
@@ -239,10 +388,12 @@ export declare class InstanceId implements IInstanceId {
239
388
 
240
389
  declare interface IPluginWrappedController extends IController {
241
390
  /**
242
- * 原型属性
391
+ * 控制器实例自定义属性原型对象
392
+ *
243
393
  * - 可在插件的 `install` 方法中扩展方法或属性
244
394
  * - 该属性为只读属性,只允许扩展,并且内置方法不能被覆盖
245
395
  * - 使用示例:
396
+ *
246
397
  * ```ts
247
398
  * // 插件中扩展方法
248
399
  * import { definePlugin } from 'vue-popup-plus'
@@ -267,10 +418,12 @@ declare interface IPluginWrappedController extends IController {
267
418
  */
268
419
  readonly customProperties: ControllerPrototype;
269
420
  /**
270
- * 自定义动画类型
421
+ * 动画类型自定义属性原型对象
422
+ *
271
423
  * - 可在插件的 `install` 方法中扩展动画类型
272
424
  * - 该属性为只读属性,只允许扩展,并且内置动画类型不能被覆盖
273
425
  * - 使用示例:
426
+ *
274
427
  * ```ts
275
428
  * // 插件中扩展动画类型
276
429
  * import { definePlugin } from 'vue-popup-plus'
@@ -278,7 +431,7 @@ declare interface IPluginWrappedController extends IController {
278
431
  * const plugin = definePlugin({
279
432
  * name: 'test',
280
433
  * install(popup) {
281
- * popup.customAnimations.CUSTOM = 'CUSTOM'
434
+ * popup.customAnimations.CUSTOM = 'custom'
282
435
  * },
283
436
  * })
284
437
  * ```
@@ -286,12 +439,135 @@ declare interface IPluginWrappedController extends IController {
286
439
  readonly customAnimations: PopupCustomAnimations;
287
440
  }
288
441
 
289
- declare type PluginInstall = (controller: IPluginWrappedController, config: Readonly<CoreConfig>) => void;
442
+ export declare class Log implements ILog {
443
+ namespace: string;
444
+ type: LogType;
445
+ caller: string;
446
+ message: string;
447
+ group: LogGroup;
448
+ get hasCaller(): boolean;
449
+ get hasGroup(): boolean;
450
+ /**
451
+ * 创建日志实例
452
+ *
453
+ * @param type 日志类型
454
+ * @param name 日志名称
455
+ * @param message 日志消息
456
+ * @param group 日志组
457
+ * @returns 日志实例
458
+ */
459
+ constructor({ type, caller, message, group, }?: LogOption);
460
+ }
461
+
462
+ export declare type LogGroup = Array<LogGroupItem>;
463
+
464
+ declare type LogGroupDataItem = {
465
+ /**
466
+ * 数据组元素类型
467
+ */
468
+ type: typeof LogGroupItemType.Data;
469
+ /**
470
+ * 数据项名称
471
+ */
472
+ dataName: string;
473
+ /**
474
+ * 数据项值
475
+ */
476
+ dataValue: any;
477
+ /**
478
+ * 数据项约束类型
479
+ *
480
+ * - 如不传,将自动设置为 any
481
+ */
482
+ dataType?: string;
483
+ };
484
+
485
+ declare type LogGroupDefaultItem = {
486
+ /**
487
+ * 组元素类型
488
+ */
489
+ type?: typeof LogGroupItemType.Default;
490
+ /**
491
+ * 组元素消息
492
+ */
493
+ message: string;
494
+ };
495
+
496
+ declare type LogGroupItem = LogGroupDefaultItem | LogGroupDataItem;
497
+
498
+ /**
499
+ * 日志组元素类型
500
+ */
501
+ export declare const LogGroupItemType: {
502
+ /**
503
+ * 默认类型
504
+ */
505
+ readonly Default: "default";
506
+ /**
507
+ * 数据类型
508
+ */
509
+ readonly Data: "data";
510
+ };
511
+
512
+ export declare type LogGroupItemType = (typeof LogGroupItemType)[keyof typeof LogGroupItemType];
513
+
514
+ export declare type LogOption = {
515
+ /**
516
+ * 日志类型
517
+ */
518
+ type?: LogType;
519
+ /**
520
+ * 日志调用者
521
+ */
522
+ caller?: string;
523
+ /**
524
+ * 日志消息
525
+ */
526
+ message?: string;
527
+ /**
528
+ * 日志组
529
+ *
530
+ * - 用于在日志消息中展示多个数据项
531
+ */
532
+ group?: LogGroup;
533
+ };
534
+
535
+ /**
536
+ * 日志类型
537
+ */
538
+ export declare const LogType: {
539
+ /**
540
+ * 成功日志
541
+ */
542
+ readonly Success: "success";
543
+ /**
544
+ * 信息日志
545
+ */
546
+ readonly Info: "info";
547
+ /**
548
+ * 警告日志
549
+ */
550
+ readonly Warning: "warning";
551
+ /**
552
+ * 错误日志
553
+ */
554
+ readonly Error: "error";
555
+ };
556
+
557
+ export declare type LogType = (typeof LogType)[keyof typeof LogType];
558
+
559
+ export declare type Placement = 'left-top' | 'left' | 'left-bottom' | 'top' | 'center' | 'bottom' | 'right-top' | 'right' | 'right-bottom';
560
+
561
+ declare type PluginInstall<TOption extends PluginOption> = (controller: IPluginWrappedController, config: Readonly<CoreConfig>, option?: TOption) => void;
562
+
563
+ declare type PluginOption = Record<string, any>;
290
564
 
291
565
  export declare const POPUP_ANIMATIONS: IAnimations;
292
566
 
293
567
  /**
294
- * 弹出层内部组件注入属性,在弹出层内部渲染的所有子代组件中,都可以通过 inject 注入弹出层所提供的相关参数
568
+ * 弹出层内部组件注入属性
569
+ *
570
+ * - 在弹出层内部渲染的所有子代组件中,都可以通过 inject 注入弹出层所提供的相关参数
295
571
  */
296
572
  export declare const POPUP_COMPONENT_INJECTS: Readonly<ComponentInjectKeys>;
297
573
 
@@ -301,11 +577,76 @@ export declare interface PopupCustomAnimations {
301
577
  export declare interface PopupCustomProperties {
302
578
  }
303
579
 
304
- export declare type PopupPlugin = {
580
+ export declare class PopupError extends Error {
581
+ /**
582
+ * 弹出层错误类
583
+ *
584
+ * - 建议从 {@link ILog} 日志实例创建错误
585
+ * @param {ErrorOption} options 错误参数
586
+ * @example
587
+ * new PopupError(new Log({
588
+ * type: LogType.Error,
589
+ * caller: 'controller.render()',
590
+ * message: '弹出层渲染失败',
591
+ * }))
592
+ */
593
+ constructor({ namespace, caller, message }: ErrorOption);
594
+ }
595
+
596
+ export declare type PopupPlugin<TOption extends PluginOption = never> = {
597
+ /**
598
+ * 插件名称
599
+ *
600
+ * - 插件名称必须唯一
601
+ * - 名称冲突将导致插件注册失败
602
+ */
305
603
  name: string;
306
- install: PluginInstall;
604
+ /**
605
+ * 插件安装函数
606
+ *
607
+ * - 第一个参数接收注册此插件的弹出层控制器实例
608
+ * - 第二个参数接收注册此插件的弹出层的创建配置
609
+ * - 第三个参数接收插件自定义选项,可自行定义,插件使用者可在调用
610
+ * `popup.use` 方法时传入
611
+ */
612
+ install: PluginInstall<TOption>;
613
+ /**
614
+ * 插件作者
615
+ *
616
+ * - 插件作者可以是个人或组织名称
617
+ * - 从核心 `1.5.0` 版本开始,不设置插件作者将会导致在插件注册时
618
+ * 通过日志输出一个警告,用以提示插件使用者相关风险
619
+ */
620
+ author?: string;
621
+ /**
622
+ * 插件核心版本校验函数
623
+ *
624
+ * - 插件作者需要在插件安装函数中校验弹出层核心版本是否符合插件要求
625
+ * - 该函数需要返回一个布尔值,`true` 表示核心版本符合要求,`false`
626
+ * 表示不符合要求,核心将会阻止该插件的注册
627
+ * - 从核心 `1.5.0` 版本开始,不设置该校验函数将会导致在插件注册时
628
+ * 通过日志输出一个警告,用以提示插件使用者相关风险
629
+ */
630
+ /**
631
+ * 插件核心版本要求
632
+ *
633
+ * - 插件作者可以指定插件所适配的最低和最高核心版本
634
+ * - 不符合要求的核心将无法注册该插件
635
+ */
636
+ requiredCoreVersion?: {
637
+ /**
638
+ * 插件所适配的最低核心版本
639
+ */
640
+ min?: Version;
641
+ /**
642
+ * 插件所适配的最高核心版本
643
+ */
644
+ max?: Version;
645
+ };
307
646
  };
308
647
 
648
+ export declare const PopupRoot: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
649
+
309
650
  declare type PopupViewStyle = ComputedRef<{
310
651
  width: number;
311
652
  height: number;
@@ -314,26 +655,46 @@ declare type PopupViewStyle = ComputedRef<{
314
655
  translateY: number;
315
656
  }>;
316
657
 
317
- declare type RenderComponentOptions = {
658
+ /**
659
+ * 打印日志
660
+ *
661
+ * - 仅在开启调试模式时打印输出日志
662
+ * @param log 日志实例
663
+ * @returns
664
+ */
665
+ export declare const printLog: ILogHandler;
666
+
667
+ declare type RenderComponentOptions<TComponent extends Component = Component> = {
318
668
  /**
319
- * 弹出层渲染的组件,想要创建一个弹出层,这个唯一必要的参数。它的值可以是一个同步组件,也可以是一个异步组件的 import() 函数。
320
- * @example
321
- * // 同步组件
322
- * import Demo from 'path/Demo.vue'
323
- * popup.render({
324
- * component: Demo,
325
- * })
669
+ * 弹出层渲染的组件
326
670
  *
671
+ * - 要创建一个弹出层,这是唯一必要的参数。
672
+ * - 支持同步组件和异步组件,为了提高加载速度,优化构建体积,建议使用异步组件。
673
+ * - 对于异步组件,无需使用 `defineAsyncComponent` 方法定义组件,直接传入
674
+ * ()=>import() 函数即可。
675
+ * - 使用示例:
676
+ *
677
+ * ```ts
327
678
  * // 异步组件
328
679
  * popup.render({
329
680
  * component: () => import('path/Demo.vue'),
330
681
  * })
682
+ *
683
+ * // 同步组件
684
+ * import Demo from 'path/Demo.vue'
685
+ * popup.render({
686
+ * component: Demo,
687
+ * })
688
+ * ```
331
689
  */
332
- component: Component;
690
+ component: TComponent;
333
691
  /**
334
692
  * 弹出层渲染组件的 props ,会传递给弹出层组件
693
+ * - 会自动根据传入的组件进行类型推导,提供完善的类型提示
694
+ * - 除了组件的属性,还支持传入组件的事件监听器,事件监听器的名称需要以 `on` 开头,
695
+ * 例如 `onClick` 、 `onInput` 等。
335
696
  */
336
- componentProps?: Record<string, any>;
697
+ componentProps?: ExtractComponentPropTypes<TComponent>;
337
698
  /**
338
699
  * 弹出层渲染之后的回调
339
700
  */
@@ -346,183 +707,250 @@ declare type RenderComponentOptions = {
346
707
 
347
708
  declare type RenderConfigOptions = {
348
709
  /**
349
- * 弹出层挂载的父元素,不指定时,默认挂载到 body 元素下
710
+ * 弹出层挂载的父元素
711
+ *
712
+ * - 不指定时,默认挂载到 body 元素下
350
713
  */
351
714
  appendTo?: Element | string;
352
715
  /**
353
- * 弹出层是否显示遮罩层,默认值为 true
716
+ * 弹出层是否显示遮罩层
717
+ *
718
+ * - 默认值为 true
354
719
  */
355
720
  mask?: boolean;
356
721
  /**
357
- * 点击遮罩层是否关闭弹出层,默认值为 false ,仅在 mask 为 true 时有效
722
+ * 点击遮罩层是否关闭弹出层
723
+ *
724
+ * - 默认值为 false ,仅在 mask 为 true 时有效
358
725
  */
359
726
  maskClickClose?: boolean;
360
727
  /**
361
- * 弹出层是否禁用窗口滚动,默认值为 true
728
+ * 弹出层是否禁用窗口滚动
729
+ *
730
+ * - 默认值为 true
362
731
  */
363
732
  disableScroll?: boolean;
364
733
  };
365
734
 
366
- export declare type RenderOptions = RenderConfigOptions & RenderComponentOptions & RenderStyleOptions;
735
+ export declare type RenderOption<TComponent extends Component = Component> = RenderComponentOptions<TComponent> & RenderConfigOptions & RenderStyleOptions;
367
736
 
368
737
  declare type RenderStyleOptions = {
369
738
  /**
370
- * 弹出层宽度,默认为 auto,即自适应,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
739
+ * 弹出层宽度
740
+ *
741
+ * - 默认为 auto,即自适应,支持 string 和 number 类型,string
742
+ * 类型更为灵活,number 类型方便计算
743
+ *
371
744
  * @example
372
- * // px
373
- * width: '300px',
374
- * // rem
375
- * width: '30rem',
376
- * // vw
377
- * width: '30vw',
378
- * // 百分比
379
- * width: '30%',
380
- * // css 动态计算
381
- * width: 'calc(50% + 20px)',
382
- * // css 变量
383
- * width: 'var(--width)',
384
- * // number 类型,方便计算,单位为 px
385
- * width: 300,
745
+ * // px
746
+ * width: '300px',
747
+ * // rem
748
+ * width: '30rem',
749
+ * // vw
750
+ * width: '30vw',
751
+ * // 百分比
752
+ * width: '30%',
753
+ * // css 动态计算
754
+ * width: 'calc(50% + 20px)',
755
+ * // css 变量
756
+ * width: 'var(--width)',
757
+ * // number 类型,方便计算,单位为 px
758
+ * width: 300,
386
759
  */
387
760
  width?: string | number;
388
761
  /**
389
- * 弹出层最大宽度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
762
+ * 弹出层最大宽度
763
+ *
764
+ * - 默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number
765
+ * 类型方便计算
766
+ *
390
767
  * @example
391
- * // px
392
- * maxWidth: '300px',
393
- * // rem
394
- * maxWidth: '30rem',
395
- * // vw
396
- * maxWidth: '30vw',
397
- * // 百分比
398
- * maxWidth: '30%',
399
- * // css 动态计算
400
- * maxWidth: 'calc(50% + 20px)',
401
- * // css 变量
402
- * maxWidth: 'var(--width)',
403
- * // number 类型,方便计算,单位为 px
404
- * maxWidth: 300,
768
+ * // px
769
+ * maxWidth: '300px',
770
+ * // rem
771
+ * maxWidth: '30rem',
772
+ * // vw
773
+ * maxWidth: '30vw',
774
+ * // 百分比
775
+ * maxWidth: '30%',
776
+ * // css 动态计算
777
+ * maxWidth: 'calc(50% + 20px)',
778
+ * // css 变量
779
+ * maxWidth: 'var(--width)',
780
+ * // number 类型,方便计算,单位为 px
781
+ * maxWidth: 300,
405
782
  */
406
783
  maxWidth?: string | number;
407
784
  /**
408
- * 弹出层最小宽度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
785
+ * 弹出层最小宽度
786
+ *
787
+ * - 默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number
788
+ * 类型方便计算
789
+ *
409
790
  * @example
410
- * // px
411
- * minWidth: '300px',
412
- * // rem
413
- * minWidth: '30rem',
414
- * // vw
415
- * minWidth: '30vw',
416
- * // 百分比
417
- * minWidth: '30%',
418
- * // css 动态计算
419
- * minWidth: 'calc(50% + 20px)',
420
- * // css 变量
421
- * minWidth: 'var(--width)',
422
- * // number 类型,方便计算,单位为 px
423
- * minWidth: 300,
791
+ * // px
792
+ * minWidth: '300px',
793
+ * // rem
794
+ * minWidth: '30rem',
795
+ * // vw
796
+ * minWidth: '30vw',
797
+ * // 百分比
798
+ * minWidth: '30%',
799
+ * // css 动态计算
800
+ * minWidth: 'calc(50% + 20px)',
801
+ * // css 变量
802
+ * minWidth: 'var(--width)',
803
+ * // number 类型,方便计算,单位为 px
804
+ * minWidth: 300,
424
805
  */
425
806
  minWidth?: string | number;
426
807
  /**
427
- * 弹出层高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
808
+ * 弹出层高度
809
+ *
810
+ * - 默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number
811
+ * 类型方便计算
812
+ *
428
813
  * @example
429
- * // px
430
- * height: '300px',
431
- * // rem
432
- * height: '30rem',
433
- * // vh
434
- * height: '30vh',
435
- * // 百分比
436
- * height: '30%',
437
- * // css 动态计算
438
- * height: 'calc(50% + 20px)',
439
- * // css 变量
440
- * height: 'var(--height)',
441
- * // number 类型,方便计算,单位为 px
442
- * height: 300,
814
+ * // px
815
+ * height: '300px',
816
+ * // rem
817
+ * height: '30rem',
818
+ * // vh
819
+ * height: '30vh',
820
+ * // 百分比
821
+ * height: '30%',
822
+ * // css 动态计算
823
+ * height: 'calc(50% + 20px)',
824
+ * // css 变量
825
+ * height: 'var(--height)',
826
+ * // number 类型,方便计算,单位为 px
827
+ * height: 300,
443
828
  */
444
829
  height?: string | number;
445
830
  /**
446
- * 弹出层最大高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
831
+ * 弹出层最大高度
832
+ *
833
+ * - 默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number
834
+ * 类型方便计算
835
+ *
447
836
  * @example
448
- * // px
449
- * maxHeight: '300px',
450
- * // rem
451
- * maxHeight: '30rem',
452
- * // vh
453
- * maxHeight: '30vh',
454
- * // 百分比
455
- * maxHeight: '30%',
456
- * // css 动态计算
457
- * maxHeight: 'calc(50% + 20px)',
458
- * // css 变量
459
- * maxHeight: 'var(--height)',
460
- * // number 类型,方便计算,单位为 px
461
- * maxHeight: 300,
837
+ * // px
838
+ * maxHeight: '300px',
839
+ * // rem
840
+ * maxHeight: '30rem',
841
+ * // vh
842
+ * maxHeight: '30vh',
843
+ * // 百分比
844
+ * maxHeight: '30%',
845
+ * // css 动态计算
846
+ * maxHeight: 'calc(50% + 20px)',
847
+ * // css 变量
848
+ * maxHeight: 'var(--height)',
849
+ * // number 类型,方便计算,单位为 px
850
+ * maxHeight: 300,
462
851
  */
463
852
  maxHeight?: string | number;
464
853
  /**
465
- * 弹出层最小高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
854
+ * 弹出层最小高度
855
+ *
856
+ * - 默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number
857
+ * 类型方便计算
858
+ *
466
859
  * @example
467
- * // px
468
- * minHeight: '300px',
469
- * // rem
470
- * minHeight: '30rem',
471
- * // vh
472
- * minHeight: '30vh',
473
- * // 百分比
474
- * minHeight: '30%',
475
- * // css 动态计算
476
- * minHeight: 'calc(50% + 20px)',
477
- * // css 变量
478
- * minHeight: 'var(--height)',
479
- * // number 类型,方便计算,单位为 px
480
- * minHeight: 300,
860
+ * // px
861
+ * minHeight: '300px',
862
+ * // rem
863
+ * minHeight: '30rem',
864
+ * // vh
865
+ * minHeight: '30vh',
866
+ * // 百分比
867
+ * minHeight: '30%',
868
+ * // css 动态计算
869
+ * minHeight: 'calc(50% + 20px)',
870
+ * // css 变量
871
+ * minHeight: 'var(--height)',
872
+ * // number 类型,方便计算,单位为 px
873
+ * minHeight: 300,
481
874
  */
482
875
  minHeight?: string | number;
483
876
  /**
484
- * 弹出层视图动画类型,默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看 {@link IAnimations}
877
+ * 弹出层位置
878
+ *
879
+ * - 默认为 center ,即居中显示
880
+ * - 更多位置请查看 {@link Placement}
881
+ * @since 1.5.0
882
+ */
883
+ placement?: Placement;
884
+ /**
885
+ * 弹出层视图动画类型
886
+ *
887
+ * - 默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看
888
+ * {@link IAnimations}
485
889
  */
486
890
  viewAnimation?: Animation_2;
487
891
  /**
488
- * 弹出层视图水平偏移量,默认为 0 ,单位为 px
892
+ * 弹出层视图水平偏移量
893
+ *
894
+ * - 默认为 0 ,单位为 px
489
895
  */
490
896
  viewTranslateX?: number;
491
897
  /**
492
- * 弹出层视图垂直偏移量,默认为 0 ,单位为 px
898
+ * 弹出层视图垂直偏移量
899
+ *
900
+ * - 默认为 0 ,单位为 px
493
901
  */
494
902
  viewTranslateY?: number;
495
903
  /**
496
- * 弹出层视图是否允许超出窗口边界,默认为 false
904
+ * 弹出层视图是否允许超出窗口边界
905
+ *
906
+ * - 默认为 false
497
907
  */
498
908
  viewTranslateOverflow?: boolean;
499
909
  /**
500
- * 弹出层遮罩动画类型,默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看 {@link IAnimations}
910
+ * 弹出层遮罩动画类型
911
+ *
912
+ * - 默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看
913
+ * {@link IAnimations}
501
914
  */
502
915
  maskAnimation?: Animation_2;
503
916
  /**
504
- * 弹出层遮罩是否启用模糊效果,默认为 true
917
+ * 弹出层遮罩是否启用模糊效果
918
+ *
919
+ * - 默认为 true
920
+ * @since 1.3.0
505
921
  */
506
922
  maskBlur?: boolean;
507
923
  /**
508
- * 弹出层动画时长,默认为 100 ,单位为 毫秒
924
+ * 弹出层动画时长
925
+ *
926
+ * - 默认为 100 ,单位为 毫秒
509
927
  */
510
928
  animationDuration?: number;
511
929
  /**
512
- * 弹出层 zIndex ,若不设置,则使用全局递增的 zIndex 值
930
+ * 弹出层 zIndex
931
+ *
932
+ * - 若不设置,则使用全局递增的 zIndex 值
513
933
  */
514
934
  zIndex?: number;
515
935
  };
516
936
 
517
- export declare type UpdateOptions = Partial<RenderStyleOptions>;
937
+ export declare type UpdateOption = Partial<RenderStyleOptions>;
518
938
 
519
939
  /**
520
940
  * 获取弹出层控制器实例
941
+ *
942
+ * - 必须先调用 {@link createPopup} 创建弹出层控制器实例,才能使用该函数
943
+ * ,否则会抛出异常
944
+ *
521
945
  * @returns 弹出层控制器实例
522
946
  */
523
947
  export declare function usePopup(): IController;
524
948
 
525
- export { version }
949
+ export declare type Version = `${number}.${number}.${number}`;
950
+
951
+ export declare const version: Version;
952
+
953
+ declare type WithDefaultProps<T> = T extends Record<string, any> ? T : Record<string, any>;
526
954
 
527
955
  export { }
528
956