vue-mount-plugin 3.0.0 → 4.0.0-beta.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.
package/dist/index.d.ts CHANGED
@@ -1,42 +1,287 @@
1
1
  import type { App } from 'vue-demi';
2
- import { createVNode } from 'vue-demi';
2
+ import type { AppContext } from 'vue-demi';
3
+ import { ComponentPublicInstance } from 'vue-demi';
4
+ import { Plugin as Plugin_2 } from 'vue-demi';
5
+ import { Ref } from 'vue-demi';
3
6
  import type { VNode } from 'vue-demi';
4
7
  import type { VNodeProps } from 'vue-demi';
5
- import { Vue2 } from 'vue-demi';
6
8
 
7
- export declare type Component = CreateVNodeParameters['0'];
9
+ export declare function addClass(element: Element, className: string): void;
8
10
 
9
- export declare type CreateVNodeParameters = Parameters<typeof createVNode>;
11
+ export { App }
12
+
13
+ export { AppContext }
14
+
15
+ export declare function appendTo(element: Element, target: Element | ShadowRoot | string | null): void;
16
+
17
+ export declare function capitalize(str: string): string;
18
+
19
+ export declare function clearSingletons(): void;
20
+
21
+ export declare type Component = any;
22
+
23
+ export { ComponentPublicInstance }
24
+
25
+ export declare interface ContextOptions {
26
+ router?: unknown;
27
+ store?: unknown;
28
+ i18n?: unknown;
29
+ [key: string]: unknown;
30
+ }
31
+
32
+ export declare function createElement(tagName?: string, attributes?: Record<string, string>): HTMLElement;
33
+
34
+ export declare function createInstanceId(): string;
35
+
36
+ export declare function createMount<T = any>(component: Component, options?: MountOptions): MountInstance<T>;
10
37
 
11
38
  export declare type Data = Record<string, unknown>;
12
39
 
