From 6548935749cc530a6209b5149f3b6e37cf6cce6d Mon Sep 17 00:00:00 2001 From: panda <919401990@qq.com> Date: Thu, 17 Oct 2024 09:59:43 +0700 Subject: [PATCH] fix: bug --- README.md | 18 +- README_EN.md | 8 +- dist/index.js | 373 +++++++++--------- dist/index.umd.cjs | 6 +- dist/src/components/Core.d.ts | 5 +- package.json | 12 +- src/components/Core.tsx | 11 +- src/components/ElementPlusDialog.tsx | 14 +- src/components/VantUiPopup.tsx | 4 +- src/main.ts | 2 +- src/pages/example/advance/communication.vue | 4 +- src/pages/example/advance/promise.vue | 4 +- src/pages/example/base/components/Content.vue | 4 +- src/pages/example/base/confirm.vue | 4 +- 14 files changed, 248 insertions(+), 221 deletions(-) diff --git a/README.md b/README.md index f1170cb..82fb9cd 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,23 @@ const app = createApp(App); app.mount("#app"); ``` +如果你对打包体积等没有要求,更简单粗暴的方法是直接全量导入组件库的 CSS: + +```ts +// 导入vant全量样式 +import "vant/lib/index.css"; + +// 导入element-plus全量样式 +import "element-plus/dist/index.css"; +``` + ## 你如何适配自己 UI 库组件 除了已经适配的 Element Plus 的 Dialog 组件以及 vant 的 Popup 组件, 您也可以自行适配您自己的 UI 库组件, 具体可以参考以下步骤: 具体可以借鉴示例代码中对 element-plus 以及 vantui 的实现,这里只说一下核心逻辑; -1.我们需要 CommandDialogProvider 函数来对我们的目标组件进行包装, 它的最主要的作用是对被包裹的组件注入`Consumer`对象,那么我们的弹窗内部组件就可以接收到这个对象,它是我们对弹窗进行控制的主要手段.这个对象上有下列属性和方法: +1.我们需要 CommandProvider 函数来对我们的目标组件进行包装, 它的最主要的作用是对被包裹的组件注入`Consumer`对象,那么我们的弹窗内部组件就可以接收到这个对象,它是我们对弹窗进行控制的主要手段.这个对象上有下列属性和方法: ```ts /** 弹窗消费者对象,或者也可理解为弹窗实例实例~ */ @@ -103,11 +113,11 @@ export interface IConsumer { 你不用关心这个对象的创建销毁等逻辑,只需要知道有这么一个对象,以及它身上有哪些属性和方法即可.你还可以注意到,这个对象上还有`on` `once` `emit` `off`等方法,通过这些 api 注册的事件函数都会严格限制在 `consumer` 对象下,所以不同的`consumer`对象的事件注册发布均不互相影响;同时你也不用关心事件的解绑等逻辑,这些内部已经帮你处理好了. -CommandDialogProvider 同时也会返回一个`consumer`对象,以供弹窗外部使用,弹窗内部和外部拿到的 consumer 是同一个对象,所以他们是全等(===)的. +CommandProvider 同时也会返回一个`consumer`对象,以供弹窗外部使用,弹窗内部和外部拿到的 consumer 是同一个对象,所以他们是全等(===)的. -弹窗内部组件获取 `consumer` 对象的方式为调用`getCommandDialogConsumer`, 该函数会返回一个 consumer 对象,它一样只能在 setup 顶部直接调用,不可条件调用或者异步调用. +弹窗内部组件获取 `consumer` 对象的方式为调用`getConsumer`, 该函数会返回一个 consumer 对象,它一样只能在 setup 顶部直接调用,不可条件调用或者异步调用. -2.剩余的就是`CommandDialogProvider`函数参数的介绍了, +2.剩余的就是`CommandProvider`函数参数的介绍了, ```ts parentInstance: ComponentInternalInstance | null, diff --git a/README_EN.md b/README_EN.md index 380922f..5778c48 100644 --- a/README_EN.md +++ b/README_EN.md @@ -59,7 +59,7 @@ In addition to the already adapted Element Plus Dialog component and Vant Popup You can refer to the implementation for element-plus and vantui in the example code. Here, we'll just discuss the core logic: -1. We need the CommandDialogProvider function to wrap our target component. Its main purpose is to inject the `Consumer` object into the wrapped component, so our internal dialog component can receive this object, which is our main means of controlling the dialog. This object has the following properties and methods: +1. We need the CommandProvider function to wrap our target component. Its main purpose is to inject the `Consumer` object into the wrapped component, so our internal dialog component can receive this object, which is our main means of controlling the dialog. This object has the following properties and methods: ```ts /** Dialog consumer object, or can be understood as the dialog instance~ */ @@ -103,11 +103,11 @@ export interface IConsumer { You don't need to worry about the creation and destruction of this object, you just need to know that there is such an object and what properties and methods it has. You may also notice that this object has methods like `on`, `once`, `emit`, `off`, etc. The event functions registered through these APIs are strictly limited to the `consumer` object, so the event registration and publishing of different `consumer` objects do not affect each other. At the same time, you don't need to worry about event unbinding and other logic, these have been handled internally for you. -CommandDialogProvider also returns a `consumer` object for external use of the dialog. The consumer objects obtained internally and externally of the dialog are the same object, so they are strictly equal (===). +CommandProvider also returns a `consumer` object for external use of the dialog. The consumer objects obtained internally and externally of the dialog are the same object, so they are strictly equal (===). -The internal dialog component obtains the `consumer` object by calling `getCommandDialogConsumer`. This function will return a consumer object, and it can only be called directly at the top of setup, not conditionally or asynchronously. +The internal dialog component obtains the `consumer` object by calling `getConsumer`. This function will return a consumer object, and it can only be called directly at the top of setup, not conditionally or asynchronously. -2. The rest is the introduction of parameter passing for the `CommandDialogProvider` function: +2. The rest is the introduction of parameter passing for the `CommandProvider` function: ```ts parentInstance: ComponentInternalInstance | null, diff --git a/dist/index.js b/dist/index.js index c93cae8..68c7ab5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,8 +1,8 @@ var He = Object.defineProperty; var Ke = (e, t, r) => t in e ? He(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; var Q = (e, t, r) => Ke(e, typeof t != "symbol" ? t + "" : t, r); -import { createVNode as C, render as k, inject as ve, defineComponent as q, provide as U, nextTick as Le, getCurrentInstance as me, ref as E, h as ge, mergeProps as ye, resolveComponent as ee } from "vue"; -import { useGlobalComponentSettings as We, ElDialog as Ve } from "element-plus"; +import { createVNode as C, render as k, inject as ve, defineComponent as q, provide as U, nextTick as Le, getCurrentInstance as me, ref as E, h as ge, mergeProps as ye } from "vue"; +import { useGlobalComponentSettings as We, ElDialog as Ve, ElButton as ee } from "element-plus"; import { Popup as qe } from "vant"; class Ze { constructor() { @@ -117,17 +117,17 @@ function Ce(e, t, r) { ..._e(e) }, k(P, o), d; } -const Dn = (e = !0) => { +const Qe = (e = !0) => { const t = () => e && console.warn(`别调用了欧尼酱~,这会儿没啥实际用途;没有根据CommandDialogInjectKey接收到注入数据.原因可能有两个: - 1.你可能对getCommandDialogConsumer进行了异步调用或条件调用,请在setup中直接调用. + 1.你可能对getConsumer进行了异步调用或条件调用,请在setup中直接调用. 2.你没有在命令弹窗内展示该组件,这个时候你一般可以忽略该警告消息.`); return ve(be, () => new Proxy({}, { get: () => t, apply: t }), !0); -}; +}, Mn = (...e) => (console.warn("Warning: This API will be deprecated in the future, please use `getConsumer` instead."), Qe(...e)); let Te; -const Mn = (e) => { +const Bn = (e) => { Te = e; }, Nn = (e = !0) => { const t = me(), { @@ -159,11 +159,11 @@ const Mn = (e) => { ...a.attrs }), { default: () => o, - footer: () => C("div", null, [a[te(y.cancel)] && C(ee("el-button"), { + footer: () => C("div", null, [a[te(y.cancel)] && C(ee, { onClick: () => i.emit(y.cancel) }, { default: () => [a.cancelBtnText || r("el.messagebox.cancel")] - }), a[te(y.confirm)] && C(ee("el-button"), { + }), a[te(y.confirm)] && C(ee, { type: "primary", onClick: () => i.emit(y.confirm) }, { @@ -183,24 +183,24 @@ const Mn = (e) => { }), i; }; }; -var je = typeof global == "object" && global && global.Object === Object && global, Qe = typeof self == "object" && self && self.Object === Object && self, T = je || Qe || Function("return this")(), D = T.Symbol, xe = Object.prototype, ke = xe.hasOwnProperty, et = xe.toString, O = D ? D.toStringTag : void 0; -function tt(e) { - var t = ke.call(e, O), r = e[O]; +var je = typeof global == "object" && global && global.Object === Object && global, ke = typeof self == "object" && self && self.Object === Object && self, T = je || ke || Function("return this")(), D = T.Symbol, xe = Object.prototype, et = xe.hasOwnProperty, tt = xe.toString, w = D ? D.toStringTag : void 0; +function rt(e) { + var t = et.call(e, w), r = e[w]; try { - e[O] = void 0; + e[w] = void 0; var n = !0; } catch { } - var o = et.call(e); - return n && (t ? e[O] = r : delete e[O]), o; + var o = tt.call(e); + return n && (t ? e[w] = r : delete e[w]), o; } -var rt = Object.prototype, nt = rt.toString; -function ot(e) { - return nt.call(e); +var nt = Object.prototype, ot = nt.toString; +function at(e) { + return ot.call(e); } -var at = "[object Null]", it = "[object Undefined]", ne = D ? D.toStringTag : void 0; -function N(e) { - return e == null ? e === void 0 ? it : at : ne && ne in Object(e) ? tt(e) : ot(e); +var it = "[object Null]", st = "[object Undefined]", ne = D ? D.toStringTag : void 0; +function B(e) { + return e == null ? e === void 0 ? st : it : ne && ne in Object(e) ? rt(e) : at(e); } function A(e) { return e != null && typeof e == "object"; @@ -213,25 +213,25 @@ function _(e) { function Pe(e) { return e; } -var st = "[object AsyncFunction]", ut = "[object Function]", ct = "[object GeneratorFunction]", lt = "[object Proxy]"; +var ut = "[object AsyncFunction]", ct = "[object Function]", lt = "[object GeneratorFunction]", ft = "[object Proxy]"; function Z(e) { if (!_(e)) return !1; - var t = N(e); - return t == ut || t == ct || t == st || t == lt; + var t = B(e); + return t == ct || t == lt || t == ut || t == ft; } var G = T["__core-js_shared__"], oe = function() { var e = /[^.]+$/.exec(G && G.keys && G.keys.IE_PROTO || ""); return e ? "Symbol(src)_1." + e : ""; }(); -function ft(e) { +function pt(e) { return !!oe && oe in e; } -var pt = Function.prototype, dt = pt.toString; -function ht(e) { +var dt = Function.prototype, ht = dt.toString; +function vt(e) { if (e != null) { try { - return dt.call(e); + return ht.call(e); } catch { } try { @@ -241,23 +241,23 @@ function ht(e) { } return ""; } -var vt = /[\\^$.*+?()[\]{}|]/g, mt = /^\[object .+?Constructor\]$/, gt = Function.prototype, yt = Object.prototype, bt = gt.toString, _t = yt.hasOwnProperty, Ct = RegExp( - "^" + bt.call(_t).replace(vt, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$" +var mt = /[\\^$.*+?()[\]{}|]/g, gt = /^\[object .+?Constructor\]$/, yt = Function.prototype, bt = Object.prototype, _t = yt.toString, Ct = bt.hasOwnProperty, Tt = RegExp( + "^" + _t.call(Ct).replace(mt, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$" ); -function Tt(e) { - if (!_(e) || ft(e)) +function jt(e) { + if (!_(e) || pt(e)) return !1; - var t = Z(e) ? Ct : mt; - return t.test(ht(e)); + var t = Z(e) ? Tt : gt; + return t.test(vt(e)); } -function jt(e, t) { +function xt(e, t) { return e == null ? void 0 : e[t]; } function X(e, t) { - var r = jt(e, t); - return Tt(r) ? r : void 0; + var r = xt(e, t); + return jt(r) ? r : void 0; } -var ae = Object.create, xt = /* @__PURE__ */ function() { +var ae = Object.create, Pt = /* @__PURE__ */ function() { function e() { } return function(t) { @@ -270,7 +270,7 @@ var ae = Object.create, xt = /* @__PURE__ */ function() { return e.prototype = void 0, r; }; }(); -function Pt(e, t, r) { +function wt(e, t, r) { switch (r.length) { case 0: return e.call(t); @@ -289,20 +289,20 @@ function Ot(e, t) { t[r] = e[r]; return t; } -var wt = 800, St = 16, At = Date.now; -function $t(e) { +var St = 800, At = 16, $t = Date.now; +function It(e) { var t = 0, r = 0; return function() { - var n = At(), o = St - (n - r); + var n = $t(), o = At - (n - r); if (r = n, o > 0) { - if (++t >= wt) + if (++t >= St) return arguments[0]; } else t = 0; return e.apply(void 0, arguments); }; } -function It(e) { +function Et(e) { return function() { return e; }; @@ -313,17 +313,17 @@ var M = function() { return e({}, "", {}), e; } catch { } -}(), Et = M ? function(e, t) { +}(), Dt = M ? function(e, t) { return M(e, "toString", { configurable: !0, enumerable: !1, - value: It(t), + value: Et(t), writable: !0 }); -} : Pe, Dt = $t(Et), Mt = 9007199254740991, Nt = /^(?:0|[1-9]\d*)$/; -function Oe(e, t) { +} : Pe, Mt = It(Dt), Bt = 9007199254740991, Nt = /^(?:0|[1-9]\d*)$/; +function we(e, t) { var r = typeof e; - return t = t ?? Mt, !!t && (r == "number" || r != "symbol" && Nt.test(e)) && e > -1 && e % 1 == 0 && e < t; + return t = t ?? Bt, !!t && (r == "number" || r != "symbol" && Nt.test(e)) && e > -1 && e % 1 == 0 && e < t; } function J(e, t, r) { t == "__proto__" && M ? M(e, t, { @@ -333,160 +333,160 @@ function J(e, t, r) { writable: !0 }) : e[t] = r; } -function R(e, t) { +function N(e, t) { return e === t || e !== e && t !== t; } var Rt = Object.prototype, zt = Rt.hasOwnProperty; -function Bt(e, t, r) { +function Ft(e, t, r) { var n = e[t]; - (!(zt.call(e, t) && R(n, r)) || r === void 0 && !(t in e)) && J(e, t, r); + (!(zt.call(e, t) && N(n, r)) || r === void 0 && !(t in e)) && J(e, t, r); } -function Ft(e, t, r, n) { +function Ut(e, t, r, n) { var o = !r; r || (r = {}); for (var a = -1, s = t.length; ++a < s; ) { var i = t[a], u = void 0; - u === void 0 && (u = e[i]), o ? J(r, i, u) : Bt(r, i, u); + u === void 0 && (u = e[i]), o ? J(r, i, u) : Ft(r, i, u); } return r; } var ie = Math.max; -function Ut(e, t, r) { +function Gt(e, t, r) { return t = ie(t === void 0 ? e.length - 1 : t, 0), function() { for (var n = arguments, o = -1, a = ie(n.length - t, 0), s = Array(a); ++o < a; ) s[o] = n[t + o]; o = -1; for (var i = Array(t + 1); ++o < t; ) i[o] = n[o]; - return i[t] = r(s), Pt(e, this, i); + return i[t] = r(s), wt(e, this, i); }; } -function Gt(e, t) { - return Dt(Ut(e, t, Pe), e + ""); +function Ht(e, t) { + return Mt(Gt(e, t, Pe), e + ""); } -var Ht = 9007199254740991; -function we(e) { - return typeof e == "number" && e > -1 && e % 1 == 0 && e <= Ht; +var Kt = 9007199254740991; +function Oe(e) { + return typeof e == "number" && e > -1 && e % 1 == 0 && e <= Kt; } function Y(e) { - return e != null && we(e.length) && !Z(e); + return e != null && Oe(e.length) && !Z(e); } -function Kt(e, t, r) { +function Lt(e, t, r) { if (!_(r)) return !1; var n = typeof t; - return (n == "number" ? Y(r) && Oe(t, r.length) : n == "string" && t in r) ? R(r[t], e) : !1; + return (n == "number" ? Y(r) && we(t, r.length) : n == "string" && t in r) ? N(r[t], e) : !1; } -function Lt(e) { - return Gt(function(t, r) { +function Wt(e) { + return Ht(function(t, r) { var n = -1, o = r.length, a = o > 1 ? r[o - 1] : void 0, s = o > 2 ? r[2] : void 0; - for (a = e.length > 3 && typeof a == "function" ? (o--, a) : void 0, s && Kt(r[0], r[1], s) && (a = o < 3 ? void 0 : a, o = 1), t = Object(t); ++n < o; ) { + for (a = e.length > 3 && typeof a == "function" ? (o--, a) : void 0, s && Lt(r[0], r[1], s) && (a = o < 3 ? void 0 : a, o = 1), t = Object(t); ++n < o; ) { var i = r[n]; i && e(t, i, n, a); } return t; }); } -var Wt = Object.prototype; +var Vt = Object.prototype; function Se(e) { - var t = e && e.constructor, r = typeof t == "function" && t.prototype || Wt; + var t = e && e.constructor, r = typeof t == "function" && t.prototype || Vt; return e === r; } -function Vt(e, t) { +function qt(e, t) { for (var r = -1, n = Array(e); ++r < e; ) n[r] = t(r); return n; } -var qt = "[object Arguments]"; +var Zt = "[object Arguments]"; function se(e) { - return A(e) && N(e) == qt; + return A(e) && B(e) == Zt; } -var Ae = Object.prototype, Zt = Ae.hasOwnProperty, Xt = Ae.propertyIsEnumerable, L = se(/* @__PURE__ */ function() { +var Ae = Object.prototype, Xt = Ae.hasOwnProperty, Jt = Ae.propertyIsEnumerable, L = se(/* @__PURE__ */ function() { return arguments; }()) ? se : function(e) { - return A(e) && Zt.call(e, "callee") && !Xt.call(e, "callee"); + return A(e) && Xt.call(e, "callee") && !Jt.call(e, "callee"); }; -function Jt() { +function Yt() { return !1; } -var $e = typeof exports == "object" && exports && !exports.nodeType && exports, ue = $e && typeof module == "object" && module && !module.nodeType && module, Yt = ue && ue.exports === $e, ce = Yt ? T.Buffer : void 0, Qt = ce ? ce.isBuffer : void 0, Ie = Qt || Jt, kt = "[object Arguments]", er = "[object Array]", tr = "[object Boolean]", rr = "[object Date]", nr = "[object Error]", or = "[object Function]", ar = "[object Map]", ir = "[object Number]", sr = "[object Object]", ur = "[object RegExp]", cr = "[object Set]", lr = "[object String]", fr = "[object WeakMap]", pr = "[object ArrayBuffer]", dr = "[object DataView]", hr = "[object Float32Array]", vr = "[object Float64Array]", mr = "[object Int8Array]", gr = "[object Int16Array]", yr = "[object Int32Array]", br = "[object Uint8Array]", _r = "[object Uint8ClampedArray]", Cr = "[object Uint16Array]", Tr = "[object Uint32Array]", c = {}; -c[hr] = c[vr] = c[mr] = c[gr] = c[yr] = c[br] = c[_r] = c[Cr] = c[Tr] = !0; -c[kt] = c[er] = c[pr] = c[tr] = c[dr] = c[rr] = c[nr] = c[or] = c[ar] = c[ir] = c[sr] = c[ur] = c[cr] = c[lr] = c[fr] = !1; -function jr(e) { - return A(e) && we(e.length) && !!c[N(e)]; -} +var $e = typeof exports == "object" && exports && !exports.nodeType && exports, ue = $e && typeof module == "object" && module && !module.nodeType && module, Qt = ue && ue.exports === $e, ce = Qt ? T.Buffer : void 0, kt = ce ? ce.isBuffer : void 0, Ie = kt || Yt, er = "[object Arguments]", tr = "[object Array]", rr = "[object Boolean]", nr = "[object Date]", or = "[object Error]", ar = "[object Function]", ir = "[object Map]", sr = "[object Number]", ur = "[object Object]", cr = "[object RegExp]", lr = "[object Set]", fr = "[object String]", pr = "[object WeakMap]", dr = "[object ArrayBuffer]", hr = "[object DataView]", vr = "[object Float32Array]", mr = "[object Float64Array]", gr = "[object Int8Array]", yr = "[object Int16Array]", br = "[object Int32Array]", _r = "[object Uint8Array]", Cr = "[object Uint8ClampedArray]", Tr = "[object Uint16Array]", jr = "[object Uint32Array]", c = {}; +c[vr] = c[mr] = c[gr] = c[yr] = c[br] = c[_r] = c[Cr] = c[Tr] = c[jr] = !0; +c[er] = c[tr] = c[dr] = c[rr] = c[hr] = c[nr] = c[or] = c[ar] = c[ir] = c[sr] = c[ur] = c[cr] = c[lr] = c[fr] = c[pr] = !1; function xr(e) { + return A(e) && Oe(e.length) && !!c[B(e)]; +} +function Pr(e) { return function(t) { return e(t); }; } -var Ee = typeof exports == "object" && exports && !exports.nodeType && exports, w = Ee && typeof module == "object" && module && !module.nodeType && module, Pr = w && w.exports === Ee, H = Pr && je.process, le = function() { +var Ee = typeof exports == "object" && exports && !exports.nodeType && exports, O = Ee && typeof module == "object" && module && !module.nodeType && module, wr = O && O.exports === Ee, H = wr && je.process, le = function() { try { - var e = w && w.require && w.require("util").types; + var e = O && O.require && O.require("util").types; return e || H && H.binding && H.binding("util"); } catch { } -}(), fe = le && le.isTypedArray, De = fe ? xr(fe) : jr; +}(), fe = le && le.isTypedArray, De = fe ? Pr(fe) : xr; function Or(e, t) { - var r = K(e), n = !r && L(e), o = !r && !n && Ie(e), a = !r && !n && !o && De(e), s = r || n || o || a, i = s ? Vt(e.length, String) : [], u = i.length; + var r = K(e), n = !r && L(e), o = !r && !n && Ie(e), a = !r && !n && !o && De(e), s = r || n || o || a, i = s ? qt(e.length, String) : [], u = i.length; for (var l in e) s && // Safari 9 has enumerable `arguments.length` in strict mode. (l == "length" || // Node.js 0.10 has enumerable non-index properties on buffers. o && (l == "offset" || l == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays. a && (l == "buffer" || l == "byteLength" || l == "byteOffset") || // Skip index properties. - Oe(l, u)) || i.push(l); + we(l, u)) || i.push(l); return i; } -function wr(e, t) { +function Sr(e, t) { return function(r) { return e(t(r)); }; } -function Sr(e) { +function Ar(e) { var t = []; if (e != null) for (var r in Object(e)) t.push(r); return t; } -var Ar = Object.prototype, $r = Ar.hasOwnProperty; -function Ir(e) { +var $r = Object.prototype, Ir = $r.hasOwnProperty; +function Er(e) { if (!_(e)) - return Sr(e); + return Ar(e); var t = Se(e), r = []; for (var n in e) - n == "constructor" && (t || !$r.call(e, n)) || r.push(n); + n == "constructor" && (t || !Ir.call(e, n)) || r.push(n); return r; } function Me(e) { - return Y(e) ? Or(e) : Ir(e); + return Y(e) ? Or(e) : Er(e); } var S = X(Object, "create"); -function Er() { +function Dr() { this.__data__ = S ? S(null) : {}, this.size = 0; } -function Dr(e) { +function Mr(e) { var t = this.has(e) && delete this.__data__[e]; return this.size -= t ? 1 : 0, t; } -var Mr = "__lodash_hash_undefined__", Nr = Object.prototype, Rr = Nr.hasOwnProperty; +var Br = "__lodash_hash_undefined__", Nr = Object.prototype, Rr = Nr.hasOwnProperty; function zr(e) { var t = this.__data__; if (S) { var r = t[e]; - return r === Mr ? void 0 : r; + return r === Br ? void 0 : r; } return Rr.call(t, e) ? t[e] : void 0; } -var Br = Object.prototype, Fr = Br.hasOwnProperty; -function Ur(e) { +var Fr = Object.prototype, Ur = Fr.hasOwnProperty; +function Gr(e) { var t = this.__data__; - return S ? t[e] !== void 0 : Fr.call(t, e); + return S ? t[e] !== void 0 : Ur.call(t, e); } -var Gr = "__lodash_hash_undefined__"; -function Hr(e, t) { +var Hr = "__lodash_hash_undefined__"; +function Kr(e, t) { var r = this.__data__; - return this.size += this.has(e) ? 0 : 1, r[e] = S && t === void 0 ? Gr : t, this; + return this.size += this.has(e) ? 0 : 1, r[e] = S && t === void 0 ? Hr : t, this; } function b(e) { var t = -1, r = e == null ? 0 : e.length; @@ -495,37 +495,37 @@ function b(e) { this.set(n[0], n[1]); } } -b.prototype.clear = Er; -b.prototype.delete = Dr; +b.prototype.clear = Dr; +b.prototype.delete = Mr; b.prototype.get = zr; -b.prototype.has = Ur; -b.prototype.set = Hr; -function Kr() { +b.prototype.has = Gr; +b.prototype.set = Kr; +function Lr() { this.__data__ = [], this.size = 0; } -function z(e, t) { +function R(e, t) { for (var r = e.length; r--; ) - if (R(e[r][0], t)) + if (N(e[r][0], t)) return r; return -1; } -var Lr = Array.prototype, Wr = Lr.splice; -function Vr(e) { - var t = this.__data__, r = z(t, e); +var Wr = Array.prototype, Vr = Wr.splice; +function qr(e) { + var t = this.__data__, r = R(t, e); if (r < 0) return !1; var n = t.length - 1; - return r == n ? t.pop() : Wr.call(t, r, 1), --this.size, !0; + return r == n ? t.pop() : Vr.call(t, r, 1), --this.size, !0; } -function qr(e) { - var t = this.__data__, r = z(t, e); +function Zr(e) { + var t = this.__data__, r = R(t, e); return r < 0 ? void 0 : t[r][1]; } -function Zr(e) { - return z(this.__data__, e) > -1; +function Xr(e) { + return R(this.__data__, e) > -1; } -function Xr(e, t) { - var r = this.__data__, n = z(r, e); +function Jr(e, t) { + var r = this.__data__, n = R(r, e); return n < 0 ? (++this.size, r.push([e, t])) : r[n][1] = t, this; } function m(e) { @@ -535,39 +535,39 @@ function m(e) { this.set(n[0], n[1]); } } -m.prototype.clear = Kr; -m.prototype.delete = Vr; -m.prototype.get = qr; -m.prototype.has = Zr; -m.prototype.set = Xr; -var Ne = X(T, "Map"); -function Jr() { +m.prototype.clear = Lr; +m.prototype.delete = qr; +m.prototype.get = Zr; +m.prototype.has = Xr; +m.prototype.set = Jr; +var Be = X(T, "Map"); +function Yr() { this.size = 0, this.__data__ = { hash: new b(), - map: new (Ne || m)(), + map: new (Be || m)(), string: new b() }; } -function Yr(e) { +function Qr(e) { var t = typeof e; return t == "string" || t == "number" || t == "symbol" || t == "boolean" ? e !== "__proto__" : e === null; } -function B(e, t) { +function z(e, t) { var r = e.__data__; - return Yr(t) ? r[typeof t == "string" ? "string" : "hash"] : r.map; -} -function Qr(e) { - var t = B(this, e).delete(e); - return this.size -= t ? 1 : 0, t; + return Qr(t) ? r[typeof t == "string" ? "string" : "hash"] : r.map; } function kr(e) { - return B(this, e).get(e); + var t = z(this, e).delete(e); + return this.size -= t ? 1 : 0, t; } function en(e) { - return B(this, e).has(e); + return z(this, e).get(e); } -function tn(e, t) { - var r = B(this, e), n = r.size; +function tn(e) { + return z(this, e).has(e); +} +function rn(e, t) { + var r = z(this, e), n = r.size; return r.set(e, t), this.size += r.size == n ? 0 : 1, this; } function j(e) { @@ -577,40 +577,40 @@ function j(e) { this.set(n[0], n[1]); } } -j.prototype.clear = Jr; -j.prototype.delete = Qr; -j.prototype.get = kr; -j.prototype.has = en; -j.prototype.set = tn; -var Re = wr(Object.getPrototypeOf, Object), rn = "[object Object]", nn = Function.prototype, on = Object.prototype, ze = nn.toString, an = on.hasOwnProperty, sn = ze.call(Object); -function un(e) { - if (!A(e) || N(e) != rn) +j.prototype.clear = Yr; +j.prototype.delete = kr; +j.prototype.get = en; +j.prototype.has = tn; +j.prototype.set = rn; +var Ne = Sr(Object.getPrototypeOf, Object), nn = "[object Object]", on = Function.prototype, an = Object.prototype, Re = on.toString, sn = an.hasOwnProperty, un = Re.call(Object); +function cn(e) { + if (!A(e) || B(e) != nn) return !1; - var t = Re(e); + var t = Ne(e); if (t === null) return !0; - var r = an.call(t, "constructor") && t.constructor; - return typeof r == "function" && r instanceof r && ze.call(r) == sn; + var r = sn.call(t, "constructor") && t.constructor; + return typeof r == "function" && r instanceof r && Re.call(r) == un; } -function cn() { +function ln() { this.__data__ = new m(), this.size = 0; } -function ln(e) { +function fn(e) { var t = this.__data__, r = t.delete(e); return this.size = t.size, r; } -function fn(e) { +function pn(e) { return this.__data__.get(e); } -function pn(e) { +function dn(e) { return this.__data__.has(e); } -var dn = 200; -function hn(e, t) { +var hn = 200; +function vn(e, t) { var r = this.__data__; if (r instanceof m) { var n = r.__data__; - if (!Ne || n.length < dn - 1) + if (!Be || n.length < hn - 1) return n.push([e, t]), this.size = ++r.size, this; r = this.__data__ = new j(n); } @@ -620,29 +620,29 @@ function x(e) { var t = this.__data__ = new m(e); this.size = t.size; } -x.prototype.clear = cn; -x.prototype.delete = ln; -x.prototype.get = fn; -x.prototype.has = pn; -x.prototype.set = hn; -var Be = typeof exports == "object" && exports && !exports.nodeType && exports, pe = Be && typeof module == "object" && module && !module.nodeType && module, vn = pe && pe.exports === Be, de = vn ? T.Buffer : void 0; +x.prototype.clear = ln; +x.prototype.delete = fn; +x.prototype.get = pn; +x.prototype.has = dn; +x.prototype.set = vn; +var ze = typeof exports == "object" && exports && !exports.nodeType && exports, pe = ze && typeof module == "object" && module && !module.nodeType && module, mn = pe && pe.exports === ze, de = mn ? T.Buffer : void 0; de && de.allocUnsafe; -function mn(e, t) { +function gn(e, t) { return e.slice(); } var he = T.Uint8Array; -function gn(e) { +function yn(e) { var t = new e.constructor(e.byteLength); return new he(t).set(new he(e)), t; } -function yn(e, t) { - var r = gn(e.buffer); +function bn(e, t) { + var r = yn(e.buffer); return new e.constructor(r, e.byteOffset, e.length); } -function bn(e) { - return typeof e.constructor == "function" && !Se(e) ? xt(Re(e)) : {}; -} function _n(e) { + return typeof e.constructor == "function" && !Se(e) ? Pt(Ne(e)) : {}; +} +function Cn(e) { return function(t, r, n) { for (var o = -1, a = Object(t), s = n(t), i = s.length; i--; ) { var u = s[++o]; @@ -652,21 +652,21 @@ function _n(e) { return t; }; } -var Cn = _n(); +var Tn = Cn(); function W(e, t, r) { - (r !== void 0 && !R(e[t], r) || r === void 0 && !(t in e)) && J(e, t, r); + (r !== void 0 && !N(e[t], r) || r === void 0 && !(t in e)) && J(e, t, r); } -function Tn(e) { +function jn(e) { return A(e) && Y(e); } function V(e, t) { if (!(t === "constructor" && typeof e[t] == "function") && t != "__proto__") return e[t]; } -function jn(e) { - return Ft(e, Me(e)); +function xn(e) { + return Ut(e, Me(e)); } -function xn(e, t, r, n, o, a, s) { +function Pn(e, t, r, n, o, a, s) { var i = V(e, r), u = V(t, r), l = s.get(u); if (l) { W(e, r, l); @@ -675,21 +675,21 @@ function xn(e, t, r, n, o, a, s) { var f = a ? a(i, u, r + "", e, t, s) : void 0, v = f === void 0; if (v) { var g = K(u), $ = !g && Ie(u), F = !g && !$ && De(u); - f = u, g || $ || F ? K(i) ? f = i : Tn(i) ? f = Ot(i) : $ ? (v = !1, f = mn(u)) : F ? (v = !1, f = yn(u)) : f = [] : un(u) || L(u) ? (f = i, L(i) ? f = jn(i) : (!_(i) || Z(i)) && (f = bn(u))) : v = !1; + f = u, g || $ || F ? K(i) ? f = i : jn(i) ? f = Ot(i) : $ ? (v = !1, f = gn(u)) : F ? (v = !1, f = bn(u)) : f = [] : cn(u) || L(u) ? (f = i, L(i) ? f = xn(i) : (!_(i) || Z(i)) && (f = _n(u))) : v = !1; } v && (s.set(u, f), o(f, u, n, a, s), s.delete(u)), W(e, r, f); } function Fe(e, t, r, n, o) { - e !== t && Cn(t, function(a, s) { + e !== t && Tn(t, function(a, s) { if (o || (o = new x()), _(a)) - xn(e, t, s, r, Fe, n, o); + Pn(e, t, s, r, Fe, n, o); else { var i = n ? n(V(e, s), a, s + "", e, t, o) : void 0; i === void 0 && (i = a), W(e, s, i); } }, Me); } -var Pn = Lt(function(e, t, r) { +var wn = Wt(function(e, t, r) { Fe(e, t, r); }); let Ue; @@ -703,7 +703,7 @@ const Rn = (e) => { backgroundColor: "#fff", color: "#000" } -}, wn = (e = !0) => { +}, Sn = (e = !0) => { const t = me(); return (n, o = {}) => { const a = E(e), s = Ce(t, ge(/* @__PURE__ */ q({ @@ -739,8 +739,8 @@ const Rn = (e) => { return s; }; }, zn = (e = !0) => { - const t = wn(e); - return (r, n = {}) => (Pn(n, { + const t = Sn(e); + return (r, n = {}) => (wn(n, { attrs: { position: "bottom", style: { @@ -751,18 +751,19 @@ const Rn = (e) => { }; export { be as CommandDialogConsumerInjectKey, - Ce as CommandDialogProvider, re as CommandDialogStackInjectKey, + Ce as CommandProvider, Ze as ConsumerEventBus, y as EVENT_NAME, Je as PromiseWithResolvers, te as busName2EventName, Nn as createElementPlusDialog, - wn as createVantUiPopup, + Sn as createVantUiPopup, zn as createVantUiPopupOnBottom, Xe as eventName2BusName, - Dn as getCommandDialogConsumer, + Mn as getCommandDialogConsumer, + Qe as getConsumer, Ye as getMaxZIndex, - Mn as setElementPlusDialogMountNode, + Bn as setElementPlusDialogMountNode, Rn as setVantUiPopupMountNode }; diff --git a/dist/index.umd.cjs b/dist/index.umd.cjs index 6fe1b48..94bac9d 100644 --- a/dist/index.umd.cjs +++ b/dist/index.umd.cjs @@ -1,3 +1,3 @@ -(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("element-plus"),require("vant")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus","vant"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.Vue3CommandDialog={},s.Vue,s.ElementPlus,s.Vant))})(this,function(s,c,C,Ue){"use strict";var Tr=Object.defineProperty;var jr=(s,c,C)=>c in s?Tr(s,c,{enumerable:!0,configurable:!0,writable:!0,value:C}):s[c]=C;var ze=(s,c,C)=>jr(s,typeof c!="symbol"?c+"":c,C);class te{constructor(){ze(this,"map",new WeakMap)}getEventsMapByConsumer(t){let n=this.map.get(t);return n||(n=new Map,this.map.set(t,n)),n}getEventsByConsumer(t,n){const r=this.getEventsMapByConsumer(t);let o=r.get(n);return o||(o=new Set,r.set(n,o)),o}on(t,n,r,o={}){const a=this.getEventsByConsumer(t,n);let u=r;o.once&&(u=(...i)=>{r(...i),this.off(t,n,u)}),a.add(u),o.callAfterDelay!==void 0&&setTimeout(()=>{u()},o.callAfterDelay||0)}once(t,n,r){this.on(t,n,r,{once:!0})}emit(t,n,...r){this.getEventsByConsumer(t,n).forEach(a=>a(...r))}off(t,n,r){this.getEventsByConsumer(t,n).delete(r)}}const ne=(e="")=>e.slice(2).toLowerCase(),V=(e="")=>`on${e.charAt(0).toUpperCase()}${e.slice(1)}`,re=()=>{let e=()=>{},t=()=>{};return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}},oe=e=>{var r;const t=((r=e.parentElement)==null?void 0:r.children)||[];let n=0;return Array.from(t).forEach(o=>{if(o!==e){const a=parseInt(window.getComputedStyle(o).zIndex);!isNaN(a)&&a>n&&(n=a)}}),n};var v=(e=>(e.confirm="confirm",e.cancel="cancel",e.destory="destory",e))(v||{});const F=Symbol("CommandDialogConsumerInjectKey"),K=Symbol("CommandDialogStackInjectKey"),D=new te,ae=e=>({...e.parent?ae(e.parent):{},...e.provides});function G(e,t,n){const r=(typeof n.appendTo=="string"?document.querySelector(n.appendTo):n.appendTo)||document.body,o=document.createElement("div");o.className="command-commponent-container",r.appendChild(o);const a=oe(o);o.style.position="relative",o.style.zIndex=String(Math.max(a+1,9999));const u=()=>{n.visible.value=!1},i=()=>{n.visible.value=!0},l=()=>{c.nextTick(()=>{c.render(null,o),o.remove()})},d=(h=!1)=>{h?(m.on(v.destory,l,{once:!0,callAfterDelay:3e3}),u()):m.stack.splice(m.stackIndex).forEach(g=>g.destroy(!0))},{promise:p,resolve:y,reject:_}=re(),m={promise:p,resolve:y,reject:_,destroyWithResolve:h=>{y(h),d()},destroyWithReject:h=>{_(h),d()},hide:u,show:i,destroy:d,container:o,visible:n.visible,on:(h,g,Cr={})=>D.on(m,h,g,Cr),once:(h,g)=>D.once(m,h,g),emit:(h,...g)=>D.emit(m,h,...g),off:(h,g)=>D.off(m,h,g),stack:[],stackIndex:-1,componentRef:void 0},_r=c.defineComponent({setup(){for(const g in n.provideProps)c.provide(g,n.provideProps[g]);c.provide(F,m);const h=c.inject(K,[]);return m.stackIndex=h.length,h.push(m),c.provide(K,h),m.stack=h,()=>t}}),I=c.createVNode(_r,null,null);return I.appContext=(e==null?void 0:e.appContext)||I.appContext,I.appContext.provides={...I.appContext.provides,...ae(e)},c.render(I,o),m}const Ve=(e=!0)=>{const t=()=>e&&console.warn(`别调用了欧尼酱~,这会儿没啥实际用途;没有根据CommandDialogInjectKey接收到注入数据.原因可能有两个: - 1.你可能对getCommandDialogConsumer进行了异步调用或条件调用,请在setup中直接调用. - 2.你没有在命令弹窗内展示该组件,这个时候你一般可以忽略该警告消息.`);return c.inject(F,()=>new Proxy({},{get:()=>t,apply:t}),!0)};let ie;const Fe=e=>{ie=e},Ke=(e=!0)=>{const t=c.getCurrentInstance(),{locale:{t:n}}=C.useGlobalComponentSettings("message-box");return(o,a={})=>{const u=c.ref(e),i=G(t,c.h(c.defineComponent({setup(){const l=c.ref(),d=_=>{_(),i.destroy()},p=()=>{i.emit(v.destory)},y=()=>{Promise.resolve().then(()=>{i.componentRef=l})};return()=>c.createVNode(C.ElDialog,c.mergeProps({ref:l,modelValue:u.value,beforeClose:d,onClosed:p,onVnodeMounted:y},{title:a.title,width:a.width,...a.attrs}),{default:()=>o,footer:()=>c.createVNode("div",null,[a[V(v.cancel)]&&c.createVNode(c.resolveComponent("el-button"),{onClick:()=>i.emit(v.cancel)},{default:()=>[a.cancelBtnText||n("el.messagebox.cancel")]}),a[V(v.confirm)]&&c.createVNode(c.resolveComponent("el-button"),{type:"primary",onClick:()=>i.emit(v.confirm)},{default:()=>[a.confirmBtnText||n("el.messagebox.confirm")]})]),...a.slots})}})),{provideProps:a.provideProps||{},appendTo:ie||a.appendTo,visible:u});return Object.entries(a).filter(([l,d])=>l.startsWith("on")&&typeof d=="function").forEach(([l,d])=>{const p=ne(l);i.on(p,d)}),i}};var se=typeof global=="object"&&global&&global.Object===Object&&global,Ge=typeof self=="object"&&self&&self.Object===Object&&self,P=se||Ge||Function("return this")(),M=P.Symbol,ce=Object.prototype,He=ce.hasOwnProperty,Le=ce.toString,S=M?M.toStringTag:void 0;function We(e){var t=He.call(e,S),n=e[S];try{e[S]=void 0;var r=!0}catch{}var o=Le.call(e);return r&&(t?e[S]=n:delete e[S]),o}var qe=Object.prototype,Ze=qe.toString;function Xe(e){return Ze.call(e)}var Je="[object Null]",Ye="[object Undefined]",ue=M?M.toStringTag:void 0;function N(e){return e==null?e===void 0?Ye:Je:ue&&ue in Object(e)?We(e):Xe(e)}function A(e){return e!=null&&typeof e=="object"}var H=Array.isArray;function T(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function le(e){return e}var Qe="[object AsyncFunction]",ke="[object Function]",et="[object GeneratorFunction]",tt="[object Proxy]";function L(e){if(!T(e))return!1;var t=N(e);return t==ke||t==et||t==Qe||t==tt}var W=P["__core-js_shared__"],fe=function(){var e=/[^.]+$/.exec(W&&W.keys&&W.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function nt(e){return!!fe&&fe in e}var rt=Function.prototype,ot=rt.toString;function at(e){if(e!=null){try{return ot.call(e)}catch{}try{return e+""}catch{}}return""}var it=/[\\^$.*+?()[\]{}|]/g,st=/^\[object .+?Constructor\]$/,ct=Function.prototype,ut=Object.prototype,lt=ct.toString,ft=ut.hasOwnProperty,dt=RegExp("^"+lt.call(ft).replace(it,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function pt(e){if(!T(e)||nt(e))return!1;var t=L(e)?dt:st;return t.test(at(e))}function ht(e,t){return e==null?void 0:e[t]}function q(e,t){var n=ht(e,t);return pt(n)?n:void 0}var de=Object.create,mt=function(){function e(){}return function(t){if(!T(t))return{};if(de)return de(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function gt(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function yt(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n0){if(++t>=vt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Tt(e){return function(){return e}}var x=function(){try{var e=q(Object,"defineProperty");return e({},"",{}),e}catch{}}(),jt=x?function(e,t){return x(e,"toString",{configurable:!0,enumerable:!1,value:Tt(t),writable:!0})}:le,Pt=Ct(jt),Ot=9007199254740991,wt=/^(?:0|[1-9]\d*)$/;function pe(e,t){var n=typeof e;return t=t??Ot,!!t&&(n=="number"||n!="symbol"&&wt.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=Mt}function X(e){return e!=null&&me(e.length)&&!L(e)}function Nt(e,t,n){if(!T(n))return!1;var r=typeof t;return(r=="number"?X(n)&&pe(t,n.length):r=="string"&&t in n)?B(n[t],e):!1}function xt(e){return Dt(function(t,n){var r=-1,o=n.length,a=o>1?n[o-1]:void 0,u=o>2?n[2]:void 0;for(a=e.length>3&&typeof a=="function"?(o--,a):void 0,u&&Nt(n[0],n[1],u)&&(a=o<3?void 0:a,o=1),t=Object(t);++r-1}function Fn(e,t){var n=this.__data__,r=R(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function b(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t{Be=e},vr={round:!0,lockScroll:!0,closeable:!0,style:{backgroundColor:"#fff",color:"#000"}},Re=(e=!0)=>{const t=c.getCurrentInstance();return(r,o={})=>{const a=c.ref(e),u=G(t,c.h(c.defineComponent({setup(){const i=c.ref(),l=()=>{u.destroy()},d=()=>{u.emit(v.destory)},p=()=>{Promise.resolve().then(()=>{u.componentRef=i})};return()=>c.createVNode(Ue.Popup,c.mergeProps({ref:i,show:a.value,onClickCloseIcon:l,onClosed:d,onVnodeMounted:p},{...vr,...o.attrs}),{default:()=>r,...o.slots})}})),{provideProps:o.provideProps||{},appendTo:Be||o.appendTo,visible:a});return u}},br=(e=!0)=>{const t=Re(e);return(n,r={})=>(gr(r,{attrs:{position:"bottom",style:{width:"100vw"}}}),t(n,r))};s.CommandDialogConsumerInjectKey=F,s.CommandDialogProvider=G,s.CommandDialogStackInjectKey=K,s.ConsumerEventBus=te,s.EVENT_NAME=v,s.PromiseWithResolvers=re,s.busName2EventName=V,s.createElementPlusDialog=Ke,s.createVantUiPopup=Re,s.createVantUiPopupOnBottom=br,s.eventName2BusName=ne,s.getCommandDialogConsumer=Ve,s.getMaxZIndex=oe,s.setElementPlusDialogMountNode=Fe,s.setVantUiPopupMountNode=yr,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}); +(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("element-plus"),require("vant")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus","vant"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.Vue3CommandDialog={},s.Vue,s.ElementPlus,s.Vant))})(this,function(s,c,v,Ve){"use strict";var jr=Object.defineProperty;var Pr=(s,c,v)=>c in s?jr(s,c,{enumerable:!0,configurable:!0,writable:!0,value:v}):s[c]=v;var Ue=(s,c,v)=>Pr(s,typeof c!="symbol"?c+"":c,v);class te{constructor(){Ue(this,"map",new WeakMap)}getEventsMapByConsumer(t){let n=this.map.get(t);return n||(n=new Map,this.map.set(t,n)),n}getEventsByConsumer(t,n){const r=this.getEventsMapByConsumer(t);let o=r.get(n);return o||(o=new Set,r.set(n,o)),o}on(t,n,r,o={}){const a=this.getEventsByConsumer(t,n);let u=r;o.once&&(u=(...i)=>{r(...i),this.off(t,n,u)}),a.add(u),o.callAfterDelay!==void 0&&setTimeout(()=>{u()},o.callAfterDelay||0)}once(t,n,r){this.on(t,n,r,{once:!0})}emit(t,n,...r){this.getEventsByConsumer(t,n).forEach(a=>a(...r))}off(t,n,r){this.getEventsByConsumer(t,n).delete(r)}}const ne=(e="")=>e.slice(2).toLowerCase(),V=(e="")=>`on${e.charAt(0).toUpperCase()}${e.slice(1)}`,re=()=>{let e=()=>{},t=()=>{};return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}},oe=e=>{var r;const t=((r=e.parentElement)==null?void 0:r.children)||[];let n=0;return Array.from(t).forEach(o=>{if(o!==e){const a=parseInt(window.getComputedStyle(o).zIndex);!isNaN(a)&&a>n&&(n=a)}}),n};var b=(e=>(e.confirm="confirm",e.cancel="cancel",e.destory="destory",e))(b||{});const F=Symbol("CommandDialogConsumerInjectKey"),K=Symbol("CommandDialogStackInjectKey"),D=new te,ae=e=>({...e.parent?ae(e.parent):{},...e.provides});function G(e,t,n){const r=(typeof n.appendTo=="string"?document.querySelector(n.appendTo):n.appendTo)||document.body,o=document.createElement("div");o.className="command-commponent-container",r.appendChild(o);const a=oe(o);o.style.position="relative",o.style.zIndex=String(Math.max(a+1,9999));const u=()=>{n.visible.value=!1},i=()=>{n.visible.value=!0},l=()=>{c.nextTick(()=>{c.render(null,o),o.remove()})},d=(h=!1)=>{h?(m.on(b.destory,l,{once:!0,callAfterDelay:3e3}),u()):m.stack.splice(m.stackIndex).forEach(g=>g.destroy(!0))},{promise:p,resolve:y,reject:C}=re(),m={promise:p,resolve:y,reject:C,destroyWithResolve:h=>{y(h),d()},destroyWithReject:h=>{C(h),d()},hide:u,show:i,destroy:d,container:o,visible:n.visible,on:(h,g,Tr={})=>D.on(m,h,g,Tr),once:(h,g)=>D.once(m,h,g),emit:(h,...g)=>D.emit(m,h,...g),off:(h,g)=>D.off(m,h,g),stack:[],stackIndex:-1,componentRef:void 0},Cr=c.defineComponent({setup(){for(const g in n.provideProps)c.provide(g,n.provideProps[g]);c.provide(F,m);const h=c.inject(K,[]);return m.stackIndex=h.length,h.push(m),c.provide(K,h),m.stack=h,()=>t}}),$=c.createVNode(Cr,null,null);return $.appContext=(e==null?void 0:e.appContext)||$.appContext,$.appContext.provides={...$.appContext.provides,...ae(e)},c.render($,o),m}const ie=(e=!0)=>{const t=()=>e&&console.warn(`别调用了欧尼酱~,这会儿没啥实际用途;没有根据CommandDialogInjectKey接收到注入数据.原因可能有两个: + 1.你可能对getConsumer进行了异步调用或条件调用,请在setup中直接调用. + 2.你没有在命令弹窗内展示该组件,这个时候你一般可以忽略该警告消息.`);return c.inject(F,()=>new Proxy({},{get:()=>t,apply:t}),!0)},Fe=(...e)=>(console.warn("Warning: This API will be deprecated in the future, please use `getConsumer` instead."),ie(...e));let se;const Ke=e=>{se=e},Ge=(e=!0)=>{const t=c.getCurrentInstance(),{locale:{t:n}}=v.useGlobalComponentSettings("message-box");return(o,a={})=>{const u=c.ref(e),i=G(t,c.h(c.defineComponent({setup(){const l=c.ref(),d=C=>{C(),i.destroy()},p=()=>{i.emit(b.destory)},y=()=>{Promise.resolve().then(()=>{i.componentRef=l})};return()=>c.createVNode(v.ElDialog,c.mergeProps({ref:l,modelValue:u.value,beforeClose:d,onClosed:p,onVnodeMounted:y},{title:a.title,width:a.width,...a.attrs}),{default:()=>o,footer:()=>c.createVNode("div",null,[a[V(b.cancel)]&&c.createVNode(v.ElButton,{onClick:()=>i.emit(b.cancel)},{default:()=>[a.cancelBtnText||n("el.messagebox.cancel")]}),a[V(b.confirm)]&&c.createVNode(v.ElButton,{type:"primary",onClick:()=>i.emit(b.confirm)},{default:()=>[a.confirmBtnText||n("el.messagebox.confirm")]})]),...a.slots})}})),{provideProps:a.provideProps||{},appendTo:se||a.appendTo,visible:u});return Object.entries(a).filter(([l,d])=>l.startsWith("on")&&typeof d=="function").forEach(([l,d])=>{const p=ne(l);i.on(p,d)}),i}};var ue=typeof global=="object"&&global&&global.Object===Object&&global,He=typeof self=="object"&&self&&self.Object===Object&&self,P=ue||He||Function("return this")(),M=P.Symbol,ce=Object.prototype,We=ce.hasOwnProperty,Le=ce.toString,S=M?M.toStringTag:void 0;function qe(e){var t=We.call(e,S),n=e[S];try{e[S]=void 0;var r=!0}catch{}var o=Le.call(e);return r&&(t?e[S]=n:delete e[S]),o}var Ze=Object.prototype,Xe=Ze.toString;function Je(e){return Xe.call(e)}var Ye="[object Null]",Qe="[object Undefined]",le=M?M.toStringTag:void 0;function N(e){return e==null?e===void 0?Qe:Ye:le&&le in Object(e)?qe(e):Je(e)}function A(e){return e!=null&&typeof e=="object"}var H=Array.isArray;function T(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function fe(e){return e}var ke="[object AsyncFunction]",et="[object Function]",tt="[object GeneratorFunction]",nt="[object Proxy]";function W(e){if(!T(e))return!1;var t=N(e);return t==et||t==tt||t==ke||t==nt}var L=P["__core-js_shared__"],de=function(){var e=/[^.]+$/.exec(L&&L.keys&&L.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function rt(e){return!!de&&de in e}var ot=Function.prototype,at=ot.toString;function it(e){if(e!=null){try{return at.call(e)}catch{}try{return e+""}catch{}}return""}var st=/[\\^$.*+?()[\]{}|]/g,ut=/^\[object .+?Constructor\]$/,ct=Function.prototype,lt=Object.prototype,ft=ct.toString,dt=lt.hasOwnProperty,pt=RegExp("^"+ft.call(dt).replace(st,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ht(e){if(!T(e)||rt(e))return!1;var t=W(e)?pt:ut;return t.test(it(e))}function mt(e,t){return e==null?void 0:e[t]}function q(e,t){var n=mt(e,t);return ht(n)?n:void 0}var pe=Object.create,gt=function(){function e(){}return function(t){if(!T(t))return{};if(pe)return pe(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function yt(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}function vt(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n0){if(++t>=bt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function jt(e){return function(){return e}}var x=function(){try{var e=q(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Pt=x?function(e,t){return x(e,"toString",{configurable:!0,enumerable:!1,value:jt(t),writable:!0})}:fe,Ot=Tt(Pt),wt=9007199254740991,St=/^(?:0|[1-9]\d*)$/;function he(e,t){var n=typeof e;return t=t??wt,!!t&&(n=="number"||n!="symbol"&&St.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=Nt}function X(e){return e!=null&&ge(e.length)&&!W(e)}function xt(e,t,n){if(!T(n))return!1;var r=typeof t;return(r=="number"?X(n)&&he(t,n.length):r=="string"&&t in n)?B(n[t],e):!1}function Bt(e){return Mt(function(t,n){var r=-1,o=n.length,a=o>1?n[o-1]:void 0,u=o>2?n[2]:void 0;for(a=e.length>3&&typeof a=="function"?(o--,a):void 0,u&&xt(n[0],n[1],u)&&(a=o<3?void 0:a,o=1),t=Object(t);++r-1}function Kn(e,t){var n=this.__data__,r=R(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function _(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t{Re=e},br={round:!0,lockScroll:!0,closeable:!0,style:{backgroundColor:"#fff",color:"#000"}},ze=(e=!0)=>{const t=c.getCurrentInstance();return(r,o={})=>{const a=c.ref(e),u=G(t,c.h(c.defineComponent({setup(){const i=c.ref(),l=()=>{u.destroy()},d=()=>{u.emit(b.destory)},p=()=>{Promise.resolve().then(()=>{u.componentRef=i})};return()=>c.createVNode(Ve.Popup,c.mergeProps({ref:i,show:a.value,onClickCloseIcon:l,onClosed:d,onVnodeMounted:p},{...br,...o.attrs}),{default:()=>r,...o.slots})}})),{provideProps:o.provideProps||{},appendTo:Re||o.appendTo,visible:a});return u}},_r=(e=!0)=>{const t=ze(e);return(n,r={})=>(yr(r,{attrs:{position:"bottom",style:{width:"100vw"}}}),t(n,r))};s.CommandDialogConsumerInjectKey=F,s.CommandDialogStackInjectKey=K,s.CommandProvider=G,s.ConsumerEventBus=te,s.EVENT_NAME=b,s.PromiseWithResolvers=re,s.busName2EventName=V,s.createElementPlusDialog=Ge,s.createVantUiPopup=ze,s.createVantUiPopupOnBottom=_r,s.eventName2BusName=ne,s.getCommandDialogConsumer=Fe,s.getConsumer=ie,s.getMaxZIndex=oe,s.setElementPlusDialogMountNode=Ke,s.setVantUiPopupMountNode=vr,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}); diff --git a/dist/src/components/Core.d.ts b/dist/src/components/Core.d.ts index 09b2896..d362344 100644 --- a/dist/src/components/Core.d.ts +++ b/dist/src/components/Core.d.ts @@ -46,5 +46,6 @@ export interface IConsumer { } export declare const CommandDialogConsumerInjectKey: InjectionKey; export declare const CommandDialogStackInjectKey: InjectionKey; -export declare function CommandDialogProvider(parentInstance: ComponentInternalInstance | null, uiComponentVnode: Component, config: ICommandDialogProviderConfig): IConsumer; -export declare const getCommandDialogConsumer: (warn?: boolean) => IConsumer; +export declare function CommandProvider(parentInstance: ComponentInternalInstance | null, uiComponentVnode: Component, config: ICommandDialogProviderConfig): IConsumer; +export declare const getConsumer: (warn?: boolean) => IConsumer; +export declare const getCommandDialogConsumer: (...args: any) => IConsumer; diff --git a/package.json b/package.json index fbe82da..b2d314e 100644 --- a/package.json +++ b/package.json @@ -48,5 +48,15 @@ }, "dependencies": { "lodash-es": "^4.17.21" - } + }, + "keywords": [ + "vue3", + "command", + "command-dialog", + "command-palette", + "vue-component", + "ui-component", + "element-plus", + "vant" + ] } diff --git a/src/components/Core.tsx b/src/components/Core.tsx index 41c6ddb..e649951 100644 --- a/src/components/Core.tsx +++ b/src/components/Core.tsx @@ -62,7 +62,7 @@ const getProvidesChain = (ins: ComponentInternalInstance): any => ({ ...(ins as any).provides }); -export function CommandDialogProvider(parentInstance: ComponentInternalInstance | null, uiComponentVnode: Component, config: ICommandDialogProviderConfig): IConsumer { +export function CommandProvider(parentInstance: ComponentInternalInstance | null, uiComponentVnode: Component, config: ICommandDialogProviderConfig): IConsumer { const appendToElement = (typeof config.appendTo === "string" ? document.querySelector(config.appendTo) : config.appendTo) || document.body; const container = document.createElement("div"); container.className = "command-commponent-container" @@ -146,10 +146,10 @@ export function CommandDialogProvider(parentInstance: ComponentInternalInstance return consumer; } -export const getCommandDialogConsumer = (warn: boolean = true): IConsumer => { +export const getConsumer = (warn: boolean = true): IConsumer => { const showWarningMessage = () => warn && console.warn(`别调用了欧尼酱~,这会儿没啥实际用途;没有根据CommandDialogInjectKey接收到注入数据.原因可能有两个: - 1.你可能对getCommandDialogConsumer进行了异步调用或条件调用,请在setup中直接调用. + 1.你可能对getConsumer进行了异步调用或条件调用,请在setup中直接调用. 2.你没有在命令弹窗内展示该组件,这个时候你一般可以忽略该警告消息.`); return inject( @@ -160,3 +160,8 @@ export const getCommandDialogConsumer = (warn: boolean = true): IConsumer => { }), true )!; }; + +export const getCommandDialogConsumer = (...args: any) => { + console.warn("Warning: This API will be deprecated in the future, please use `getConsumer` instead."); + return getConsumer(...args); +}; diff --git a/src/components/ElementPlusDialog.tsx b/src/components/ElementPlusDialog.tsx index d055724..29ec037 100644 --- a/src/components/ElementPlusDialog.tsx +++ b/src/components/ElementPlusDialog.tsx @@ -1,8 +1,8 @@ -import { ElDialog, useGlobalComponentSettings, type DialogProps } from "element-plus"; +import { ElDialog, useGlobalComponentSettings, ElButton, type DialogProps } from "element-plus"; import type { VNode } from "vue"; import { getCurrentInstance, h, ref, defineComponent } from "vue"; import type { ICommandDialogArrtsProviderConfig } from "./Core"; -import { CommandDialogProvider } from "./Core"; +import { CommandProvider } from "./Core"; import { busName2EventName, eventName2BusName } from "./utils"; import { EVENT_NAME } from "./type"; @@ -45,7 +45,7 @@ export const createElementPlusDialog = (immediately = true) => { // 我们不再依赖外部的visible变量来控制弹窗的显示与隐藏,这免去了外部手动控制弹窗显示与隐藏的麻烦,而是通过consumer对象来进行控制 const visible = ref(immediately); // 这里的consumer和弹窗内部通过`inject`接收到的`consumer`是同一个对象 - const consumer = CommandDialogProvider( + const consumer = CommandProvider( parentInstance, h(defineComponent({ setup() { @@ -84,14 +84,14 @@ export const createElementPlusDialog = (immediately = true) => { footer: () => (
{config[busName2EventName(EVENT_NAME.cancel)] && ( - consumer.emit(EVENT_NAME.cancel)}> + consumer.emit(EVENT_NAME.cancel)}> {config.cancelBtnText || t('el.messagebox.cancel')} - + )} {config[busName2EventName(EVENT_NAME.confirm)] && ( - consumer.emit(EVENT_NAME.confirm)}> + consumer.emit(EVENT_NAME.confirm)}> {config.confirmBtnText || t('el.messagebox.confirm')} - + )}
), diff --git a/src/components/VantUiPopup.tsx b/src/components/VantUiPopup.tsx index 3873b80..33bc358 100644 --- a/src/components/VantUiPopup.tsx +++ b/src/components/VantUiPopup.tsx @@ -3,7 +3,7 @@ import { Popup } from 'vant' import type { VNode } from "vue"; import { getCurrentInstance, h, ref, defineComponent } from "vue"; import type { ICommandDialogArrtsProviderConfig } from "./Core"; -import { CommandDialogProvider } from "./Core"; +import { CommandProvider } from "./Core"; import { EVENT_NAME } from "./type"; import { merge } from "lodash-es"; @@ -38,7 +38,7 @@ export const createVantUiPopup = (immediately = true) => { const parentInstance = getCurrentInstance(); const commandDialog = (ContentVNode: VNode, config: IVantUiConfig = {}) => { const visible = ref(immediately); - const consumer = CommandDialogProvider( + const consumer = CommandProvider( parentInstance, h(defineComponent({ setup() { diff --git a/src/main.ts b/src/main.ts index af4683a..d490c84 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ app.provide("main", "来自main的🩷"); // 导入vant-popup弹窗样式 import("vant/es/popup/style"); -// 导入element-plus dialog弹窗样式 +// 导入element-plus 样式 import("element-plus/es/components/dialog/style/css"); app.use(router); diff --git a/src/pages/example/advance/communication.vue b/src/pages/example/advance/communication.vue index 8d0a480..1d0d794 100644 --- a/src/pages/example/advance/communication.vue +++ b/src/pages/example/advance/communication.vue @@ -1,5 +1,5 @@