naive-ui-x 0.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/dist/es/index.js +361 -0
- package/dist/js/naive-ui.esm.js +86055 -0
- package/dist/js/naive-ui.js +7620 -0
- package/dist/types/components/n-view-provider/n-view-provider.vue.d.ts +58 -0
- package/dist/types/components/n-view-provider/utils.d.ts +10 -0
- package/dist/types/lib/esm.d.ts +3 -0
- package/dist/types/lib/index.d.ts +3 -0
- package/dist/types/utils/NaiveComponents.d.ts +97 -0
- package/dist/types/utils/ViewEvent.d.ts +79 -0
- package/package.json +46 -0
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { ref as D, computed as g, defineComponent as z, onMounted as K, resolveComponent as S, createBlock as F, createCommentVNode as W, openBlock as q, unref as $, withCtx as E, createVNode as P, renderSlot as Q } from "vue";
|
|
2
|
+
import { dateZhCN as X, zhCN as Y, darkTheme as p, lightTheme as j, useNotification as G, useMessage as J, NConfigProvider as ee, NGlobalStyle as ne } from "naive-ui";
|
|
3
|
+
const C = "iframe", T = "window";
|
|
4
|
+
let A = null;
|
|
5
|
+
function re() {
|
|
6
|
+
if (A)
|
|
7
|
+
return A;
|
|
8
|
+
const e = /* @__PURE__ */ new Map();
|
|
9
|
+
let { windowInstance: t, mode: n } = window.opener ? {
|
|
10
|
+
windowInstance: window.opener,
|
|
11
|
+
mode: T
|
|
12
|
+
} : {
|
|
13
|
+
windowInstance: window.parent,
|
|
14
|
+
mode: C
|
|
15
|
+
};
|
|
16
|
+
function u() {
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
function o() {
|
|
20
|
+
return t !== window ? t : null;
|
|
21
|
+
}
|
|
22
|
+
function s() {
|
|
23
|
+
return n;
|
|
24
|
+
}
|
|
25
|
+
function w(i) {
|
|
26
|
+
if ((i == null ? void 0 : i.source) !== t)
|
|
27
|
+
return;
|
|
28
|
+
const { event: r, data: l } = i.data;
|
|
29
|
+
r && e.has(r) && e.get(r).forEach((c) => {
|
|
30
|
+
c.once && h(c);
|
|
31
|
+
try {
|
|
32
|
+
c.callback(l);
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function d(i, r, l = !1) {
|
|
38
|
+
e.has(i) || e.set(i, []);
|
|
39
|
+
const c = { event: i, callback: r, once: l };
|
|
40
|
+
return e.get(i).push(c), c;
|
|
41
|
+
}
|
|
42
|
+
function h(i) {
|
|
43
|
+
if (typeof i == "string")
|
|
44
|
+
return e.has(i) ? (e.delete(i), !0) : !1;
|
|
45
|
+
if (e.has(i.event)) {
|
|
46
|
+
const r = e.get(i.event).indexOf(i);
|
|
47
|
+
if (r !== -1)
|
|
48
|
+
return e.get(i.event).splice(r, 1), !0;
|
|
49
|
+
}
|
|
50
|
+
return !1;
|
|
51
|
+
}
|
|
52
|
+
function m(i, r) {
|
|
53
|
+
return d(i, r, !0);
|
|
54
|
+
}
|
|
55
|
+
function _(i, r = null) {
|
|
56
|
+
return !t || t === window ? !1 : (r && V(r) && (r = y(r)), t.postMessage({ event: i, data: r }, "*"), !0);
|
|
57
|
+
}
|
|
58
|
+
function N(i, r) {
|
|
59
|
+
return d(i, ({ event: l, data: c }) => {
|
|
60
|
+
if (r.constructor.name === "AsyncFunction")
|
|
61
|
+
r(c).then((a) => {
|
|
62
|
+
a && V(a) && (a = y(a)), _(l, { _data: a, error: null });
|
|
63
|
+
}).catch((a) => {
|
|
64
|
+
_(l, { data: null, error: a });
|
|
65
|
+
});
|
|
66
|
+
else
|
|
67
|
+
try {
|
|
68
|
+
let a = r(c);
|
|
69
|
+
a && V(a) && (a = y(a)), _(l, {
|
|
70
|
+
data: a,
|
|
71
|
+
error: null
|
|
72
|
+
});
|
|
73
|
+
} catch (a) {
|
|
74
|
+
_(l, { data: null, error: a });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function f(i, r = null, l = 5e3, c = 100) {
|
|
79
|
+
if ((!l || l <= 0) && (l = 5e3), (!l || l <= 0) && (l = 5e3), (!c || c < 0) && (c = 100), !t || t === window)
|
|
80
|
+
return Promise.reject("No window instance");
|
|
81
|
+
r && V(r) && (r = y(r));
|
|
82
|
+
const a = Date.now(), Z = Math.random().toString(), b = `callback_event_${i}${a}_${Z}`;
|
|
83
|
+
t.postMessage({ event: i, data: { event: b, data: r } }, "*");
|
|
84
|
+
let k = "__null__", x = null;
|
|
85
|
+
d(b, ({ data: B, error: M }) => {
|
|
86
|
+
k = B, x = M;
|
|
87
|
+
}, !0);
|
|
88
|
+
const H = Date.now() + l;
|
|
89
|
+
return new Promise((B, M) => {
|
|
90
|
+
const U = setInterval(() => {
|
|
91
|
+
x ? (clearInterval(U), M(x)) : k !== "__null__" ? (clearInterval(U), B(k)) : Date.now() >= H && (clearInterval(U), M("Call timed out " + l + "ms"));
|
|
92
|
+
}, c);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function O(i) {
|
|
96
|
+
let r = null, l = null;
|
|
97
|
+
return n === T && (i.constructor.name === "AsyncFunction" ? r = async function(c) {
|
|
98
|
+
const a = await i();
|
|
99
|
+
if (a)
|
|
100
|
+
return c.preventDefault(), c.returnValue = a, a;
|
|
101
|
+
} : r = function(c) {
|
|
102
|
+
try {
|
|
103
|
+
const a = i();
|
|
104
|
+
if (a)
|
|
105
|
+
return c.preventDefault(), c.returnValue = a, a;
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}, l = function() {
|
|
109
|
+
n === T && window.history.length === 2 && (window.history.pushState({}, "", ""), I());
|
|
110
|
+
}, window.history.pushState({}, "", ""), window.addEventListener("popstate", l), window.addEventListener("beforeunload", r)), n === C && (r = N("close", i)), () => {
|
|
111
|
+
n === T && r && window.removeEventListener("beforeunload", r), n === C && r && h(r), l && window.removeEventListener("popstate", l);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
let v = null;
|
|
115
|
+
function I(i = 300) {
|
|
116
|
+
v && (clearTimeout(v), v = null), v = setTimeout(() => {
|
|
117
|
+
n === T && window.close(), n === C && _("onClose"), v = null;
|
|
118
|
+
}, i);
|
|
119
|
+
}
|
|
120
|
+
function R() {
|
|
121
|
+
window.removeEventListener("message", w), A = null, e != null && e.clear && e.clear();
|
|
122
|
+
}
|
|
123
|
+
return window.addEventListener("message", w), A = { on: d, ononce: m, onclose: O, off: h, emit: _, register: N, call: f, close: I, destroy: R, getWindow: u, getMode: s, getParent: o }, A;
|
|
124
|
+
}
|
|
125
|
+
function V(e) {
|
|
126
|
+
return typeof e != "object" ? !1 : (e == null ? void 0 : e.__v_raw) !== void 0 || (e == null ? void 0 : e.__v_isRef) !== void 0 || (e == null ? void 0 : e.__v_isShallow) !== void 0 || (e == null ? void 0 : e.__v_isReadonly) !== void 0 || (e == null ? void 0 : e.__ob__) !== void 0;
|
|
127
|
+
}
|
|
128
|
+
function y(e) {
|
|
129
|
+
if (e === null || typeof e != "object")
|
|
130
|
+
return e;
|
|
131
|
+
let t;
|
|
132
|
+
if (Array.isArray(e)) {
|
|
133
|
+
t = [];
|
|
134
|
+
for (let n = 0, u = e.length; n < u; n++)
|
|
135
|
+
t[n] = y(e[n]);
|
|
136
|
+
} else {
|
|
137
|
+
t = {};
|
|
138
|
+
for (let n in e)
|
|
139
|
+
e.hasOwnProperty(n) && (t[n] = y(e[n]));
|
|
140
|
+
}
|
|
141
|
+
return t;
|
|
142
|
+
}
|
|
143
|
+
const L = re();
|
|
144
|
+
function te() {
|
|
145
|
+
return L;
|
|
146
|
+
}
|
|
147
|
+
function ue(e = 100, t = 200) {
|
|
148
|
+
e < 0 && (e = 100);
|
|
149
|
+
let n = !0;
|
|
150
|
+
const u = D(!1);
|
|
151
|
+
L.getParent() && (u.value = !0);
|
|
152
|
+
const o = () => {
|
|
153
|
+
n && setTimeout(() => {
|
|
154
|
+
L.call("online", null, t, e).then((w) => {
|
|
155
|
+
u.value = !!w;
|
|
156
|
+
}).catch(() => {
|
|
157
|
+
u.value = !1;
|
|
158
|
+
}).finally(() => {
|
|
159
|
+
o();
|
|
160
|
+
});
|
|
161
|
+
}, e);
|
|
162
|
+
}, s = () => {
|
|
163
|
+
n = !1;
|
|
164
|
+
};
|
|
165
|
+
return o(), {
|
|
166
|
+
status: g(() => u.value),
|
|
167
|
+
stop: s
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async function ce(e = null, t = {}) {
|
|
171
|
+
const n = new URLSearchParams(window.location.search), u = new URLSearchParams(t);
|
|
172
|
+
n.has("_token") && u.append("_token", n.get("_token"));
|
|
173
|
+
try {
|
|
174
|
+
const o = await L.call("getRequestBaseURL", e);
|
|
175
|
+
return u.size > 0 ? o + "?" + u.toString() : o;
|
|
176
|
+
} catch {
|
|
177
|
+
return u.size > 0 ? e + "?" + u.toString() : e;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function fe(e) {
|
|
181
|
+
var t, n;
|
|
182
|
+
if (window.opener) {
|
|
183
|
+
if ((e == null ? void 0 : e.duration) === 0)
|
|
184
|
+
return;
|
|
185
|
+
if ((!(e != null && e.duration) || (e == null ? void 0 : e.duration) <= 0) && (e.duration = 2e3), !(e != null && e.type)) {
|
|
186
|
+
if (!((t = window == null ? void 0 : window.naive) != null && t.message)) {
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
window.naive.message.destroyAll();
|
|
189
|
+
}, 100);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
window.naive.message.destroyAll();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (e.type !== "info" && e.type !== "warning" && e.type !== "error" && e.type !== "success")
|
|
196
|
+
return;
|
|
197
|
+
try {
|
|
198
|
+
if (!((n = window == null ? void 0 : window.naive) != null && n.message)) {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
window.naive.message.create((e == null ? void 0 : e.content) || null, e);
|
|
201
|
+
}, 100);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
window.naive.message.create((e == null ? void 0 : e.content) || null, e);
|
|
205
|
+
} catch {
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
L.call("message", e).then((u) => {
|
|
210
|
+
}).catch((u) => {
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function oe(e) {
|
|
214
|
+
var t, n;
|
|
215
|
+
if (window.opener) {
|
|
216
|
+
if ((e == null ? void 0 : e.duration) === 0)
|
|
217
|
+
return;
|
|
218
|
+
if ((!(e != null && e.duration) || (e == null ? void 0 : e.duration) <= 0) && (e.duration = 5e3), !(e != null && e.type)) {
|
|
219
|
+
if (!((t = window == null ? void 0 : window.naive) != null && t.notification)) {
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
window.naive.notification.destroyAll();
|
|
222
|
+
}, 100);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
window.naive.notification.destroyAll();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (e.type !== "info" && e.type !== "warning" && e.type !== "error" && e.type !== "success")
|
|
229
|
+
return;
|
|
230
|
+
try {
|
|
231
|
+
if (!((n = window == null ? void 0 : window.naive) != null && n.notification)) {
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
window.naive.notification.create((e == null ? void 0 : e.content) || null, e);
|
|
234
|
+
}, 100);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
window.naive.notification.create((e == null ? void 0 : e.content) || null, e);
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
L.call("notification", e).then(() => {
|
|
243
|
+
}).catch(() => {
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function se(e) {
|
|
247
|
+
return y(e);
|
|
248
|
+
}
|
|
249
|
+
function ie(e, t) {
|
|
250
|
+
return Object.keys(t).forEach((n) => {
|
|
251
|
+
t[n] && typeof t[n] == "object" && !Array.isArray(t[n]) ? (e[n] || (e[n] = Array.isArray(t[n]) ? [] : {}), ie(e[n], t[n])) : e[n] = t[n];
|
|
252
|
+
}), e;
|
|
253
|
+
}
|
|
254
|
+
const de = /* @__PURE__ */ z({
|
|
255
|
+
__name: "n-view-provider",
|
|
256
|
+
props: {
|
|
257
|
+
locale: { default: Y },
|
|
258
|
+
dateLocale: { default: X },
|
|
259
|
+
breakpoints: { default: null }
|
|
260
|
+
},
|
|
261
|
+
emits: ["init", "theme"],
|
|
262
|
+
setup(e, { emit: t }) {
|
|
263
|
+
const n = e, u = t, o = g(() => window.opener ? "window" : "iframe"), s = D("light"), w = D(!0), d = te(), h = g(() => s.value === "dark" ? p : j), m = D({});
|
|
264
|
+
d.on("onTheme", (f) => {
|
|
265
|
+
s.value = f.name, m.value = f.overrides, u("theme", {
|
|
266
|
+
mode: o,
|
|
267
|
+
view: d,
|
|
268
|
+
theme_style: h,
|
|
269
|
+
theme_name: g(() => s.value),
|
|
270
|
+
theme_overrides: g(() => m.value)
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
const _ = z({
|
|
274
|
+
name: "NPreViewProvider",
|
|
275
|
+
setup() {
|
|
276
|
+
return window.naive ? (window.naive.message = J(), window.naive.notification = G()) : window.naive = {
|
|
277
|
+
message: J(),
|
|
278
|
+
notification: G()
|
|
279
|
+
}, {};
|
|
280
|
+
},
|
|
281
|
+
render() {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
function N() {
|
|
286
|
+
s.value = window.localStorage.getItem("theme") || "light";
|
|
287
|
+
let f = window.localStorage.getItem("themeOverrides");
|
|
288
|
+
if (f)
|
|
289
|
+
try {
|
|
290
|
+
m.value = JSON.parse(f);
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
w.value = !1;
|
|
294
|
+
}
|
|
295
|
+
return K(() => {
|
|
296
|
+
d.getParent() ? d.call("getTheme", null, 500).then((f) => {
|
|
297
|
+
s.value = f.name, m.value = f.overrides, w.value = !1;
|
|
298
|
+
}).catch((f) => {
|
|
299
|
+
N();
|
|
300
|
+
}) : N(), u("init", {
|
|
301
|
+
mode: o,
|
|
302
|
+
view: d,
|
|
303
|
+
theme_style: h,
|
|
304
|
+
theme_name: g(() => s.value),
|
|
305
|
+
theme_overrides: g(() => m.value)
|
|
306
|
+
});
|
|
307
|
+
}), (f, O) => {
|
|
308
|
+
const v = S("n-dialog-provider"), I = S("n-modal-provider"), R = S("n-notification-provider"), i = S("n-message-provider"), r = S("n-el");
|
|
309
|
+
return w.value ? W("", !0) : (q(), F($(ee), {
|
|
310
|
+
key: 0,
|
|
311
|
+
theme: h.value,
|
|
312
|
+
"theme-overrides": m.value,
|
|
313
|
+
locale: n.locale,
|
|
314
|
+
"date-locale": n.dateLocale,
|
|
315
|
+
breakpoints: n.breakpoints
|
|
316
|
+
}, {
|
|
317
|
+
default: E(() => [
|
|
318
|
+
o.value == "window" ? (q(), F($(ne), { key: 0 })) : W("", !0),
|
|
319
|
+
P(r, null, {
|
|
320
|
+
default: E(() => [
|
|
321
|
+
P(i, null, {
|
|
322
|
+
default: E(() => [
|
|
323
|
+
P(R, null, {
|
|
324
|
+
default: E(() => [
|
|
325
|
+
P(I, null, {
|
|
326
|
+
default: E(() => [
|
|
327
|
+
P(v, null, {
|
|
328
|
+
default: E(() => [
|
|
329
|
+
P($(_)),
|
|
330
|
+
Q(f.$slots, "default")
|
|
331
|
+
]),
|
|
332
|
+
_: 3
|
|
333
|
+
})
|
|
334
|
+
]),
|
|
335
|
+
_: 3
|
|
336
|
+
})
|
|
337
|
+
]),
|
|
338
|
+
_: 3
|
|
339
|
+
})
|
|
340
|
+
]),
|
|
341
|
+
_: 3
|
|
342
|
+
})
|
|
343
|
+
]),
|
|
344
|
+
_: 3
|
|
345
|
+
})
|
|
346
|
+
]),
|
|
347
|
+
_: 3
|
|
348
|
+
}, 8, ["theme", "theme-overrides", "locale", "date-locale", "breakpoints"]));
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
export {
|
|
353
|
+
de as NViewProvider,
|
|
354
|
+
se as deepClone,
|
|
355
|
+
ie as deepMerge,
|
|
356
|
+
ce as getRequestBaseURL,
|
|
357
|
+
fe as message,
|
|
358
|
+
oe as notification,
|
|
359
|
+
ue as useOnline,
|
|
360
|
+
te as useViewEvent
|
|
361
|
+
};
|