vane-waterfall 2.0.0 → 2.0.2
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 +6 -6
- package/dist/chunks/WaterfallCore-EdAZuWAY.js +695 -0
- package/dist/chunks/{doc-kTbJE7rY.js → doc-BCmEnh39.js} +31 -29
- package/dist/chunks/doc-BQQoKNto.js +126 -0
- package/dist/chunks/{doc-j4W9SUrY.js → doc-BSnWbrkH.js} +39 -27
- package/dist/chunks/{doc-BCGQ8Cp5.js → doc-BXaJl1By.js} +54 -41
- package/dist/chunks/{doc-CraXjOaA.js → doc-BindRMfO.js} +30 -26
- package/dist/chunks/{doc-78xF08vt.js → doc-BmoijI6q.js} +35 -35
- package/dist/chunks/{doc-BtzhgTYj.js → doc-CN4edvn_.js} +27 -27
- package/dist/chunks/{doc-NhL4Ux8q.js → doc-CkU5GtLw.js} +65 -54
- package/dist/chunks/doc-DAieSXLy.js +86 -0
- package/dist/chunks/{doc-BP0DmB7-.js → doc-D_ozEn0Q.js} +27 -27
- package/dist/chunks/{doc-f4Uijujv.js → doc-KN6Bvmty.js} +54 -32
- package/dist/chunks/{doc-B6kLfMPv.js → doc-a0MK2S3n.js} +61 -40
- package/dist/chunks/{index-COaun3nf.js → index-B8o6R4RZ.js} +2 -2
- package/dist/chunks/{index-DXAtA2f6.js → index-BFyYpEY_.js} +2 -2
- package/dist/chunks/{index-wLI6UXkY.js → index-CF0tYRop.js} +1 -1
- package/dist/chunks/{index-gjoCq0yC.js → index-CJR0Buju.js} +4 -4
- package/dist/chunks/{index-DsRLmBW-.js → index-DHTB3QEP.js} +3 -3
- package/dist/chunks/withPlugins-DG3YpSgL.js +655 -0
- package/dist/components/WaterfallPlugin/WaterfallCore.d.ts +19 -0
- package/dist/components/WaterfallPlugin/WaterfallCore.d.ts.map +1 -1
- package/dist/components/WaterfallPlugin/layout.d.ts +7 -0
- package/dist/components/WaterfallPlugin/layout.d.ts.map +1 -1
- package/dist/components/WaterfallPlugin/plugins/types.d.ts +4 -1
- package/dist/components/WaterfallPlugin/plugins/types.d.ts.map +1 -1
- package/dist/components/WaterfallPlugin/withPlugins.d.ts.map +1 -1
- package/dist/custom-plugins/A11yPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/A11yPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/A11yPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/A11yPlugin/index.js +1 -1
- package/dist/custom-plugins/AlignmentPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/AlignmentPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/AutoColumnPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/AutoColumnPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/BookmarkPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/BookmarkPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/BookmarkPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/BookmarkPlugin/index.js +1 -1
- package/dist/custom-plugins/ClickAnalyticsPlugin/create.d.ts +2 -0
- package/dist/custom-plugins/ClickAnalyticsPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/ClickAnalyticsPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/ClickAnalyticsPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/ClickAnalyticsPlugin/index.js +1 -1
- package/dist/custom-plugins/DebounceLayoutPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/DebounceLayoutPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/DragReorderPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/DragReorderPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/FilterPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/FilterPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/FixedHeightPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/FixedHeightPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/GapPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/GapPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/GapPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/GapPlugin/index.js +1 -1
- package/dist/custom-plugins/GroupingPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/GroupingPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/GroupingPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/GroupingPlugin/index.js +1 -1
- package/dist/custom-plugins/HeatmapAnalyticsPlugin/create.d.ts +2 -0
- package/dist/custom-plugins/HeatmapAnalyticsPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/HeatmapAnalyticsPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/HeatmapAnalyticsPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/HeatmapAnalyticsPlugin/index.js +1 -1
- package/dist/custom-plugins/InfiniteScrollPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/InfiniteScrollPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/InfiniteScrollPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/InfiniteScrollPlugin/index.js +1 -1
- package/dist/custom-plugins/PaginationPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/PaginationPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/PaginationPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/PaginationPlugin/index.js +1 -1
- package/dist/custom-plugins/PinItemPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/PinItemPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/RecyclePlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/RecyclePlugin/index.d.ts +1 -1
- package/dist/custom-plugins/RecyclePlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/RecyclePlugin/index.js +1 -1
- package/dist/custom-plugins/ReducedMotionPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/ReducedMotionPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/ResponsiveColumnsPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/ResponsiveColumnsPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/ScrollAnchorPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/ScrollAnchorPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/SearchPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/SearchPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/SortPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/SortPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/StatePersistencePlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/StatePersistencePlugin/index.d.ts +1 -1
- package/dist/custom-plugins/StatePersistencePlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/StatePersistencePlugin/index.js +1 -1
- package/dist/custom-plugins/StickyHeaderPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/StickyHeaderPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/StickyHeaderPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/StickyHeaderPlugin/index.js +1 -1
- package/dist/custom-plugins/ThrottlePlugin/index.d.ts +1 -1
- package/dist/custom-plugins/ThrottlePlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/TransitionPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/TransitionPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/URLSyncPlugin/create.d.ts.map +1 -1
- package/dist/custom-plugins/URLSyncPlugin/index.d.ts +1 -1
- package/dist/custom-plugins/URLSyncPlugin/index.d.ts.map +1 -1
- package/dist/custom-plugins/URLSyncPlugin/index.js +1 -1
- package/dist/custom-plugins/index.js +5 -5
- package/dist/entries/core.js +1 -1
- package/dist/entries/plugins.d.ts +1 -1
- package/dist/entries/plugins.d.ts.map +1 -1
- package/dist/entries/plugins.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/presets/dashboard/index.js +2 -2
- package/dist/presets/photo-feed/index.js +2 -2
- package/dist/presets/product-feed/index.js +1 -1
- package/package.json +32 -25
- package/dist/chunks/WaterfallCore-BSXw7bl_.js +0 -581
- package/dist/chunks/doc-B-7dugGv.js +0 -79
- package/dist/chunks/doc-DJjxOYzW.js +0 -111
- package/dist/chunks/withPlugins-DLoKg4AP.js +0 -559
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
function L(i = {}) {
|
|
2
|
-
const h = i.mode || "hash", r = i.keys || ["pageIndex", "pageSize", "searchQuery"];
|
|
3
|
-
function l() {
|
|
4
|
-
try {
|
|
5
|
-
if (h === "hash") {
|
|
6
|
-
const s = window.location.hash || "", t = s.indexOf("?"), a = t >= 0 ? s.slice(t + 1) : s.replace(/^#/, ""), e = new URLSearchParams(a), n = {};
|
|
7
|
-
return r.forEach((c) => {
|
|
8
|
-
const o = e.get(c);
|
|
9
|
-
o !== null && (n[c] = o);
|
|
10
|
-
}), n;
|
|
11
|
-
} else {
|
|
12
|
-
const s = new URLSearchParams(window.location.search), t = {};
|
|
13
|
-
return r.forEach((a) => {
|
|
14
|
-
const e = s.get(a);
|
|
15
|
-
e !== null && (t[a] = e);
|
|
16
|
-
}), t;
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function p(s) {
|
|
23
|
-
try {
|
|
24
|
-
const t = new URLSearchParams();
|
|
25
|
-
r.forEach((e) => {
|
|
26
|
-
const n = s[e];
|
|
27
|
-
n != null && String(n).length > 0 && t.set(e, String(n));
|
|
28
|
-
});
|
|
29
|
-
const a = t.toString();
|
|
30
|
-
if (h === "hash") {
|
|
31
|
-
const e = window.location.hash || "", o = `#${e.replace(/^#/, "").split("?")[0] || ""}${a ? `?${a}` : ""}`;
|
|
32
|
-
e !== o && history.replaceState(
|
|
33
|
-
null,
|
|
34
|
-
"",
|
|
35
|
-
`${window.location.pathname}${window.location.search}${o}`
|
|
36
|
-
);
|
|
37
|
-
} else {
|
|
38
|
-
const n = window.location.pathname + (a ? `?${a}` : "") + (window.location.hash || "");
|
|
39
|
-
history.replaceState(null, "", n);
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
name: "URLSyncPlugin",
|
|
46
|
-
enabled: !0,
|
|
47
|
-
hooks: {
|
|
48
|
-
onMount: (s) => {
|
|
49
|
-
const t = l();
|
|
50
|
-
s.bus?.emit("urlsync:init", t);
|
|
51
|
-
},
|
|
52
|
-
onPropsChange: (s, t, a) => {
|
|
53
|
-
const e = {}, n = a ?? {};
|
|
54
|
-
r.forEach((c) => {
|
|
55
|
-
const o = n[c];
|
|
56
|
-
o !== void 0 && (e[c] = o);
|
|
57
|
-
}), p(e);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const u = "URLSyncPlugin", d = "props 变化时把指定键写进 URL(hash 或 search),挂载时读出来广播 `urlsync:init`。刷新与分享都能还原筛选状态。", m = "2.0.0", w = [
|
|
63
|
-
"ui",
|
|
64
|
-
"URL",
|
|
65
|
-
"可分享"
|
|
66
|
-
], f = [
|
|
67
|
-
{
|
|
68
|
-
name: "mode",
|
|
69
|
-
type: '"hash" | "search"',
|
|
70
|
-
default: '"hash"',
|
|
71
|
-
description: "写 hash 还是 search"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "keys",
|
|
75
|
-
type: "string[]",
|
|
76
|
-
default: '["pageIndex","pageSize","searchQuery"]',
|
|
77
|
-
description: "要同步的 props 键"
|
|
78
|
-
}
|
|
79
|
-
], g = `// 把分页/搜索/排序同步进 URL(hash 或 search),链接可分享。
|
|
80
|
-
const Waterfall = withPlugins(WaterfallCore, [
|
|
81
|
-
createURLSyncPlugin({
|
|
82
|
-
mode: "hash",
|
|
83
|
-
keys: ["pageIndex","pageSize","searchQuery"],
|
|
84
|
-
}),
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
<Waterfall items={items} renderItem={(item) => <Card data={item} />} />;`, S = [
|
|
88
|
-
"hash 模式会保留已有路由路径",
|
|
89
|
-
"用 replaceState,不污染后退栈",
|
|
90
|
-
"SSR 安全:无 window 时直接跳过"
|
|
91
|
-
], y = [
|
|
92
|
-
"搜索结果可分享",
|
|
93
|
-
"后台筛选状态可刷新",
|
|
94
|
-
"带参数的深链"
|
|
95
|
-
], R = [
|
|
96
|
-
"只做单向同步(props → URL)与初始读取;URL 前进后退的监听请页面自己做。"
|
|
97
|
-
], U = {
|
|
98
|
-
name: u,
|
|
99
|
-
description: d,
|
|
100
|
-
since: m,
|
|
101
|
-
tags: w,
|
|
102
|
-
config: f,
|
|
103
|
-
example: g,
|
|
104
|
-
features: S,
|
|
105
|
-
useCases: y,
|
|
106
|
-
notes: R
|
|
107
|
-
};
|
|
108
|
-
export {
|
|
109
|
-
L as c,
|
|
110
|
-
U as d
|
|
111
|
-
};
|
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
import { jsxs as le, Fragment as ce, jsx as q } from "react/jsx-runtime";
|
|
2
|
-
import ue, { useRef as M, useState as A, useCallback as C, useMemo as z, useLayoutEffect as X, createContext as fe, forwardRef as ge, useEffect as J } from "react";
|
|
3
|
-
function me() {
|
|
4
|
-
const i = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), c = (e, o) => {
|
|
5
|
-
const s = i.get(e);
|
|
6
|
-
if (s)
|
|
7
|
-
for (const r of [...s])
|
|
8
|
-
try {
|
|
9
|
-
r(o);
|
|
10
|
-
} catch (a) {
|
|
11
|
-
console.warn(`[PluginBus] handler error for event "${e}"`, a);
|
|
12
|
-
}
|
|
13
|
-
}, g = (e, o) => {
|
|
14
|
-
let s = i.get(e);
|
|
15
|
-
return s || (s = /* @__PURE__ */ new Set(), i.set(e, s)), s.add(o), () => {
|
|
16
|
-
s?.delete(o);
|
|
17
|
-
};
|
|
18
|
-
}, m = (e, o) => {
|
|
19
|
-
const s = (r) => {
|
|
20
|
-
o(r), l(e, s);
|
|
21
|
-
};
|
|
22
|
-
return g(e, s);
|
|
23
|
-
}, l = (e, o) => {
|
|
24
|
-
if (!o) {
|
|
25
|
-
i.delete(e);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
i.get(e)?.delete(o);
|
|
29
|
-
};
|
|
30
|
-
return { emit: c, on: g, once: m, off: l, getData: (e) => t.get(e), setData: (e, o) => {
|
|
31
|
-
const s = t.get(e);
|
|
32
|
-
t.set(e, o), s !== o && c(e, o);
|
|
33
|
-
}, deleteData: (e) => {
|
|
34
|
-
const o = t.has(e);
|
|
35
|
-
t.delete(e), o && c(e, void 0);
|
|
36
|
-
}, hasData: (e) => t.has(e), getAll: () => {
|
|
37
|
-
const e = {};
|
|
38
|
-
return t.forEach((o, s) => {
|
|
39
|
-
e[s] = o;
|
|
40
|
-
}), e;
|
|
41
|
-
}, clear: () => {
|
|
42
|
-
i.clear(), t.clear();
|
|
43
|
-
} };
|
|
44
|
-
}
|
|
45
|
-
function ee(i) {
|
|
46
|
-
const t = new Map(i.map((o) => [o.name, o])), c = [];
|
|
47
|
-
for (const o of i)
|
|
48
|
-
for (const s of o.dependencies ?? [])
|
|
49
|
-
t.has(s) || c.push(`${o.name} -> ${s}`);
|
|
50
|
-
const g = [], m = /* @__PURE__ */ new Set(), l = [...i], e = (o) => (o.dependencies ?? []).every((s) => m.has(s) || !t.has(s));
|
|
51
|
-
for (; l.length > 0; ) {
|
|
52
|
-
const o = l.filter(e);
|
|
53
|
-
if (o.length === 0)
|
|
54
|
-
throw new Error(
|
|
55
|
-
`[vane/plugin-core] 插件循环依赖: ${l.map((r) => r.name).join(" <-> ")}`
|
|
56
|
-
);
|
|
57
|
-
let s = o[0];
|
|
58
|
-
for (const r of o)
|
|
59
|
-
(r.priority ?? 0) > (s.priority ?? 0) && (s = r);
|
|
60
|
-
g.push(s), m.add(s.name), l.splice(l.indexOf(s), 1);
|
|
61
|
-
}
|
|
62
|
-
return c.length > 0 && console.warn(
|
|
63
|
-
`[vane/plugin-core] 以下插件依赖未注册,将被忽略:
|
|
64
|
-
${c.join(`
|
|
65
|
-
`)}`
|
|
66
|
-
), g;
|
|
67
|
-
}
|
|
68
|
-
async function de(i, t = {}) {
|
|
69
|
-
const { timeout: c = 3e3, name: g = "anonymous", hook: m = "unknown" } = t;
|
|
70
|
-
if (!c || c <= 0)
|
|
71
|
-
return await i();
|
|
72
|
-
let l;
|
|
73
|
-
const e = new Promise((o, s) => {
|
|
74
|
-
l = setTimeout(() => {
|
|
75
|
-
s(new Error(`[vane/plugin-core] 插件 ${g} 的钩子 ${m} 超时(${c}ms)`));
|
|
76
|
-
}, c);
|
|
77
|
-
});
|
|
78
|
-
try {
|
|
79
|
-
return await Promise.race([Promise.resolve().then(i), e]);
|
|
80
|
-
} finally {
|
|
81
|
-
l && clearTimeout(l);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const he = /* @__PURE__ */ new Set(["onMount", "onUnmount", "onPropsChange", "onError"]);
|
|
85
|
-
function pe(i = {}) {
|
|
86
|
-
const t = i.logger ?? console, c = i.sandbox ?? !0, g = i.timeout ?? 3e3, m = [], l = [], e = /* @__PURE__ */ new Map(), o = () => ee([...e.values()].filter((r) => r.enabled !== !1)), s = (r) => {
|
|
87
|
-
e.set(r.name, { ...r, enabled: r.enabled ?? !0 }), r.init && Promise.resolve(r.init()).catch((a) => {
|
|
88
|
-
t.warn(`[PluginManager] init failed for ${r.name}`, a);
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
register: s,
|
|
93
|
-
registerAll: (r) => {
|
|
94
|
-
for (const a of r) s(a);
|
|
95
|
-
},
|
|
96
|
-
unregister: (r) => {
|
|
97
|
-
const a = e.get(r);
|
|
98
|
-
a && (a.destroy && Promise.resolve(a.destroy()).catch((b) => {
|
|
99
|
-
t.warn(`[PluginManager] destroy failed for ${a.name}`, b);
|
|
100
|
-
}), e.delete(r));
|
|
101
|
-
},
|
|
102
|
-
getPlugin: (r) => e.get(r),
|
|
103
|
-
getAllPlugins: () => [...e.values()],
|
|
104
|
-
getEnabledPlugins: () => [...e.values()].filter((r) => r.enabled !== !1),
|
|
105
|
-
getExecutionOrder: o,
|
|
106
|
-
enable: (r) => {
|
|
107
|
-
const a = e.get(r);
|
|
108
|
-
a && (a.enabled = !0);
|
|
109
|
-
},
|
|
110
|
-
disable: (r) => {
|
|
111
|
-
const a = e.get(r);
|
|
112
|
-
a && (a.enabled = !1);
|
|
113
|
-
},
|
|
114
|
-
has: (r) => e.has(r),
|
|
115
|
-
executeHook: async (r, a, ...b) => {
|
|
116
|
-
for (const p of o()) {
|
|
117
|
-
const R = p.hooks?.[r];
|
|
118
|
-
if (typeof R != "function") continue;
|
|
119
|
-
const $ = p.sandbox ?? c, N = p.timeout ?? g;
|
|
120
|
-
let k;
|
|
121
|
-
try {
|
|
122
|
-
k = $ ? await de(
|
|
123
|
-
() => R(a, ...b),
|
|
124
|
-
{ timeout: N, name: p.name, hook: String(r) }
|
|
125
|
-
) : await R(a, ...b);
|
|
126
|
-
} catch (W) {
|
|
127
|
-
if (m.push({ plugin: p.name, hook: String(r), error: W }), t.warn(
|
|
128
|
-
`[PluginManager] hook ${String(r)} failed in ${p.name}`,
|
|
129
|
-
W
|
|
130
|
-
), i.onError?.(p.name, String(r), W), r === "onError") break;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (he.has(String(r)) && typeof k == "function") {
|
|
134
|
-
l.push(k);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (k === !1) return !1;
|
|
138
|
-
if (k !== void 0 && k !== !0) return k;
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
clear: () => {
|
|
142
|
-
const r = l.splice(0);
|
|
143
|
-
for (const a of r.reverse())
|
|
144
|
-
try {
|
|
145
|
-
a();
|
|
146
|
-
} catch (b) {
|
|
147
|
-
t.warn("[PluginManager] cleanup failed", b);
|
|
148
|
-
}
|
|
149
|
-
for (const a of e.values())
|
|
150
|
-
a.destroy && Promise.resolve(a.destroy()).catch((b) => {
|
|
151
|
-
t.warn(`[PluginManager] destroy failed for ${a.name}`, b);
|
|
152
|
-
});
|
|
153
|
-
e.clear();
|
|
154
|
-
},
|
|
155
|
-
getErrors: () => [...m]
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
var we = Object.defineProperty, ye = (i, t, c) => t in i ? we(i, t, { enumerable: !0, configurable: !0, writable: !0, value: c }) : i[t] = c, ve = (i, t, c) => ye(i, t + "", c);
|
|
159
|
-
class te extends ue.Component {
|
|
160
|
-
constructor() {
|
|
161
|
-
super(...arguments), ve(this, "state", { error: null });
|
|
162
|
-
}
|
|
163
|
-
static getDerivedStateFromError(t) {
|
|
164
|
-
return { error: t };
|
|
165
|
-
}
|
|
166
|
-
componentDidCatch(t, c) {
|
|
167
|
-
console.warn("[vane/plugin-core] 插件渲染错误已被隔离", t, c), this.props.onError?.(t, c);
|
|
168
|
-
}
|
|
169
|
-
render() {
|
|
170
|
-
const { error: t } = this.state;
|
|
171
|
-
return t ? this.props.fallback ? this.props.fallback(t) : null : this.props.children;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
let Y = null;
|
|
175
|
-
function Pe(i = !1) {
|
|
176
|
-
if (Y && !i) return Y;
|
|
177
|
-
const t = typeof window < "u" ? window.innerWidth : 1024, c = typeof window < "u" ? window.innerHeight : 768, g = typeof window < "u" && window.devicePixelRatio || 1, m = typeof navigator < "u" && navigator.userAgent || "", l = /iPad|Tablet/i.test(m), e = /Mobile|Android|iPhone/i.test(m), o = typeof window < "u" && ("ontouchstart" in window || (navigator.maxTouchPoints ?? 0) > 0);
|
|
178
|
-
return Y = {
|
|
179
|
-
type: l ? "tablet" : e ? "mobile" : "desktop",
|
|
180
|
-
os: m,
|
|
181
|
-
browser: m,
|
|
182
|
-
devicePixelRatio: g,
|
|
183
|
-
viewportWidth: t,
|
|
184
|
-
viewportHeight: c,
|
|
185
|
-
isTouchDevice: o,
|
|
186
|
-
isRetina: g >= 2
|
|
187
|
-
}, Y;
|
|
188
|
-
}
|
|
189
|
-
function Ie(i) {
|
|
190
|
-
const {
|
|
191
|
-
plugins: t,
|
|
192
|
-
props: c,
|
|
193
|
-
data: g,
|
|
194
|
-
initialState: m,
|
|
195
|
-
containerRef: l,
|
|
196
|
-
enableDebug: e = !1,
|
|
197
|
-
managerOptions: o,
|
|
198
|
-
extendContext: s
|
|
199
|
-
} = i, r = M(null), a = l ?? r, b = M(null);
|
|
200
|
-
b.current || (b.current = pe(o));
|
|
201
|
-
const p = b.current, R = M(null);
|
|
202
|
-
R.current || (R.current = me());
|
|
203
|
-
const $ = R.current, N = M(/* @__PURE__ */ new Map()), [k, W] = A(m ?? {}), [, K] = A(0), U = C(() => K((I) => I + 1), []), O = z(() => Pe(), []), D = t.map((I) => I.name).join("|");
|
|
204
|
-
X(() => {
|
|
205
|
-
p.clear(), p.registerAll(t), e && console.debug("[vane/plugin-core] plugins registered:", D);
|
|
206
|
-
}, [D]), X(
|
|
207
|
-
() => () => {
|
|
208
|
-
p.executeHook("onUnmount", j.current), p.clear();
|
|
209
|
-
},
|
|
210
|
-
[p]
|
|
211
|
-
);
|
|
212
|
-
const B = z(
|
|
213
|
-
() => ee(t),
|
|
214
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
215
|
-
[D]
|
|
216
|
-
), j = M(null), F = z(() => {
|
|
217
|
-
const I = {
|
|
218
|
-
props: c,
|
|
219
|
-
data: g,
|
|
220
|
-
bus: $,
|
|
221
|
-
refs: { container: a, getContainer: () => a.current },
|
|
222
|
-
state: k,
|
|
223
|
-
setState: (v) => W((V) => ({ ...V, ...v })),
|
|
224
|
-
shared: N.current,
|
|
225
|
-
deviceInfo: O,
|
|
226
|
-
forceUpdate: U,
|
|
227
|
-
getSize: () => {
|
|
228
|
-
const v = a.current;
|
|
229
|
-
return v ? { width: v.offsetWidth, height: v.offsetHeight } : { width: 0, height: 0 };
|
|
230
|
-
},
|
|
231
|
-
logger: console
|
|
232
|
-
};
|
|
233
|
-
return s ? s(I) : I;
|
|
234
|
-
}, [c, g, k, O, $, s]);
|
|
235
|
-
j.current = F;
|
|
236
|
-
const L = C(
|
|
237
|
-
(I) => {
|
|
238
|
-
let v = I;
|
|
239
|
-
for (const V of B) {
|
|
240
|
-
const E = V.hooks?.transformProps;
|
|
241
|
-
typeof E == "function" && (v = E(v));
|
|
242
|
-
}
|
|
243
|
-
return v;
|
|
244
|
-
},
|
|
245
|
-
[B]
|
|
246
|
-
), T = C(
|
|
247
|
-
(I) => {
|
|
248
|
-
let v = I;
|
|
249
|
-
for (const V of B) {
|
|
250
|
-
const E = V.hooks?.transformData;
|
|
251
|
-
typeof E == "function" && (v = E(j.current, v));
|
|
252
|
-
}
|
|
253
|
-
return v;
|
|
254
|
-
},
|
|
255
|
-
[B]
|
|
256
|
-
), h = C(
|
|
257
|
-
(I, ...v) => p.executeHook(I, j.current, ...v),
|
|
258
|
-
[p]
|
|
259
|
-
);
|
|
260
|
-
return {
|
|
261
|
-
manager: p,
|
|
262
|
-
bus: $,
|
|
263
|
-
context: F,
|
|
264
|
-
state: k,
|
|
265
|
-
setState: F.setState,
|
|
266
|
-
execute: h,
|
|
267
|
-
transformProps: L,
|
|
268
|
-
transformData: T,
|
|
269
|
-
orderedPlugins: B
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
fe(null);
|
|
273
|
-
function _(i, t, c) {
|
|
274
|
-
const { hook: g, position: m = "after" } = c;
|
|
275
|
-
return i.filter((l) => l.enabled !== !1).filter((l) => typeof l.hooks?.[g] == "function").filter((l) => (l.config?.slotPosition ?? "after") === m).sort(
|
|
276
|
-
(l, e) => (l.config?.order ?? 0) - (e.config?.order ?? 0) || (e.priority ?? 0) - (l.priority ?? 0)
|
|
277
|
-
).map((l, e) => {
|
|
278
|
-
try {
|
|
279
|
-
const o = l.hooks[g](t);
|
|
280
|
-
return o == null ? null : /* @__PURE__ */ q(te, { children: o }, `vane-slot-${l.name}-${e}`);
|
|
281
|
-
} catch (o) {
|
|
282
|
-
return console.warn(`[vane/plugin-core] 插件 ${l.name} 的 ${g} 渲染失败`, o), null;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
function be(i, t, c) {
|
|
287
|
-
return /* @__PURE__ */ le(ce, { children: [
|
|
288
|
-
_(i, t, { hook: "renderHeader", position: "before" }),
|
|
289
|
-
c,
|
|
290
|
-
_(i, t, { hook: "renderOverlay" }),
|
|
291
|
-
_(i, t, { hook: "renderHeader", position: "after" }),
|
|
292
|
-
_(i, t, { hook: "renderFooter" })
|
|
293
|
-
] });
|
|
294
|
-
}
|
|
295
|
-
const ke = {
|
|
296
|
-
columns: 0,
|
|
297
|
-
columnWidth: 0,
|
|
298
|
-
gap: 0,
|
|
299
|
-
columnHeights: [],
|
|
300
|
-
totalHeight: 0,
|
|
301
|
-
containerWidth: 0,
|
|
302
|
-
containerHeight: 0
|
|
303
|
-
}, xe = {
|
|
304
|
-
scrollTop: 0,
|
|
305
|
-
scrollLeft: 0,
|
|
306
|
-
scrollHeight: 0,
|
|
307
|
-
scrollWidth: 0,
|
|
308
|
-
clientHeight: 0,
|
|
309
|
-
clientWidth: 0,
|
|
310
|
-
isScrolling: !1,
|
|
311
|
-
direction: null
|
|
312
|
-
};
|
|
313
|
-
function Ce() {
|
|
314
|
-
const i = typeof navigator < "u" ? navigator : void 0, t = i?.connection || i?.mozConnection || i?.webkitConnection;
|
|
315
|
-
if (t)
|
|
316
|
-
return {
|
|
317
|
-
effectiveType: t.effectiveType || "4g",
|
|
318
|
-
downlink: Number(t.downlink || 10),
|
|
319
|
-
rtt: Number(t.rtt || 50),
|
|
320
|
-
saveData: !!t.saveData,
|
|
321
|
-
online: i?.onLine !== !1
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function Z(i, t, c) {
|
|
325
|
-
let g = Number.POSITIVE_INFINITY, m = -1;
|
|
326
|
-
return i.forEach((l, e) => {
|
|
327
|
-
Math.max(
|
|
328
|
-
0,
|
|
329
|
-
Math.min(t + c, l.y + l.height) - Math.max(t, l.y)
|
|
330
|
-
) > 0 && (e < g && (g = e), e > m && (m = e));
|
|
331
|
-
}), m < 0 ? { start: 0, end: 0 } : { start: g, end: m };
|
|
332
|
-
}
|
|
333
|
-
function Le(i, t) {
|
|
334
|
-
const c = Array.isArray(t) ? { plugins: t } : t, { plugins: g, enableDebug: m = !1 } = c, l = ge(
|
|
335
|
-
(e, o) => {
|
|
336
|
-
const s = M(null), r = M(/* @__PURE__ */ new Map()), a = M(null), b = z(() => Ce(), []), p = M(null), [R, $] = A(ke), [N, k] = A(
|
|
337
|
-
() => /* @__PURE__ */ new Map()
|
|
338
|
-
), [W, K] = A(xe), [U, O] = A(!1), [D, B] = A(e.items ?? []), j = C(
|
|
339
|
-
(n) => {
|
|
340
|
-
const u = () => a.current?.getLayoutInfo() ?? R, y = () => a.current?.getAllItemPositions() ?? N, P = () => a.current?.getViewportInfo() ?? W, f = {
|
|
341
|
-
...n,
|
|
342
|
-
items: D,
|
|
343
|
-
itemCount: D.length,
|
|
344
|
-
containerRef: s,
|
|
345
|
-
itemRefs: r.current,
|
|
346
|
-
getItemRef: (d) => r.current.get(d) ?? null,
|
|
347
|
-
layout: u(),
|
|
348
|
-
itemPositions: y(),
|
|
349
|
-
getItemPosition: (d) => y().get(d) ?? null,
|
|
350
|
-
viewport: P(),
|
|
351
|
-
visibleItems: /* @__PURE__ */ new Set(),
|
|
352
|
-
visibleRange: Z(
|
|
353
|
-
y(),
|
|
354
|
-
P().scrollTop,
|
|
355
|
-
P().clientHeight
|
|
356
|
-
),
|
|
357
|
-
isLayouting: U,
|
|
358
|
-
isScrolling: W.isScrolling,
|
|
359
|
-
isDragging: !!n.state?.dragInfo?.isDragging,
|
|
360
|
-
isLoading: !!(n.state?.isLoading ?? !1),
|
|
361
|
-
hasMore: !!(n.state?.hasMore ?? !0),
|
|
362
|
-
error: n.state?.error ?? null,
|
|
363
|
-
sharedData: n.shared,
|
|
364
|
-
networkInfo: b,
|
|
365
|
-
dragInfo: n.state?.dragInfo,
|
|
366
|
-
relayout: () => a.current?.relayout(),
|
|
367
|
-
scrollToItem: (d, S) => a.current?.scrollToItem(d, S),
|
|
368
|
-
scrollToTop: (d) => a.current?.scrollToTop(d),
|
|
369
|
-
scrollToBottom: (d) => a.current?.scrollToBottom(d),
|
|
370
|
-
measureItem: (d) => a.current?.measureItem(d) ?? Promise.resolve({ width: 0, height: 0 })
|
|
371
|
-
};
|
|
372
|
-
return Object.defineProperties(f, {
|
|
373
|
-
layout: { get: u, enumerable: !0, configurable: !0 },
|
|
374
|
-
itemPositions: { get: y, enumerable: !0, configurable: !0 },
|
|
375
|
-
viewport: { get: P, enumerable: !0, configurable: !0 },
|
|
376
|
-
props: {
|
|
377
|
-
get: () => p.current ?? n.props,
|
|
378
|
-
enumerable: !0,
|
|
379
|
-
configurable: !0
|
|
380
|
-
},
|
|
381
|
-
visibleRange: {
|
|
382
|
-
get: () => {
|
|
383
|
-
const d = P();
|
|
384
|
-
return Z(y(), d.scrollTop, d.clientHeight);
|
|
385
|
-
},
|
|
386
|
-
enumerable: !0,
|
|
387
|
-
configurable: !0
|
|
388
|
-
}
|
|
389
|
-
}), f;
|
|
390
|
-
},
|
|
391
|
-
[D, R, N, W, U, b]
|
|
392
|
-
), L = Ie({
|
|
393
|
-
plugins: g,
|
|
394
|
-
props: e,
|
|
395
|
-
enableDebug: m,
|
|
396
|
-
containerRef: s,
|
|
397
|
-
extendContext: j
|
|
398
|
-
}), T = M(L.context);
|
|
399
|
-
T.current = L.context;
|
|
400
|
-
const h = C(
|
|
401
|
-
(n, ...u) => L.execute(n, ...u),
|
|
402
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
403
|
-
[L.manager]
|
|
404
|
-
), I = L.orderedPlugins, v = g.map((n) => n.name).join("|"), V = z(() => {
|
|
405
|
-
const n = I.filter(
|
|
406
|
-
(f) => typeof f.hooks?.calculateColumns == "function"
|
|
407
|
-
), u = I.filter(
|
|
408
|
-
(f) => typeof f.hooks?.calculateColumnWidth == "function"
|
|
409
|
-
), y = I.filter(
|
|
410
|
-
(f) => typeof f.hooks?.calculateItemPosition == "function"
|
|
411
|
-
);
|
|
412
|
-
if (!n.length && !u.length && !y.length)
|
|
413
|
-
return;
|
|
414
|
-
const P = (f, d, S) => console.warn(`[vane-waterfall] ${f} 的 ${d} 执行失败`, S);
|
|
415
|
-
return {
|
|
416
|
-
calculateColumns: n.length ? (f) => {
|
|
417
|
-
const d = T.current?.containerRef?.current?.clientWidth ?? 0;
|
|
418
|
-
for (const S of n)
|
|
419
|
-
try {
|
|
420
|
-
const x = S.hooks.calculateColumns(T.current, d);
|
|
421
|
-
if (typeof x == "number" && Number.isFinite(x)) return x;
|
|
422
|
-
} catch (x) {
|
|
423
|
-
P(S.name, "calculateColumns", x);
|
|
424
|
-
}
|
|
425
|
-
} : void 0,
|
|
426
|
-
calculateColumnWidth: u.length ? (f, d, S) => {
|
|
427
|
-
for (const x of u)
|
|
428
|
-
try {
|
|
429
|
-
const H = x.hooks.calculateColumnWidth(
|
|
430
|
-
T.current,
|
|
431
|
-
S,
|
|
432
|
-
d
|
|
433
|
-
);
|
|
434
|
-
if (typeof H == "number" && Number.isFinite(H)) return H;
|
|
435
|
-
} catch (H) {
|
|
436
|
-
P(x.name, "calculateColumnWidth", H);
|
|
437
|
-
}
|
|
438
|
-
} : void 0,
|
|
439
|
-
calculateItemPosition: y.length ? (f, d, S) => {
|
|
440
|
-
for (const x of y)
|
|
441
|
-
try {
|
|
442
|
-
const H = x.hooks.calculateItemPosition(
|
|
443
|
-
T.current,
|
|
444
|
-
f,
|
|
445
|
-
d,
|
|
446
|
-
S
|
|
447
|
-
);
|
|
448
|
-
if (H) return H;
|
|
449
|
-
} catch (H) {
|
|
450
|
-
P(x.name, "calculateItemPosition", H);
|
|
451
|
-
}
|
|
452
|
-
} : void 0
|
|
453
|
-
};
|
|
454
|
-
}, [v]), E = C(() => {
|
|
455
|
-
const n = a.current;
|
|
456
|
-
if (!n) return;
|
|
457
|
-
const u = n.getLayoutInfo(), y = n.getAllItemPositions(), P = n.getViewportInfo();
|
|
458
|
-
$(
|
|
459
|
-
(f) => f.totalHeight === u.totalHeight && f.columns === u.columns && f.columnWidth === u.columnWidth && f.containerWidth === u.containerWidth ? f : u
|
|
460
|
-
), k(
|
|
461
|
-
(f) => f.size === y.size ? f : y
|
|
462
|
-
), K(
|
|
463
|
-
(f) => f.scrollTop === P.scrollTop && f.clientHeight === P.clientHeight && f.scrollHeight === P.scrollHeight && f.isScrolling === P.isScrolling ? f : P
|
|
464
|
-
);
|
|
465
|
-
}, []);
|
|
466
|
-
J(() => {
|
|
467
|
-
B(e.items ?? []);
|
|
468
|
-
}, [e.items]), J(() => {
|
|
469
|
-
h("onMount");
|
|
470
|
-
}, [h]);
|
|
471
|
-
const G = M(e);
|
|
472
|
-
J(() => {
|
|
473
|
-
const n = G.current;
|
|
474
|
-
n !== e && (G.current = e, h("onPropsChange", n, e));
|
|
475
|
-
}, [e, h]);
|
|
476
|
-
const w = L.transformProps(e);
|
|
477
|
-
p.current = w;
|
|
478
|
-
const ne = C(async () => (O(!0), await h("onBeforeLayout") === !1 ? (O(!1), !1) : !0), [h]), oe = C(() => {
|
|
479
|
-
h("onLayout");
|
|
480
|
-
}, [h]), re = C(() => {
|
|
481
|
-
O(!1), h("onLayoutComplete"), Promise.resolve().then(E);
|
|
482
|
-
}, [h, E]), ie = I.filter(
|
|
483
|
-
(n) => typeof n.hooks?.renderItemWrapper == "function"
|
|
484
|
-
), Q = w.renderItem, se = C(
|
|
485
|
-
(n, u) => {
|
|
486
|
-
let y = Q?.(n, u) ?? null;
|
|
487
|
-
for (const P of ie)
|
|
488
|
-
try {
|
|
489
|
-
const f = P.hooks.renderItemWrapper(T.current, y, u);
|
|
490
|
-
f != null && (y = f);
|
|
491
|
-
} catch (f) {
|
|
492
|
-
console.warn(`[vane-waterfall] ${P.name} 的 renderItemWrapper 失败`, f);
|
|
493
|
-
}
|
|
494
|
-
return y;
|
|
495
|
-
},
|
|
496
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
497
|
-
[Q, v]
|
|
498
|
-
), ae = {
|
|
499
|
-
...w,
|
|
500
|
-
containerRefExternal: s,
|
|
501
|
-
itemRefsExternal: r,
|
|
502
|
-
debug: w.debug ?? m,
|
|
503
|
-
layoutHooks: V ?? w.layoutHooks,
|
|
504
|
-
renderItem: se,
|
|
505
|
-
children: /* @__PURE__ */ q(te, { children: be(L.orderedPlugins, L.context, w.children) }),
|
|
506
|
-
onMount: () => {
|
|
507
|
-
w.onMount?.();
|
|
508
|
-
},
|
|
509
|
-
onUnmount: () => {
|
|
510
|
-
w.onUnmount?.();
|
|
511
|
-
},
|
|
512
|
-
onBeforeLayout: async () => await ne() === !1 ? !1 : w.onBeforeLayout?.() ?? !0,
|
|
513
|
-
onLayout: () => {
|
|
514
|
-
w.onLayout?.(), oe();
|
|
515
|
-
},
|
|
516
|
-
onLayoutComplete: () => {
|
|
517
|
-
w.onLayoutComplete?.(), re();
|
|
518
|
-
},
|
|
519
|
-
onItemMount: (n, u) => {
|
|
520
|
-
w.onItemMount?.(n, u), h("onItemMount", n, u);
|
|
521
|
-
},
|
|
522
|
-
onItemUnmount: (n) => {
|
|
523
|
-
w.onItemUnmount?.(n), h("onItemUnmount", n);
|
|
524
|
-
},
|
|
525
|
-
onItemEnterViewport: (n, u) => {
|
|
526
|
-
w.onItemEnterViewport?.(n, u), h("onItemEnterViewport", n, u);
|
|
527
|
-
},
|
|
528
|
-
onItemLeaveViewport: (n, u) => {
|
|
529
|
-
w.onItemLeaveViewport?.(n, u), h("onItemLeaveViewport", n, u);
|
|
530
|
-
},
|
|
531
|
-
onScroll: (n, u) => {
|
|
532
|
-
w.onScroll?.(n, u), h("onScroll", n, u), E();
|
|
533
|
-
},
|
|
534
|
-
onResize: (n, u) => {
|
|
535
|
-
w.onResize?.(n, u), h("onResize", n, u);
|
|
536
|
-
},
|
|
537
|
-
onReachBottom: async (n) => {
|
|
538
|
-
await w.onReachBottom?.(n), await h("onReachBottom", n);
|
|
539
|
-
},
|
|
540
|
-
onItemClick: (n, u, y) => {
|
|
541
|
-
w.onItemClick?.(n, u, y), h("onItemClick", n, u, y);
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
return /* @__PURE__ */ q(
|
|
545
|
-
i,
|
|
546
|
-
{
|
|
547
|
-
ref: (n) => {
|
|
548
|
-
a.current = n, typeof o == "function" ? o(n) : o && (o.current = n);
|
|
549
|
-
},
|
|
550
|
-
...ae
|
|
551
|
-
}
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
);
|
|
555
|
-
return l.displayName = "WithPlugins(WaterfallCore)", l;
|
|
556
|
-
}
|
|
557
|
-
export {
|
|
558
|
-
Le as w
|
|
559
|
-
};
|