vue-popup-plus 1.4.0 → 1.5.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/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Vue Popup Plus 🚀
2
+
3
+ 一个功能强大、灵活易用的 Vue 3 弹窗组件库,让弹窗管理变得简单而优雅。
4
+
5
+ [![Vue 3](https://img.shields.io/badge/Vue-3.x-brightgreen.svg)](https://vuejs.org/)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)
7
+ [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Version](https://img.shields.io/badge/version-1.0.0-orange.svg)](https://github.com/yourusername/vue-popup-plus)
9
+
10
+ ## ✨ 特性
11
+
12
+ - 🎯 **简单易用** - 简洁的 API,快速集成到您的项目中
13
+ - 🔌 **可扩展** - 自定义弹窗内容和样式,满足各种场景需求
14
+ - 🎭 **动画支持** - 内置多种动画效果,让弹窗展示更生动
15
+ - 📱 **响应式设计** - 完美适配各种屏幕尺寸
16
+ - 🧩 **TypeScript 支持** - 完整的类型定义,提供良好的开发体验
17
+
18
+ ## 📦 安装
19
+
20
+ ```bash
21
+ # 使用 npm
22
+ npm install vue-popup-plus
23
+
24
+ # 使用 yarn
25
+ yarn add vue-popup-plus
26
+
27
+ # 使用 pnpm
28
+ pnpm add vue-popup-plus
29
+ ```
30
+
31
+ ## 📚 文档
32
+
33
+ 查看我们的[在线文档](http://vue-popup-plus.styzy.cn)获取更多详细信息和高级用法。
34
+
35
+ ## 🚀 快速开始
36
+
37
+ ### 全局注册
38
+
39
+ ```js
40
+ import { createApp } from 'vue'
41
+ import { createPopup } from 'vue-popup-plus'
42
+ import App from './App.vue'
43
+
44
+ const app = createApp(App)
45
+ const popup = createPopup()
46
+
47
+ app.use(popup)
48
+
49
+ app.mount('#app')
50
+ ```
51
+
52
+ ### 基本使用
53
+
54
+ ```vue
55
+ <template>
56
+ <button @click="showPopup">显示弹窗</button>
57
+ </template>
58
+
59
+ <script setup>
60
+ import { usePopup } from 'vue-popup-plus'
61
+
62
+ const popup = usePopup()
63
+
64
+ const showPopup = () => {
65
+ popup.render({
66
+ // 组件
67
+ component: () => import('./components/Demo.vue'),
68
+ // 组件属性
69
+ componentProps: {
70
+ // 根据你的组件属性传入
71
+ },
72
+ width: 400,
73
+ maxHeight: 600,
74
+ mask: false,
75
+ })
76
+ }
77
+ </script>
78
+ ```
79
+
80
+ ## 🤝 贡献
81
+
82
+ 欢迎贡献代码、报告问题或提出新功能建议!请查看[贡献指南](CONTRIBUTING.md)了解更多信息。
83
+
84
+ ## 📄 许可证
85
+
86
+ [MIT](LICENSE) © Your Name
@@ -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
 
@@ -130,13 +136,21 @@ export declare type CreateOption = {
130
136
  * ```
131
137
  */
132
138
  prototypeName?: string;
139
+ /**
140
+ * 日志器
141
+ *
142
+ * - 默认使用内置的日志器,仅会在开启调试模式时在控制台输出日志
143
+ * - 你可以自定义日志器,需要注意日志的接收将不会受到调试模式的影响,
144
+ * 无论调试模式是否开启,日志都将被传递给自定义的日志器。
145
+ */
146
+ logHandler?: ILogHandler;
133
147
  /**
134
148
  * 开启调试模式
135
149
  *
136
150
  * - 默认为 false
137
151
  * - 注意:开启调试模式可能会影响到性能,不建议在生产环境开启。
138
- * - 开启后,所有的弹出层将以 Vue app 应用实例的方式创建,可通过 Vue DevTools
139
- * 开发者工具直接访问到内部的相关组件,方便开发者调试。
152
+ * - 开启后,将会在控制台输出日志,同时如果未注册根组件,调试模式下
153
+ * 将会使用 Vue App 实例渲染弹出层,方便开发者调试。
140
154
  */
141
155
  debugMode?: boolean;
142
156
  };
@@ -144,7 +158,7 @@ export declare type CreateOption = {
144
158
  /**
145
159
  * 创建一个弹出层控制器实例
146
160
  *
147
- * - 该实例需要通过 app.use() 安装后才能使用
161
+ * - 该实例需要被 Vue 的 app.use() 函数后才能使用
148
162
  *
149
163
  * @param options 创建配置,具体请参考 {@link CreateOption}
150
164
  * @returns 弹出层控制器实例
@@ -153,6 +167,35 @@ export declare function createPopup(options?: CreateOption): IController;
153
167
 
154
168
  export declare const definePlugin: IDefinePlugin;
155
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
+
156
199
  declare type ExtractPluginOption<TPlugin extends PopupPlugin> = TPlugin extends PopupPlugin<infer TOption> ? TOption : never;
157
200
 
158
201
  declare interface IAnimations extends PopupCustomAnimations {
@@ -194,18 +237,19 @@ declare interface IController extends PopupCustomProperties {
194
237
  /**
195
238
  * 版本号
196
239
  */
197
- readonly version: string;
240
+ readonly version: Version;
198
241
  /**
199
242
  * 安装插件
200
243
  *
201
244
  * @param {App} app - Vue应用实例
202
- * @returns {void}
245
+ * @returns {any}
203
246
  */
204
- install(app: App): void;
247
+ install(app: App): any;
205
248
  /**
206
- * 安装插件
249
+ * 注册插件
207
250
  *
208
- * - 可安装使用 `definePlugin` 方法定义的插件
251
+ * - 可注册使用 `definePlugin()` 方法定义的插件
252
+ * - 重复注册相同的插件,会被忽略
209
253
  * - 具体请参考{@link IDefinePlugin}
210
254
  */
211
255
  use<TOption extends PluginOption, TPlugin extends PopupPlugin<TOption>>(plugin: TPlugin, options?: ExtractPluginOption<TPlugin>): void;
@@ -216,7 +260,7 @@ declare interface IController extends PopupCustomProperties {
216
260
  * 是唯一的必填项,其他渲染参数具体请参考{@link RenderOption}
217
261
  * - 返回值是弹出层的实例 id ,用于调用 destroy() 方法销毁弹出层
218
262
  */
219
- render(options: RenderOption): InstanceId;
263
+ render<TComponent extends Component = Component>(options: RenderOption<TComponent>): InstanceId;
220
264
  /**
221
265
  * 更新弹出层
222
266
  *
@@ -231,6 +275,7 @@ declare interface IController extends PopupCustomProperties {
231
275
  * - 传入弹出层的实例 id ,用于销毁指定的弹出层
232
276
  * - 第二个参数是自定义负载参数,会作为参数传递给创建弹出层时的 onUnmounted 回调函数
233
277
  * - 该函数返回一个 Promise 对象,用于等待弹出层关闭动画完成
278
+ * - 如果弹出层不存在,会在调试模式下打印警告日志
234
279
  */
235
280
  destroy(instanceId: InstanceId, payload?: any): void;
236
281
  }
@@ -239,11 +284,14 @@ declare interface IDefinePlugin {
239
284
  /**
240
285
  * 定义插件
241
286
  *
242
- * - 该方法用于定义一个可以直接被 `popup.use` 方法安装的插件
287
+ * - 该方法用于定义一个可以直接被 `popup.use` 方法注册的插件
243
288
  * - 插件的名称 `name` 必须唯一
289
+ * - 插件的作者 `author` 可以是个人或组织名称
290
+ * - 插件的核心版本要求 `coreVersion` 可以指定插件所适配的最低和最高核心版本,
291
+ * 不符合要求的核心将无法注册该插件
244
292
  * - 插件的安装函数 `install` 必须是一个函数,接收三个参数:
245
- * - 第一个参数接收安装此插件的弹出层控制器实例
246
- * - 第二个参数接收安装此插件的弹出层的创建配置
293
+ * - 第一个参数接收注册此插件的弹出层控制器实例
294
+ * - 第二个参数接收注册此插件的弹出层的创建配置
247
295
  * - 第三个参数接收插件自定义选项,可自行定义,插件使用者可在调用
248
296
  * `popup.use` 方法时传入
249
297
  * - 使用示例:
@@ -258,6 +306,11 @@ declare interface IDefinePlugin {
258
306
  *
259
307
  * const plugin = definePlugin({
260
308
  * name: 'test',
309
+ * author: 'your name',
310
+ * coreVersionValidator(coreVersion){
311
+ * const requiredVersion = '1.5.0'
312
+ * return coreVersion >= requiredVersion
313
+ * },
261
314
  * install(popup, config, { logEnable = false }: TestPluginOption = {}) {
262
315
  * popup.customProperties.test = function (message) {
263
316
  * this.render({
@@ -289,8 +342,45 @@ declare interface IInstanceId {
289
342
  name: Readonly<string>;
290
343
  }
291
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
+
292
382
  export declare class InstanceId implements IInstanceId {
293
- #private;
383
+ private _seed;
294
384
  get seed(): number;
295
385
  get name(): string;
296
386
  constructor(seed: number);
@@ -349,6 +439,125 @@ declare interface IPluginWrappedController extends IController {
349
439
  readonly customAnimations: PopupCustomAnimations;
350
440
  }
351
441
 
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
+
352
561
  declare type PluginInstall<TOption extends PluginOption> = (controller: IPluginWrappedController, config: Readonly<CoreConfig>, option?: TOption) => void;
353
562
 
354
563
  declare type PluginOption = Record<string, any>;
@@ -368,24 +577,76 @@ export declare interface PopupCustomAnimations {
368
577
  export declare interface PopupCustomProperties {
369
578
  }
370
579
 
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
+
371
596
  export declare type PopupPlugin<TOption extends PluginOption = never> = {
372
597
  /**
373
598
  * 插件名称
374
599
  *
375
600
  * - 插件名称必须唯一
601
+ * - 名称冲突将导致插件注册失败
376
602
  */
377
603
  name: string;
378
604
  /**
379
605
  * 插件安装函数
380
606
  *
381
- * - 第一个参数接收安装此插件的弹出层控制器实例
382
- * - 第二个参数接收安装此插件的弹出层的创建配置
607
+ * - 第一个参数接收注册此插件的弹出层控制器实例
608
+ * - 第二个参数接收注册此插件的弹出层的创建配置
383
609
  * - 第三个参数接收插件自定义选项,可自行定义,插件使用者可在调用
384
610
  * `popup.use` 方法时传入
385
611
  */
386
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
+ };
387
646
  };
388
647
 
648
+ export declare const PopupRoot: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
649
+
389
650
  declare type PopupViewStyle = ComputedRef<{
390
651
  width: number;
391
652
  height: number;
@@ -394,7 +655,16 @@ declare type PopupViewStyle = ComputedRef<{
394
655
  translateY: number;
395
656
  }>;
396
657
 
397
- 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> = {
398
668
  /**
399
669
  * 弹出层渲染的组件
400
670
  *
@@ -417,11 +687,14 @@ declare type RenderComponentOptions = {
417
687
  * })
418
688
  * ```
419
689
  */
420
- component: Component;
690
+ component: TComponent;
421
691
  /**
422
692
  * 弹出层渲染组件的 props ,会传递给弹出层组件
693
+ * - 会自动根据传入的组件进行类型推导,提供完善的类型提示
694
+ * - 除了组件的属性,还支持传入组件的事件监听器,事件监听器的名称需要以 `on` 开头,
695
+ * 例如 `onClick` 、 `onInput` 等。
423
696
  */
424
- componentProps?: Record<string, any>;
697
+ componentProps?: ExtractComponentPropTypes<TComponent>;
425
698
  /**
426
699
  * 弹出层渲染之后的回调
427
700
  */
@@ -459,7 +732,7 @@ declare type RenderConfigOptions = {
459
732
  disableScroll?: boolean;
460
733
  };
461
734
 
462
- export declare type RenderOption = RenderConfigOptions & RenderComponentOptions & RenderStyleOptions;
735
+ export declare type RenderOption<TComponent extends Component = Component> = RenderComponentOptions<TComponent> & RenderConfigOptions & RenderStyleOptions;
463
736
 
464
737
  declare type RenderStyleOptions = {
465
738
  /**
@@ -600,6 +873,14 @@ declare type RenderStyleOptions = {
600
873
  * minHeight: 300,
601
874
  */
602
875
  minHeight?: string | number;
876
+ /**
877
+ * 弹出层位置
878
+ *
879
+ * - 默认为 center ,即居中显示
880
+ * - 更多位置请查看 {@link Placement}
881
+ * @since 1.5.0
882
+ */
883
+ placement?: Placement;
603
884
  /**
604
885
  * 弹出层视图动画类型
605
886
  *
@@ -633,7 +914,10 @@ declare type RenderStyleOptions = {
633
914
  */
634
915
  maskAnimation?: Animation_2;
635
916
  /**
636
- * 弹出层遮罩是否启用模糊效果,默认为 true
917
+ * 弹出层遮罩是否启用模糊效果
918
+ *
919
+ * - 默认为 true
920
+ * @since 1.3.0
637
921
  */
638
922
  maskBlur?: boolean;
639
923
  /**
@@ -655,11 +939,18 @@ export declare type UpdateOption = Partial<RenderStyleOptions>;
655
939
  /**
656
940
  * 获取弹出层控制器实例
657
941
  *
942
+ * - 必须先调用 {@link createPopup} 创建弹出层控制器实例,才能使用该函数
943
+ * ,否则会抛出异常
944
+ *
658
945
  * @returns 弹出层控制器实例
659
946
  */
660
947
  export declare function usePopup(): IController;
661
948
 
662
- 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>;
663
954
 
664
955
  export { }
665
956