@splicetree/plugin-lazy-load 3.0.2 → 3.1.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/CHANGELOG.md +18 -0
- package/dist/index.js +30 -1
- package/package.json +2 -2
- package/src/index.ts +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @splicetree/plugin-lazy-load
|
|
2
2
|
|
|
3
|
+
## 3.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Core/Adapter/Lazy-Load/DnD:稳定性修复与小幅改进
|
|
8
|
+
- DnD:为 `draggable/sortable/nestable` 增加函数/异步判定;在悬停与释放阶段严格校验并在不允许时隐藏 ghost;增加去抖与离开清理以消除偶发 ghost 闪烁
|
|
9
|
+
- Adapter-Vue:抽取数据同步工具;字段变更走 `updateOriginal` 合并,结构变更再 `syncData`
|
|
10
|
+
- Core:节点扩展应用于追加节点;补充若干示例与文档更新
|
|
11
|
+
- Lazy-Load:覆盖 `syncData`,在重建后恢复已加载子树与覆盖
|
|
12
|
+
|
|
13
|
+
## 3.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- Lazy-Load 插件:
|
|
18
|
+
- 覆盖 `syncData`,在重建后恢复此前已懒加载的子树并重新应用覆盖方法与事件派发(`lazyload`)
|
|
19
|
+
- 追加子节点后,新节点的覆盖方法与实例能力保持一致(与核心的 `extendNode` 自动应用配合)
|
|
20
|
+
|
|
3
21
|
## 3.0.2
|
|
4
22
|
|
|
5
23
|
## 3.0.1
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const lazyLoad = {
|
|
|
5
5
|
const { loadChildren } = ctx.options?.configuration?.lazyLoad ?? {};
|
|
6
6
|
const loadedKeys = /* @__PURE__ */ new Set();
|
|
7
7
|
const loadingKeys = /* @__PURE__ */ new Set();
|
|
8
|
+
const loadedChildrenData = /* @__PURE__ */ new Map();
|
|
8
9
|
const isLoaded = (id) => loadedKeys.has(id);
|
|
9
10
|
const isLoading = (id) => loadingKeys.has(id);
|
|
10
11
|
/**
|
|
@@ -41,6 +42,7 @@ const lazyLoad = {
|
|
|
41
42
|
const children = await loadChildren(node);
|
|
42
43
|
if (children?.length) {
|
|
43
44
|
ctx.tree.appendChildren(id, children);
|
|
45
|
+
loadedChildrenData.set(id, children);
|
|
44
46
|
for (const c of children) {
|
|
45
47
|
const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.keyField ?? "id"));
|
|
46
48
|
const childNode = ctx.tree.getNode(childId);
|
|
@@ -60,6 +62,7 @@ const lazyLoad = {
|
|
|
60
62
|
};
|
|
61
63
|
const origExpand = ctx.tree.expand.bind(ctx.tree);
|
|
62
64
|
const origToggle = ctx.tree.toggleExpand.bind(ctx.tree);
|
|
65
|
+
const origSync = ctx.tree.syncData.bind(ctx.tree);
|
|
63
66
|
/**
|
|
64
67
|
* 覆盖 expand:在展开前确保子节点已加载
|
|
65
68
|
* @param ids 要展开的节点 id 或 id 数组
|
|
@@ -82,6 +85,31 @@ const lazyLoad = {
|
|
|
82
85
|
}
|
|
83
86
|
origToggle(ids);
|
|
84
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* 覆盖 syncData:在重建后重新附加已加载的子节点数据并恢复覆盖
|
|
90
|
+
*/
|
|
91
|
+
const syncData = (next) => {
|
|
92
|
+
origSync(next);
|
|
93
|
+
if (loadedChildrenData.size) {
|
|
94
|
+
for (const [parentId, children] of loadedChildrenData.entries()) {
|
|
95
|
+
if (!ctx.tree.getNode(parentId)) continue;
|
|
96
|
+
ctx.tree.appendChildren(parentId, children);
|
|
97
|
+
for (const c of children) {
|
|
98
|
+
const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.keyField ?? "id"));
|
|
99
|
+
const childNode = ctx.tree.getNode(childId);
|
|
100
|
+
if (childNode) applyLazyOverrides(childNode);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
ctx.events.emit({
|
|
104
|
+
name: "visibility",
|
|
105
|
+
keys: ctx.tree.expandedKeys()
|
|
106
|
+
});
|
|
107
|
+
ctx.events.emit({
|
|
108
|
+
name: "lazyload",
|
|
109
|
+
keys: Array.from(loadedKeys)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
85
113
|
return {
|
|
86
114
|
loadedKeys,
|
|
87
115
|
loadingKeys,
|
|
@@ -89,7 +117,8 @@ const lazyLoad = {
|
|
|
89
117
|
isLoading,
|
|
90
118
|
load,
|
|
91
119
|
expand,
|
|
92
|
-
toggleExpand
|
|
120
|
+
toggleExpand,
|
|
121
|
+
syncData
|
|
93
122
|
};
|
|
94
123
|
},
|
|
95
124
|
extendNode(node, ctx) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splicetree/plugin-lazy-load",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "michael.cocova@gmail.com",
|
|
7
7
|
"name": "Michael Cocova"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@splicetree/core": "3.
|
|
26
|
+
"@splicetree/core": "3.1.1"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"dev": "tsdown --watch",
|
package/src/index.ts
CHANGED
|
@@ -73,6 +73,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
73
73
|
const { loadChildren } = cfg
|
|
74
74
|
const loadedKeys = new Set<string>()
|
|
75
75
|
const loadingKeys = new Set<string>()
|
|
76
|
+
const loadedChildrenData = new Map<string, any[]>()
|
|
76
77
|
const isLoaded = (id: string) => loadedKeys.has(id)
|
|
77
78
|
const isLoading = (id: string) => loadingKeys.has(id)
|
|
78
79
|
|
|
@@ -119,6 +120,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
119
120
|
const children = await loadChildren(node)
|
|
120
121
|
if (children?.length) {
|
|
121
122
|
ctx.tree.appendChildren(id, children)
|
|
123
|
+
loadedChildrenData.set(id, children)
|
|
122
124
|
for (const c of children) {
|
|
123
125
|
const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.keyField ?? 'id'))
|
|
124
126
|
const childNode = ctx.tree.getNode(childId)
|
|
@@ -135,6 +137,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
135
137
|
|
|
136
138
|
const origExpand = ctx.tree.expand.bind(ctx.tree)
|
|
137
139
|
const origToggle = ctx.tree.toggleExpand.bind(ctx.tree)
|
|
140
|
+
const origSync = ctx.tree.syncData.bind(ctx.tree)
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
143
|
* 覆盖 expand:在展开前确保子节点已加载
|
|
@@ -166,6 +169,29 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
166
169
|
}
|
|
167
170
|
origToggle(ids)
|
|
168
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* 覆盖 syncData:在重建后重新附加已加载的子节点数据并恢复覆盖
|
|
174
|
+
*/
|
|
175
|
+
const syncData = (next: any[]) => {
|
|
176
|
+
origSync(next)
|
|
177
|
+
if (loadedChildrenData.size) {
|
|
178
|
+
for (const [parentId, children] of loadedChildrenData.entries()) {
|
|
179
|
+
if (!ctx.tree.getNode(parentId)) {
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
ctx.tree.appendChildren(parentId, children)
|
|
183
|
+
for (const c of children) {
|
|
184
|
+
const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.keyField ?? 'id'))
|
|
185
|
+
const childNode = ctx.tree.getNode(childId)
|
|
186
|
+
if (childNode) {
|
|
187
|
+
applyLazyOverrides(childNode)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
ctx.events.emit({ name: 'visibility', keys: ctx.tree.expandedKeys() })
|
|
192
|
+
ctx.events.emit({ name: 'lazyload', keys: Array.from(loadedKeys) })
|
|
193
|
+
}
|
|
194
|
+
}
|
|
169
195
|
|
|
170
196
|
return {
|
|
171
197
|
loadedKeys,
|
|
@@ -175,6 +201,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
175
201
|
load,
|
|
176
202
|
expand,
|
|
177
203
|
toggleExpand,
|
|
204
|
+
syncData,
|
|
178
205
|
}
|
|
179
206
|
},
|
|
180
207
|
/**
|