promise-portal 2.0.0 → 2.0.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/LICENSE +21 -0
- package/README.md +2 -1
- package/dist/index.cjs +7 -4
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +8 -4
- package/package.json +9 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License Copyright (c) 2022 yuanpeng
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of
|
|
4
|
+
charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -293,7 +293,8 @@ definePortal(Comp, {
|
|
|
293
293
|
// Initial value for the show ref (defaults to true)
|
|
294
294
|
initialShowValue: true,
|
|
295
295
|
|
|
296
|
-
// a dom element or CSS selector
|
|
296
|
+
// a dom element or CSS selector or Ref value or a function returing a dom element,
|
|
297
|
+
// append the portal element to (defaults to document.body)
|
|
297
298
|
appendTo: document.body,
|
|
298
299
|
})
|
|
299
300
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,6 @@ const detectPromisePortalInstance = (options = {}) => {
|
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/portal.ts
|
|
27
27
|
const promisePortalSymbol = Symbol("promise-portal");
|
|
28
|
-
const version = `2.0.0`;
|
|
29
28
|
let activeInstance;
|
|
30
29
|
const createPromisePortal = () => {
|
|
31
30
|
const instance = {
|
|
@@ -51,7 +50,12 @@ const usePortalContext = (options = {}) => {
|
|
|
51
50
|
if (options.initialShowValue !== void 0) scope.show.value = options.initialShowValue;
|
|
52
51
|
return scope;
|
|
53
52
|
};
|
|
54
|
-
const resolveTarget = (to) =>
|
|
53
|
+
const resolveTarget = (to) => {
|
|
54
|
+
if (typeof to === "string") return document.querySelector(to);
|
|
55
|
+
else if ((0, vue.isRef)(to)) return (0, vue.unref)(to);
|
|
56
|
+
else if (typeof to === "function") return to();
|
|
57
|
+
return to;
|
|
58
|
+
};
|
|
55
59
|
const definePortal = (component, options = {}) => {
|
|
56
60
|
const instance = ((0, vue.getCurrentInstance)() && (0, vue.inject)(promisePortalSymbol)) ?? activeInstance;
|
|
57
61
|
if (!instance) throw new Error("[promise-portal]: no instance found. Did you forget to install promise-portal?");
|
|
@@ -110,5 +114,4 @@ exports.ContextProvider = ContextProvider;
|
|
|
110
114
|
exports.createPromisePortal = createPromisePortal;
|
|
111
115
|
exports.definePortal = definePortal;
|
|
112
116
|
exports.detectPromisePortalInstance = detectPromisePortalInstance;
|
|
113
|
-
exports.usePortalContext = usePortalContext;
|
|
114
|
-
exports.version = version;
|
|
117
|
+
exports.usePortalContext = usePortalContext;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
|
-
import { App, Component, Ref,
|
|
2
|
+
import { App, Component, Ref, VNode } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/detector.d.ts
|
|
5
5
|
interface DetectorOptions {
|
|
@@ -9,13 +9,12 @@ interface DetectorOptions {
|
|
|
9
9
|
declare const detectPromisePortalInstance: (options?: DetectorOptions) => () => void;
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/portal.d.ts
|
|
12
|
-
declare const version = "2.0.0";
|
|
13
12
|
interface UsePortalContextOptions {
|
|
14
13
|
unmountDelay?: number;
|
|
15
14
|
initialShowValue?: boolean;
|
|
16
15
|
}
|
|
17
16
|
interface DefinePortalOptions extends UsePortalContextOptions {
|
|
18
|
-
appendTo?: string |
|
|
17
|
+
appendTo?: string | HTMLElement | Ref<HTMLElement> | (() => HTMLElement);
|
|
19
18
|
}
|
|
20
19
|
type DefinePortalResult<Output, Input> = [(props?: Input, children?: unknown) => Promise<Output>, Component];
|
|
21
20
|
interface Scope<R> {
|
|
@@ -35,8 +34,8 @@ interface Instance<R = any> {
|
|
|
35
34
|
declare const createPromisePortal: () => Instance<any>;
|
|
36
35
|
declare const usePortalContext: <Output = any>(options?: UsePortalContextOptions) => Scope<Output>;
|
|
37
36
|
declare const definePortal: <Output = any, Input = any>(component: Component, options?: DefinePortalOptions) => DefinePortalResult<Output, Input>;
|
|
38
|
-
declare const ContextProvider: vue0.DefineComponent<{}, () => VNode<vue0.RendererNode, RendererElement, {
|
|
37
|
+
declare const ContextProvider: vue0.DefineComponent<{}, () => VNode<vue0.RendererNode, vue0.RendererElement, {
|
|
39
38
|
[key: string]: any;
|
|
40
39
|
}>[] | undefined, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
|
|
41
40
|
//#endregion
|
|
42
|
-
export { ContextProvider, DefinePortalOptions, DefinePortalResult, DetectorOptions, Instance, Scope, UsePortalContextOptions, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext
|
|
41
|
+
export { ContextProvider, DefinePortalOptions, DefinePortalResult, DetectorOptions, Instance, Scope, UsePortalContextOptions, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
|
-
import { App, Component, Ref,
|
|
2
|
+
import { App, Component, Ref, VNode } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/detector.d.ts
|
|
5
5
|
interface DetectorOptions {
|
|
@@ -9,13 +9,12 @@ interface DetectorOptions {
|
|
|
9
9
|
declare const detectPromisePortalInstance: (options?: DetectorOptions) => () => void;
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/portal.d.ts
|
|
12
|
-
declare const version = "2.0.0";
|
|
13
12
|
interface UsePortalContextOptions {
|
|
14
13
|
unmountDelay?: number;
|
|
15
14
|
initialShowValue?: boolean;
|
|
16
15
|
}
|
|
17
16
|
interface DefinePortalOptions extends UsePortalContextOptions {
|
|
18
|
-
appendTo?: string |
|
|
17
|
+
appendTo?: string | HTMLElement | Ref<HTMLElement> | (() => HTMLElement);
|
|
19
18
|
}
|
|
20
19
|
type DefinePortalResult<Output, Input> = [(props?: Input, children?: unknown) => Promise<Output>, Component];
|
|
21
20
|
interface Scope<R> {
|
|
@@ -35,8 +34,8 @@ interface Instance<R = any> {
|
|
|
35
34
|
declare const createPromisePortal: () => Instance<any>;
|
|
36
35
|
declare const usePortalContext: <Output = any>(options?: UsePortalContextOptions) => Scope<Output>;
|
|
37
36
|
declare const definePortal: <Output = any, Input = any>(component: Component, options?: DefinePortalOptions) => DefinePortalResult<Output, Input>;
|
|
38
|
-
declare const ContextProvider: vue0.DefineComponent<{}, () => VNode<vue0.RendererNode, RendererElement, {
|
|
37
|
+
declare const ContextProvider: vue0.DefineComponent<{}, () => VNode<vue0.RendererNode, vue0.RendererElement, {
|
|
39
38
|
[key: string]: any;
|
|
40
39
|
}>[] | undefined, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
|
|
41
40
|
//#endregion
|
|
42
|
-
export { ContextProvider, DefinePortalOptions, DefinePortalResult, DetectorOptions, Instance, Scope, UsePortalContextOptions, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext
|
|
41
|
+
export { ContextProvider, DefinePortalOptions, DefinePortalResult, DetectorOptions, Instance, Scope, UsePortalContextOptions, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createVNode, defineComponent, getCurrentInstance, inject, ref, render } from "vue";
|
|
1
|
+
import { createVNode, defineComponent, getCurrentInstance, inject, isRef, ref, render, unref } from "vue";
|
|
2
2
|
|
|
3
3
|
//#region src/detector.ts
|
|
4
4
|
function detect(options) {
|
|
@@ -25,7 +25,6 @@ const detectPromisePortalInstance = (options = {}) => {
|
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/portal.ts
|
|
27
27
|
const promisePortalSymbol = Symbol("promise-portal");
|
|
28
|
-
const version = `2.0.0`;
|
|
29
28
|
let activeInstance;
|
|
30
29
|
const createPromisePortal = () => {
|
|
31
30
|
const instance = {
|
|
@@ -51,7 +50,12 @@ const usePortalContext = (options = {}) => {
|
|
|
51
50
|
if (options.initialShowValue !== void 0) scope.show.value = options.initialShowValue;
|
|
52
51
|
return scope;
|
|
53
52
|
};
|
|
54
|
-
const resolveTarget = (to) =>
|
|
53
|
+
const resolveTarget = (to) => {
|
|
54
|
+
if (typeof to === "string") return document.querySelector(to);
|
|
55
|
+
else if (isRef(to)) return unref(to);
|
|
56
|
+
else if (typeof to === "function") return to();
|
|
57
|
+
return to;
|
|
58
|
+
};
|
|
55
59
|
const definePortal = (component, options = {}) => {
|
|
56
60
|
const instance = (getCurrentInstance() && inject(promisePortalSymbol)) ?? activeInstance;
|
|
57
61
|
if (!instance) throw new Error("[promise-portal]: no instance found. Did you forget to install promise-portal?");
|
|
@@ -106,4 +110,4 @@ const ContextProvider = defineComponent({
|
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
//#endregion
|
|
109
|
-
export { ContextProvider, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext
|
|
113
|
+
export { ContextProvider, createPromisePortal, definePortal, detectPromisePortalInstance, usePortalContext };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "promise-portal",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "use component as a promisd-like function",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "tjyuanpeng",
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"files": [
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"vue": "3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"tsdown": "0.20.1",
|
|
43
|
+
"typescript": "~5.9.3"
|
|
44
|
+
},
|
|
38
45
|
"scripts": {
|
|
39
46
|
"dev": "tsdown --watch",
|
|
40
47
|
"build": "tsdown",
|
|
41
48
|
"typecheck": "tsc --noEmit",
|
|
42
49
|
"lint": "eslint ."
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"vue": "3"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"tsdown": "catalog:",
|
|
49
|
-
"typescript": "catalog:"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|