promise-portal 1.0.1 → 1.0.3

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.
Files changed (2) hide show
  1. package/README.md +115 -2
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -24,7 +24,7 @@ yarn add promise-portal --D
24
24
  import { createPromisePortal } from 'promise-portal'
25
25
 
26
26
  const app = createApp(App)
27
- app.use(createVuePortal())
27
+ app.use(createPromisePortal())
28
28
  ```
29
29
 
30
30
  ### in component, use `usePortalContext` to get portal context
@@ -56,7 +56,120 @@ const onClick = async () => {
56
56
  }
57
57
  ```
58
58
 
59
- ## Reference
59
+ ## API Reference
60
+
61
+ - createPromisePortal
62
+
63
+ create promise-portal instance
64
+
65
+ ```ts
66
+ const instance = createPromisePortal()
67
+ app.use(instance) // vue instance
68
+ ```
69
+
70
+ - getActiveInstance
71
+
72
+ get active promise-portal instance
73
+
74
+ ```ts
75
+ const instance = getActiveInstance()
76
+ ```
77
+
78
+ - setActiveInstance
79
+
80
+ set promise-portal instance to be active
81
+
82
+ ```ts
83
+ setActiveInstance(instance)
84
+ ```
85
+
86
+ - usePortalContext
87
+
88
+ a vue composition api, use in portal component to get context of portal
89
+
90
+ ```ts
91
+ const { resolve, reject, el, vNode } = usePortalContext()
92
+ // resolve: promise resolve handler
93
+ // reject: promise reject handler
94
+ // el: portal base element, injecting to body element
95
+ // vNode: portal base vue vnode
96
+ ```
97
+
98
+ you can use typescript generic types
99
+
100
+ ```ts
101
+ const { resolve } = usePortalContext<Output>()
102
+ resolve({ ... }) // an object of type Output
103
+ ```
104
+
105
+ - definePortal
106
+
107
+ define a portal, return a portal function
108
+
109
+ ```ts
110
+ import Comp from './component.vue'
111
+ const portal = definePortal(Comp)
112
+ portal() // return a promise
113
+ ```
114
+
115
+ you can define generic types to check input object and output object
116
+
117
+ ```ts
118
+ // component.vue
119
+ export interface Input {
120
+ firstName: string
121
+ lastName: string
122
+ }
123
+
124
+ export interface Output {
125
+ fullName: string
126
+ confirm: boolean
127
+ }
128
+
129
+ const props = defineProps<Input>()
130
+ const { resolve } = usePortalContext<Output>()
131
+
132
+ // App.vue
133
+ import Comp, { Input, Output } from './component.vue'
134
+ const portal = definePortal<Output, Input>(Comp)
135
+ const output = await portal({
136
+ firstName: 'joe',
137
+ lastName: 'watson',
138
+ })
139
+ ```
140
+
141
+ how to define a portal with empty parameter
142
+
143
+ ```ts
144
+ // component.vue
145
+ export interface Output {
146
+ fullName: string
147
+ confirm: boolean
148
+ }
149
+
150
+ const { resolve } = usePortalContext<Output>()
151
+
152
+ // App.vue
153
+ import Comp, { Output } from './component.vue'
154
+ const portal = definePortal<Output, void>(Comp)
155
+ const output = await portal() // only allow empty parameter
156
+ ```
157
+
158
+ you can set a config to definePortal
159
+
160
+ ```ts
161
+ definePortal(Comp, {
162
+ // set a time gap before portal unmount,
163
+ // in general, it to wait for animation effect
164
+ unmountDelay: 1000,
165
+ // set promise-portal instance explicitly to render this portal
166
+ // not use the active instance internally
167
+ // of course, you can use `setActiveInstance` to set active instance
168
+ instance: promisePortalInstance,
169
+ })
170
+ ```
171
+
172
+ ## Link
60
173
 
61
174
  [@filez/portal](https://github.com/lenovo-filez/portal)
62
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promise-portal",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "a vite plugin to load svg icon for element-plus",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -39,6 +39,7 @@
39
39
  "license": "MIT",
40
40
  "keywords": [
41
41
  "vue",
42
+ "promise",
42
43
  "portal"
43
44
  ],
44
45
  "scripts": {