promise-portal 1.1.0 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # promise-portal
2
2
 
3
- use component like a promisd-like function
3
+ use component as a promisd-like function
4
4
 
5
5
  ## Installation
6
6
 
@@ -87,11 +87,28 @@ app.use(
87
87
  )
88
88
  ```
89
89
 
90
+ ### use `ContextProvider` to set context globally
91
+
92
+ ```vue
93
+ <!-- ./App.vue -->
94
+ <script setup lang="ts">
95
+ import locale from 'ant-design-vue/es/locale/zh_CN'
96
+ import { ContextProvider } from 'promise-portal'
97
+ </script>
98
+ <template>
99
+ <a-config-provider :locale="locale">
100
+ <ContextProvider>
101
+ <router-view></router-view>
102
+ </ContextProvider>
103
+ </a-config-provider>
104
+ </template>
105
+ ```
106
+
90
107
  ### in component, use `usePortalContext` to use portal context
91
108
 
92
109
  ```vue
110
+ <!-- ./components/comp.vue -->
93
111
  <script setup lang="ts">
94
- // ./components/comp.vue
95
112
  import { usePortalContext } from 'promise-portal'
96
113
  export interface Output {
97
114
  confirm: boolean
@@ -165,6 +182,24 @@ set active promise-portal instance
165
182
  setActiveInstance(instance)
166
183
  ```
167
184
 
185
+ ### ContextProvider
186
+
187
+ a component to set context globally
188
+
189
+ ```vue
190
+ <script setup lang="ts">
191
+ import locale from 'ant-design-vue/es/locale/zh_CN'
192
+ import { ContextProvider } from 'promise-portal'
193
+ </script>
194
+ <template>
195
+ <a-config-provider :locale="locale">
196
+ <ContextProvider>
197
+ <router-view></router-view>
198
+ </ContextProvider>
199
+ </a-config-provider>
200
+ </template>
201
+ ```
202
+
168
203
  ### usePortalContext
169
204
 
170
205
  a vue composition api, use in portal component to get context of portal
package/dist/index.cjs CHANGED
@@ -20,18 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ ContextProvider: () => ContextProvider,
23
24
  createPromisePortal: () => createPromisePortal,
24
25
  definePortal: () => definePortal,
25
26
  detectPromisePortalInstance: () => detectPromisePortalInstance,
26
27
  getActiveInstance: () => getActiveInstance,
27
28
  setActiveInstance: () => setActiveInstance,
28
- usePortalContext: () => usePortalContext
29
+ usePortalContext: () => usePortalContext,
30
+ version: () => version
29
31
  });
30
32
  module.exports = __toCommonJS(src_exports);
31
33
 
32
34
  // src/portal.ts
33
35
  var import_vue = require("vue");
34
36
  var promisePortalSymbol = process.env.NODE_ENV !== "production" ? Symbol("promise-portal") : Symbol();
37
+ var version = `1.2.1`;
35
38
  var activeInstance;
36
39
  var getActiveInstance = () => activeInstance;
37
40
  var setActiveInstance = (instance) => activeInstance = instance;
@@ -40,6 +43,7 @@ var createPromisePortal = (defaultOptions = {}) => {
40
43
  defaultOptions,
41
44
  app: void 0,
42
45
  map: /* @__PURE__ */ new WeakMap(),
46
+ provides: void 0,
43
47
  install(app) {
44
48
  instance.app = app;
45
49
  setActiveInstance(instance);
@@ -96,7 +100,7 @@ var definePortal = (component, options = {}) => {
96
100
  const ac = appContext ?? instance.app._context;
97
101
  vnode.appContext = Object.create(ac, {
98
102
  provides: {
99
- value: contextHolderProvides ?? ac.provides
103
+ value: contextHolderProvides ?? instance.provides ?? ac.provides
100
104
  }
101
105
  });
102
106
  (0, import_vue.render)(vnode, el);
@@ -112,6 +116,17 @@ var definePortal = (component, options = {}) => {
112
116
  };
113
117
  return [portal, ContextHolder];
114
118
  };
119
+ var ContextProvider = (0, import_vue.defineComponent)({
120
+ name: "PromisePortalContextProvider",
121
+ setup(_props, { slots }) {
122
+ const p = (0, import_vue.getCurrentInstance)()?.provides;
123
+ const instance = getActiveInstance();
124
+ if (p && instance) {
125
+ instance.provides = p;
126
+ }
127
+ return () => slots.default?.();
128
+ }
129
+ });
115
130
 
116
131
  // src/detector.ts
117
132
  function detect(options) {
@@ -139,10 +154,12 @@ var detectPromisePortalInstance = (options = {}) => {
139
154
  };
140
155
  // Annotate the CommonJS export names for ESM import in node:
141
156
  0 && (module.exports = {
157
+ ContextProvider,
142
158
  createPromisePortal,
143
159
  definePortal,
144
160
  detectPromisePortalInstance,
145
161
  getActiveInstance,
146
162
  setActiveInstance,
147
- usePortalContext
163
+ usePortalContext,
164
+ version
148
165
  });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { VNode, Ref, App, Component } from 'vue';
3
3
 
4
+ declare const version = "1.2.1";
4
5
  interface Options {
5
6
  unmountDelay?: number;
6
7
  initialShowValue?: boolean;
@@ -17,6 +18,7 @@ interface Instance<R = any> {
17
18
  defaultOptions: Options;
18
19
  app: App;
19
20
  map: WeakMap<VNode, Context<R>>;
21
+ provides: any;
20
22
  install: (app: App) => void;
21
23
  }
22
24
  declare const getActiveInstance: () => Instance<any>;
@@ -26,6 +28,9 @@ declare const usePortalContext: <TOutput = any>(options?: Options) => Context<TO
26
28
  declare const definePortal: <TOutput = any, TProps = any>(component: Component, options?: Options & {
27
29
  instance?: Instance<TOutput> | undefined;
28
30
  }) => [(props?: TProps | undefined, children?: unknown) => Promise<TOutput>, Component<any, any, any, vue.ComputedOptions, vue.MethodOptions>];
31
+ declare const ContextProvider: vue.DefineComponent<{}, () => VNode<vue.RendererNode, vue.RendererElement, {
32
+ [key: string]: any;
33
+ }>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}, {}>;
29
34
 
30
35
  interface DetectorOptions {
31
36
  style?: string;
@@ -33,4 +38,4 @@ interface DetectorOptions {
33
38
  }
34
39
  declare const detectPromisePortalInstance: (options?: DetectorOptions) => () => void;
35
40
 
36
- export { Context, DetectorOptions, Instance, Options, createPromisePortal, definePortal, detectPromisePortalInstance, getActiveInstance, setActiveInstance, usePortalContext };
41
+ export { Context, ContextProvider, DetectorOptions, Instance, Options, createPromisePortal, definePortal, detectPromisePortalInstance, getActiveInstance, setActiveInstance, usePortalContext, version };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/portal.ts
2
2
  import { createVNode, render, inject, getCurrentInstance, defineComponent, ref } from "vue";
3
3
  var promisePortalSymbol = process.env.NODE_ENV !== "production" ? Symbol("promise-portal") : Symbol();
4
+ var version = `1.2.1`;
4
5
  var activeInstance;
5
6
  var getActiveInstance = () => activeInstance;
6
7
  var setActiveInstance = (instance) => activeInstance = instance;
@@ -9,6 +10,7 @@ var createPromisePortal = (defaultOptions = {}) => {
9
10
  defaultOptions,
10
11
  app: void 0,
11
12
  map: /* @__PURE__ */ new WeakMap(),
13
+ provides: void 0,
12
14
  install(app) {
13
15
  instance.app = app;
14
16
  setActiveInstance(instance);
@@ -65,7 +67,7 @@ var definePortal = (component, options = {}) => {
65
67
  const ac = appContext ?? instance.app._context;
66
68
  vnode.appContext = Object.create(ac, {
67
69
  provides: {
68
- value: contextHolderProvides ?? ac.provides
70
+ value: contextHolderProvides ?? instance.provides ?? ac.provides
69
71
  }
70
72
  });
71
73
  render(vnode, el);
@@ -81,6 +83,17 @@ var definePortal = (component, options = {}) => {
81
83
  };
82
84
  return [portal, ContextHolder];
83
85
  };
86
+ var ContextProvider = defineComponent({
87
+ name: "PromisePortalContextProvider",
88
+ setup(_props, { slots }) {
89
+ const p = getCurrentInstance()?.provides;
90
+ const instance = getActiveInstance();
91
+ if (p && instance) {
92
+ instance.provides = p;
93
+ }
94
+ return () => slots.default?.();
95
+ }
96
+ });
84
97
 
85
98
  // src/detector.ts
86
99
  function detect(options) {
@@ -107,10 +120,12 @@ var detectPromisePortalInstance = (options = {}) => {
107
120
  return () => clearInterval(timer);
108
121
  };
109
122
  export {
123
+ ContextProvider,
110
124
  createPromisePortal,
111
125
  definePortal,
112
126
  detectPromisePortalInstance,
113
127
  getActiveInstance,
114
128
  setActiveInstance,
115
- usePortalContext
129
+ usePortalContext,
130
+ version
116
131
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "promise-portal",
3
- "version": "1.1.0",
4
- "description": "let you use react portal in vue, and with promise",
3
+ "version": "1.2.1",
4
+ "description": "use component as a promisd-like function",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",