13
- declare class Mount {
14
- vNode: VNode | typeof Vue2 | null;
15
- target: Element | ShadowRoot;
16
- options: Options;
17
- seed: number;
18
- constructor(component: Component, options?: Options);
19
- createVM(component: Component, { props, children, patchFlag, dynamicProps, isBlockNode, app, context, parent }?: Options): any;
20
- mount(): void;
40
+ export declare class EventEmitter {
41
+ private events;
42
+ on(event: string, handler: Listener): this;
43
+ off(event: string, handler?: Listener): this;
44
+ emit(event: string, ...args: any[]): this;
45
+ has(event: string): boolean;
46
+ clear(): void;
47
+ eventNames(): string[];
48
+ }
49
+
50
+ export declare function eventToPropName(event: string): string;
51
+
52
+ export declare function getActiveInstanceIds(): string[];
53
+
54
+ export declare function getCurrentComponentContext(componentInstance: any): ContextOptions;
55
+
56
+ export declare function getGlobalConfig(): GlobalConfig;
57
+
58
+ export declare function getInstanceById(id: string): MountBase | undefined;
59
+
60
+ export declare function getInstances(): MountBase[];
61
+
62
+ export declare function getSingleton(key: string | symbol): MountInstance | undefined;
63
+
64
+ export declare function getSingletonKey(component: any, singleton?: boolean | string): string | symbol | undefined;
65
+
66
+ export declare function getSingletonKeys(): (string | symbol)[];
67
+
68
+ export declare interface GlobalConfig extends Partial<MountOptions> {
69
+ zIndex?: number;
70
+ container?: string | Element | null;
71
+ transition?: string | TransitionOptions;
72
+ context?: ContextOptions;
73
+ installed?: boolean;
74
+ }
75
+
76
+ export declare const globalConfig: GlobalConfig;
77
+
78
+ export declare function hasSingleton(key: string | symbol): boolean;
79
+
80
+ export declare function inheritVue2Context(parent: any, options: MountOptions): ContextOptions;
81
+
82
+ export declare function inheritVue3Context(app: App | undefined, _options?: MountOptions): {
83
+ appContext?: App['_context'];
84
+ provides?: Record<string, unknown>;
85
+ };
86
+
87
+ export declare function isBrowser(): boolean;
88
+
89
+ export declare function isInDOM(element: Element): boolean;
90
+
91
+ export declare function isMounted(id: string): boolean;
92
+
93
+ export declare function isNodeEnv(): boolean;
94
+
95
+ export declare interface KeepAliveOptions {
96
+ enabled?: boolean;
97
+ include?: string | RegExp | string[];
98
+ exclude?: string | RegExp | string[];
99
+ max?: number;
100
+ }
101
+
102
+ export declare interface LifecycleHooks {
103
+ onBeforeMount?: (instance: MountInstance) => void;
104
+ onMounted?: (instance: MountInstance) => void;
105
+ onBeforeUnmount?: (instance: MountInstance) => void;
106
+ onUnmounted?: (instance: MountInstance) => void;
107
+ }
108
+
109
+ export declare type Listener = (...args: any[]) => void;
110
+
111
+ export declare type Listeners = Record<string, Listener | Listener[]>;
112
+
113
+ export declare function mergeWithGlobalConfig<T extends Record<string, any>>(options: T): T;
114
+
115
+ export declare function mount<T = any>(component: Component, options?: MountOptions): MountInstance<T>;
116
+
117
+ export declare abstract class MountBase implements MountInstance {
118
+ readonly id: string;
119
+ options: MountOptions;
120
+ mounted: boolean;
121
+ el: HTMLElement | null;
122
+ abstract vm: ComponentPublicInstance | null;
123
+ protected _eventEmitter: EventEmitter;
124
+ protected _promise: Promise<any>;
125
+ protected _resolve: (value: any) => void;
126
+ protected _reject: (error: any) => void;
127
+ protected _component: any;
128
+ protected _autoCreatedTarget: boolean;
129
+ protected _hidden: boolean;
130
+ protected _destroyed: boolean;
131
+ protected _singletonKey: string | symbol | undefined;
132
+ constructor(component: any, options?: MountOptions);
133
+ protected abstract _createVM(): void;
134
+ protected abstract _mountVM(): void;
135
+ protected abstract _unmountVM(): void;
136
+ protected abstract _updateVM(): void;
137
+ show(): this;
138
+ hide(): this;
21
139
  unmount(): void;
140
+ destroy: () => void;
141
+ remove: () => void;
142
+ setProps(props: Record<string, any>): this;
143
+ on(event: string, handler: Listener): this;
144
+ off(event: string, handler?: Listener): this;
145
+ emit(event: string, ...args: any[]): this;
146
+ then<TResult = void>(resolve: (value: any) => TResult): Promise<TResult>;
147
+ catch<TResult = never>(reject: (error: any) => TResult): Promise<any>;
148
+ finally(onFinally: () => void): Promise<any>;
149
+ setTarget(target: string | Element | ShadowRoot): this;
150
+ setHooks(hooks: LifecycleHooks): this;
151
+ setSlots(slots: Slots): this;
152
+ protected _ensureElement(): void;
153
+ protected _appendElementToDOM(): void;
154
+ protected _resolvePromise(value?: any): void;
155
+ protected _rejectPromise(error?: any): void;
156
+ protected _mergeListenersToProps(listeners: Record<string, Listener>): Record<string, any>;
157
+ static get instances(): MountBase[];
158
+ static unmountAll(): void;
159
+ static getById(id: string): MountBase | undefined;
22
160
  }
23
- export default Mount;
24
161
 
25
- export declare interface Options {
162
+ export declare interface MountInstance<T = ComponentPublicInstance> {
163
+ vm: T | null;
164
+ el: HTMLElement | null;
165
+ mounted: boolean;
166
+ id: string;
167
+ options: MountOptions;
168
+ setProps: (props: Partial<Data>) => MountInstance<T>;
169
+ show: () => MountInstance<T>;
170
+ hide: () => MountInstance<T>;
171
+ unmount: () => void;
172
+ on: (event: string, handler: Listener) => MountInstance<T>;
173
+ off: (event: string, handler?: Listener) => MountInstance<T>;
174
+ emit: (event: string, ...args: any[]) => MountInstance<T>;
175
+ then: <TResult = void>(resolve: (value: any) => TResult) => Promise<TResult>;
176
+ setTarget: (target: string | Element | ShadowRoot) => MountInstance<T>;
177
+ setHooks: (hooks: LifecycleHooks) => MountInstance<T>;
178
+ setSlots: (slots: Slots) => MountInstance<T>;
179
+ }
180
+
181
+ export declare interface MountOptions<TContext = ContextOptions> extends LifecycleHooks {
182
+ target?: string | Element | ShadowRoot | null;
183
+ tagName?: string;
184
+ replace?: boolean;
26
185
  props?: (Data & VNodeProps) | null;
27
186
  children?: unknown;
28
187
  patchFlag?: number;
29
188
  dynamicProps?: string[] | null;
30
189
  isBlockNode?: boolean;
31
- target?: Element | ShadowRoot;
32
- tagName?: keyof HTMLElementTagNameMap;
190
+ listeners?: Listeners;
191
+ on?: Listeners;
192
+ slots?: Slots;
33
193
  app?: App;
34
- context?: Data & {
35
- router: unknown;
36
- store: unknown;
37
- i18n: unknown;
38
- };
194
+ context?: TContext;
39
195
  parent?: unknown;
196
+ ref?: Ref<ComponentPublicInstance | null>;
197
+ zIndex?: number;
198
+ singleton?: boolean | string;
199
+ transition?: string | TransitionOptions;
200
+ delay?: number;
201
+ keepAlive?: KeepAliveOptions | boolean;
202
+ }
203
+
204
+ export declare const MountPlugin: Plugin_2;
205
+
206
+ export declare interface MountPluginOptions extends GlobalConfig {
207
+ name?: string;
208
+ }
209
+
210
+ export declare class MountVue2 extends MountBase {
211
+ vm: ComponentPublicInstance | null;
212
+ private _vue2Instance;
213
+ constructor(component: any, options?: MountOptions);
214
+ protected _createVM(): void;
215
+ protected _mountVM(): void;
216
+ protected _unmountVM(): void;
217
+ protected _updateVM(): void;
218
+ }
219
+
220
+ export declare class MountVue3 extends MountBase {
221
+ vm: ComponentPublicInstance | null;
222
+ private _vNode;
223
+ constructor(component: any, options?: MountOptions);
224
+ protected _createVM(): void;
225
+ protected _mountVM(): void;
226
+ protected _unmountVM(): void;
227
+ protected _updateVM(): void;
40
228
  }
41
229
 
230
+ export { Ref }
231
+
232
+ export declare function removeClass(element: Element, className: string): void;
233
+
234
+ export declare function removeElement(element: Element): void;
235
+
236
+ export declare function removeSingleton(key: string | symbol): void;
237
+
238
+ export declare function resetGlobalConfig(): void;
239
+
240
+ export declare function resolveTarget(target: string | Element | ShadowRoot | null | undefined): Element | ShadowRoot | null;
241
+
242
+ export declare function setGlobalConfig(config: Partial<GlobalConfig>): void;
243
+
244
+ export declare function setSingleton(key: string | symbol, instance: MountInstance): void;
245
+
246
+ export declare function setZIndex(element: HTMLElement, zIndex: number | undefined): void;
247
+
248
+ export declare interface Slots {
249
+ default?: VNode | VNode[];
250
+ [key: string]: VNode | VNode[] | undefined;
251
+ }
252
+
253
+ export declare interface TransitionOptions {
254
+ name?: string;
255
+ appear?: boolean;
256
+ css?: boolean;
257
+ enterClass?: string;
258
+ leaveClass?: string;
259
+ enterActiveClass?: string;
260
+ leaveActiveClass?: string;
261
+ enterToClass?: string;
262
+ leaveToClass?: string;
263
+ }
264
+
265
+ export declare function unmountAll(): void;
266
+
267
+ export declare function useMount(): UseMountReturn;
268
+
269
+ export declare interface UseMountReturn {
270
+ instances: Ref<MountInstance[]>;
271
+ mount: <T = any>(component: any, options?: MountOptions) => MountInstance<T>;
272
+ unmount: (instance: MountInstance) => void;
273
+ unmountAll: () => void;
274
+ getById: (id: string) => MountInstance | undefined;
275
+ hasInstances: () => boolean;
276
+ count: () => number;
277
+ }
278
+
279
+ export declare function useSingleton(): UseSingletonReturn;
280
+
281
+ export declare interface UseSingletonReturn {
282
+ getOrCreate: <T = any>(key: string, component: any, options?: MountOptions) => MountInstance<T>;
283
+ }
284
+
285
+ export { VNode }
286
+
42
287
  export { }