vue-popup-plus 1.0.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.
@@ -0,0 +1,363 @@
1
+ import { App } from 'vue';
2
+ import { Component } from 'vue';
3
+ import { InjectionKey } from 'vue';
4
+ import { version } from '../package.json';
5
+
6
+ /**
7
+ * 组件注入键类型
8
+ */
9
+ declare type ComponentInjectKeys = {
10
+ /**
11
+ * 当前组件所在弹出层的实例ID,可用于销毁当前弹出层
12
+ * @example
13
+ * // 弹出层渲染的所有子代组件中
14
+ * const instanceId = inject(POPUP_COMPONENT_INJECT_KEYS.INSTANCE_ID)
15
+ *
16
+ * // 销毁当前弹出层
17
+ * this.$popup.destroy(instanceId)
18
+ */
19
+ INSTANCE_ID: InjectionKey<InstanceId>;
20
+ };
21
+
22
+ declare type CoreOptions = {
23
+ /**
24
+ * 弹出层 zIndex 基础值,默认为1000,每次生成弹出层时,除非 render() 方法传入 zIndex,否则使用此基础值,每次使用后会自动递增
25
+ */
26
+ zIndex?: number;
27
+ /**
28
+ * 弹出层控制器挂载在 Vue 实例上的属性名,默认为 $popup ,这在使用选项式API时可以在组件内通过this.$popup 访问控制器实例,如需自定义属性名,请参考如下代码:
29
+ *
30
+ * @example
31
+ * // 初始化插件
32
+ * createPopup({
33
+ * prototypeName: '$customPopup'
34
+ * })
35
+ *
36
+ * // 在组件内访问
37
+ * this.$customPopup.render({
38
+ * component: Demo,
39
+ * })
40
+ * @end
41
+ * @important 注意,如果你使用 TypeScript,则自定义属性名称需要手动同步添加类型扩展,扩展代码可以放在一个 .ts 文件,或是一个影响整个项目的 *.d.ts 文件中。
42
+ * @example
43
+ * // 添加导出,没有该代码将无法有效扩展
44
+ * export {}
45
+ *
46
+ * // 自定义扩展
47
+ * declare module 'vue' {
48
+ * interface ComponentCustomProperties {
49
+ * $customPopup: VuePopupPlusController
50
+ * }
51
+ * }
52
+ */
53
+ prototypeName?: string;
54
+ };
55
+
56
+ /**
57
+ * 创建一个弹出层控制器实例,该实例需要通过 app.use() 安装到Vue实例上才能使用
58
+ * @param options 弹出层核心配置
59
+ * @returns 弹出层控制器实例
60
+ */
61
+ export declare function createPopup(options?: CoreOptions): PopupController;
62
+
63
+ declare class InstanceId implements PopupInstanceId {
64
+ #private;
65
+ get seed(): number;
66
+ get name(): string;
67
+ constructor(seed: number);
68
+ }
69
+
70
+ /**
71
+ * 动画类型集合
72
+ */
73
+ export declare const POPUP_ANIMATIONS: Readonly<PopupAnimationCollection>;
74
+
75
+ /**
76
+ * 弹出层内部组件注入属性,在弹出层内部渲染的所有子代组件中,都可以通过 inject 注入弹出层所提供的相关参数
77
+ */
78
+ export declare const POPUP_COMPONENT_INJECT_KEYS: Readonly<ComponentInjectKeys>;
79
+
80
+ /**
81
+ * 动画类型集合类型
82
+ */
83
+ declare interface PopupAnimationCollection {
84
+ /**
85
+ * 无动画
86
+ */
87
+ NONE: symbol;
88
+ /**
89
+ * 淡入淡出
90
+ */
91
+ FADE: symbol;
92
+ /**
93
+ * 缩放放大
94
+ */
95
+ SCALE_ENLARGE: symbol;
96
+ /**
97
+ * 缩放缩小
98
+ */
99
+ SCALE_SHRINK: symbol;
100
+ /**
101
+ * 顶部飞入
102
+ */
103
+ FLY_TOP: symbol;
104
+ /**
105
+ * 左侧飞入
106
+ */
107
+ FLY_LEFT: symbol;
108
+ /**
109
+ * 右侧飞入
110
+ */
111
+ FLY_RIGHT: symbol;
112
+ /**
113
+ * 底部飞入
114
+ */
115
+ FLY_BOTTOM: symbol;
116
+ }
117
+
118
+ declare interface PopupController extends PopupCustomController {
119
+ /**
120
+ * 渲染弹出层,返回弹出层实例id,可调用destroy(id)方法销毁弹出层
121
+ * @param {RenderOptions} options - 渲染参数
122
+ * @returns 弹出层实例id
123
+ */
124
+ render(options: RenderOptions): InstanceId;
125
+ /**
126
+ * 更新弹出层,可更新弹出层参数
127
+ * @param {InstanceId} instanceId - 弹出层实例id
128
+ * @param {UpdateOptions} options - 更新参数
129
+ */
130
+ update(instanceId: InstanceId, options: UpdateOptions): void;
131
+ /**
132
+ * 销毁弹出层
133
+ * @param {InstanceId} instanceId - 弹出层实例id
134
+ * @param {any} payload - 自定义负载参数,会作为参数传递给创建弹出层时的onUnmounted回调函数
135
+ * @returns {Promise<void>}
136
+ */
137
+ destroy(instanceId: InstanceId, payload?: any): void;
138
+ /**
139
+ * 安装插件
140
+ * @param {App} app - Vue应用实例
141
+ * @returns {void}
142
+ */
143
+ install(app: App): void;
144
+ }
145
+
146
+ declare interface PopupCustomController {
147
+ }
148
+
149
+ /**
150
+ * 实例 id 接口
151
+ */
152
+ declare interface PopupInstanceId {
153
+ /* Excluded from this release type: seed */
154
+ /**
155
+ * 实例 id 名称
156
+ */
157
+ name: Readonly<string>;
158
+ }
159
+
160
+ declare type RenderComponentOptions = {
161
+ /**
162
+ * 弹出层渲染的组件,想要创建一个弹出层,这个唯一必要的参数。它的值可以是一个同步组件,也可以是一个异步组件的 import() 函数。
163
+ * @example
164
+ * // 同步组件
165
+ * import Demo from 'path/Demo.vue'
166
+ * popup.render({
167
+ * component: Demo,
168
+ * })
169
+ *
170
+ * // 异步组件
171
+ * popup.render({
172
+ * component: () => import('path/Demo.vue'),
173
+ * })
174
+ */
175
+ component: Component;
176
+ /**
177
+ * 弹出层渲染组件的 props ,会传递给弹出层组件
178
+ */
179
+ componentProps?: Record<string, any>;
180
+ /**
181
+ * 弹出层渲染之后的回调
182
+ */
183
+ onMounted?: () => void;
184
+ /**
185
+ * 弹出层关闭之后的回调,触发时会将destroy() 方法的负载参数 payload 作为参数传入
186
+ */
187
+ onUnmounted?: <T>(payload?: T) => void;
188
+ };
189
+
190
+ declare type RenderElement = HTMLElement | string;
191
+
192
+ declare type RenderExtraOptions = {
193
+ /**
194
+ * 弹出层挂载的元素,不指定时,默认挂载到 body 元素下
195
+ */
196
+ el?: RenderElement;
197
+ /**
198
+ * 弹出层是否显示遮罩层,默认值为 true
199
+ */
200
+ mask?: boolean;
201
+ /**
202
+ * 点击遮罩层是否关闭弹出层,默认值为 false ,仅在 mask 为 true 时有效
203
+ */
204
+ maskClickCloseEnabled?: boolean;
205
+ /**
206
+ * 弹出层是否自动隐藏窗口滚动条,默认值为 true
207
+ */
208
+ autoHideWindowScroll?: boolean;
209
+ };
210
+
211
+ declare type RenderOptions = RenderComponentOptions & RenderStyleOptions & RenderExtraOptions;
212
+
213
+ declare type RenderStyleOptions = {
214
+ /**
215
+ * 弹出层宽度,默认为 auto,即自适应,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
216
+ * @example
217
+ * // px
218
+ * width: '300px',
219
+ * // rem
220
+ * width: '30rem',
221
+ * // vw
222
+ * width: '30vw',
223
+ * // 百分比
224
+ * width: '30%',
225
+ * // css 动态计算
226
+ * width: 'calc(50% + 20px)',
227
+ * // css 变量
228
+ * width: 'var(--width)',
229
+ * // number 类型,方便计算,单位为 px
230
+ * width: 300,
231
+ */
232
+ width?: string | number;
233
+ /**
234
+ * 弹出层最大宽度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
235
+ * @example
236
+ * // px
237
+ * maxWidth: '300px',
238
+ * // rem
239
+ * maxWidth: '30rem',
240
+ * // vw
241
+ * maxWidth: '30vw',
242
+ * // 百分比
243
+ * maxWidth: '30%',
244
+ * // css 动态计算
245
+ * maxWidth: 'calc(50% + 20px)',
246
+ * // css 变量
247
+ * maxWidth: 'var(--width)',
248
+ * // number 类型,方便计算,单位为 px
249
+ * maxWidth: 300,
250
+ */
251
+ maxWidth?: string | number;
252
+ /**
253
+ * 弹出层最小宽度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
254
+ * @example
255
+ * // px
256
+ * minWidth: '300px',
257
+ * // rem
258
+ * minWidth: '30rem',
259
+ * // vw
260
+ * minWidth: '30vw',
261
+ * // 百分比
262
+ * minWidth: '30%',
263
+ * // css 动态计算
264
+ * minWidth: 'calc(50% + 20px)',
265
+ * // css 变量
266
+ * minWidth: 'var(--width)',
267
+ * // number 类型,方便计算,单位为 px
268
+ * minWidth: 300,
269
+ */
270
+ minWidth?: string | number;
271
+ /**
272
+ * 弹出层高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
273
+ * @example
274
+ * // px
275
+ * height: '300px',
276
+ * // rem
277
+ * height: '30rem',
278
+ * // vh
279
+ * height: '30vh',
280
+ * // 百分比
281
+ * height: '30%',
282
+ * // css 动态计算
283
+ * height: 'calc(50% + 20px)',
284
+ * // css 变量
285
+ * height: 'var(--height)',
286
+ * // number 类型,方便计算,单位为 px
287
+ * height: 300,
288
+ */
289
+ height?: string | number;
290
+ /**
291
+ * 弹出层最大高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
292
+ * @example
293
+ * // px
294
+ * maxHeight: '300px',
295
+ * // rem
296
+ * maxHeight: '30rem',
297
+ * // vh
298
+ * maxHeight: '30vh',
299
+ * // 百分比
300
+ * maxHeight: '30%',
301
+ * // css 动态计算
302
+ * maxHeight: 'calc(50% + 20px)',
303
+ * // css 变量
304
+ * maxHeight: 'var(--height)',
305
+ * // number 类型,方便计算,单位为 px
306
+ * maxHeight: 300,
307
+ */
308
+ maxHeight?: string | number;
309
+ /**
310
+ * 弹出层最小高度,默认为 auto,支持 string 和 number 类型,string 类型更为灵活,number 类型方便计算
311
+ * @example
312
+ * // px
313
+ * minHeight: '300px',
314
+ * // rem
315
+ * minHeight: '30rem',
316
+ * // vh
317
+ * minHeight: '30vh',
318
+ * // 百分比
319
+ * minHeight: '30%',
320
+ * // css 动态计算
321
+ * minHeight: 'calc(50% + 20px)',
322
+ * // css 变量
323
+ * minHeight: 'var(--height)',
324
+ * // number 类型,方便计算,单位为 px
325
+ * minHeight: 300,
326
+ */
327
+ minHeight?: string | number;
328
+ /**
329
+ * 弹出层动画时长,默认为 100 ,单位为 毫秒
330
+ */
331
+ animationDuration?: number;
332
+ /**
333
+ * 遮罩层动画类型,默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看 {@link PopupAnimationCollection}
334
+ */
335
+ maskAnimation?: symbol;
336
+ /**
337
+ * 视图层动画类型,默认为 POPUP_ANIMATIONS.FADE ,即淡入淡出,更多动画类型请查看 {@link PopupAnimationCollection}
338
+ */
339
+ viewAnimation?: symbol;
340
+ /**
341
+ * 弹出层 zIndex ,若不设置,则使用全局递增的 zIndex 值
342
+ */
343
+ zIndex?: number;
344
+ };
345
+
346
+ declare type UpdateOptions = Partial<Omit<RenderOptions, 'component' | 'el' | 'autoHideWindowScroll'>>;
347
+
348
+ /**
349
+ * 获取弹出层控制器实例
350
+ * @returns 弹出层控制器实例
351
+ */
352
+ export declare function usePopup(): PopupController;
353
+
354
+ export { version }
355
+
356
+ export { }
357
+
358
+
359
+ declare module 'vue' {
360
+ interface ComponentCustomProperties {
361
+ $popup: PopupController;
362
+ }
363
+ }