@splicetree/plugin-lazy-load 0.0.1 → 0.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 +7 -17
- package/README.md +2 -2
- package/dist/index.d.ts +4 -11
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +20 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
# @splicetree/plugin-lazy-load
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.1.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- fix: republish plugin-lazy-load after partial release failure
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
- 建立无头树(Headless Tree)核心模型与数据结构
|
|
11
|
-
- 定义节点操作 API、事件系统和状态管理机制
|
|
12
|
-
- 设计并实现插件体系(生命周期、注册机制、能力扩展)
|
|
13
|
-
- 引入模块化架构,明确 core / plugins / adapters 的边界
|
|
14
|
-
- 预留扩展点与内部协议,构建可插拔式架构基础
|
|
11
|
+
## 0.0.1
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
- 添加 Vue 3 适配层(渲染无关、纯接口绑定)
|
|
18
|
-
- 设计独立的 UI 层解耦策略,确保跨框架可迁移
|
|
19
|
-
- 预留未来 React/Svelte/WebComponents 的适配接口
|
|
13
|
+
### Patch Changes
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
- 初始化 monorepo 工程结构(packages + docs)
|
|
23
|
-
- 配置构建工具链 tsdown(多包构建、类型输出)
|
|
24
|
-
- 构建文档系统(VitePress)与基础导航结构
|
|
25
|
-
- 设置开发环境、代码规范(ESLint)、格式化流程
|
|
15
|
+
- chore: 搭建 SpliceTree 框架基础架构与工程体系
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @splicetree/plugin-lazy-load
|
|
2
2
|
|
|
3
|
+
提供懒加载子节点能力,在首次展开时动态加载并追加到树。
|
|
4
|
+
|
|
3
5
|
[](https://www.npmjs.com/package/@splicetree/plugin-lazy-load)
|
|
4
6
|
[](https://npmcharts.com/compare/%40splicetree%2Fplugin-lazy-load?minimal=true)
|
|
5
7
|
[](https://www.npmjs.com/package/@splicetree/plugin-lazy-load)
|
|
6
8
|
[](https://www.splicetree.dev)
|
|
7
9
|
[](https://github.com/michaelcocova/splicetree)
|
|
8
10
|
|
|
9
|
-
提供懒加载子节点能力,在首次展开时动态加载并追加到树。
|
|
10
|
-
|
|
11
11
|
## 安装
|
|
12
12
|
|
|
13
13
|
`pnpm add @splicetree/plugin-lazy-load`
|
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,10 @@ import { SpliceTreePlugin } from "@splicetree/core";
|
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
declare module '@splicetree/core' {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
interface UseSpliceTreeOptions {
|
|
10
|
-
/**
|
|
11
|
-
* 加载指定节点的子节点
|
|
12
|
-
* 返回子节点数据数组,加载完成后将自动追加到树中
|
|
13
|
-
* @param node 要加载子节点的目标节点
|
|
14
|
-
*/
|
|
15
|
-
loadChildren?: (node: SpliceTreeNode<any>) => Promise<any[]>;
|
|
5
|
+
interface SpliceTreeConfiguration {
|
|
6
|
+
lazyLoad?: {
|
|
7
|
+
loadChildren?: (node: SpliceTreeNode<any>) => Promise<any[]>;
|
|
8
|
+
};
|
|
16
9
|
}
|
|
17
10
|
/**
|
|
18
11
|
* 事件扩展(Lazy-Load)
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const lazyLoad = {
|
|
3
3
|
name: "lazy-load",
|
|
4
4
|
setup(ctx) {
|
|
5
|
-
const { loadChildren } = ctx.options;
|
|
5
|
+
const { loadChildren } = ctx.options?.configuration?.lazyLoad ?? {};
|
|
6
6
|
const loadedKeys = /* @__PURE__ */ new Set();
|
|
7
7
|
const isLoaded = (id) => loadedKeys.has(id);
|
|
8
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splicetree/plugin-lazy-load",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.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": "0.
|
|
26
|
+
"@splicetree/core": "0.1.1"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"dev": "tsdown --watch",
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import type { SpliceTreePlugin, SpliceTreePluginContext } from '@splicetree/core'
|
|
1
|
+
import type { SpliceTreeNode, SpliceTreePlugin, SpliceTreePluginContext } from '@splicetree/core'
|
|
2
2
|
import '@splicetree/core'
|
|
3
3
|
|
|
4
4
|
declare module '@splicetree/core' {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
interface UseSpliceTreeOptions {
|
|
10
|
-
/**
|
|
11
|
-
* 加载指定节点的子节点
|
|
12
|
-
* 返回子节点数据数组,加载完成后将自动追加到树中
|
|
13
|
-
* @param node 要加载子节点的目标节点
|
|
14
|
-
*/
|
|
15
|
-
loadChildren?: (node: SpliceTreeNode<any>) => Promise<any[]>
|
|
5
|
+
export interface SpliceTreeConfiguration {
|
|
6
|
+
lazyLoad?: {
|
|
7
|
+
loadChildren?: (node: SpliceTreeNode<any>) => Promise<any[]>
|
|
8
|
+
}
|
|
16
9
|
}
|
|
17
10
|
|
|
18
11
|
/**
|
|
@@ -63,7 +56,10 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
63
56
|
* - 通过 loadedKeys 标记已加载节点
|
|
64
57
|
*/
|
|
65
58
|
setup(ctx: SpliceTreePluginContext) {
|
|
66
|
-
const
|
|
59
|
+
const cfg = (ctx.options?.configuration?.lazyLoad ?? {}) as {
|
|
60
|
+
loadChildren?: (node: SpliceTreeNode<any>) => Promise<any[]>
|
|
61
|
+
}
|
|
62
|
+
const { loadChildren } = cfg
|
|
67
63
|
const loadedKeys = new Set<string>()
|
|
68
64
|
const isLoaded = (id: string) => loadedKeys.has(id)
|
|
69
65
|
|
|
@@ -105,7 +101,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
105
101
|
if (children?.length) {
|
|
106
102
|
ctx.tree.appendChildren(id, children)
|
|
107
103
|
for (const c of children) {
|
|
108
|
-
const childId = String(Reflect.get(c
|
|
104
|
+
const childId = String(Reflect.get(c, ctx.tree.options?.keyField ?? 'id'))
|
|
109
105
|
const childNode = ctx.tree.getNode(childId)
|
|
110
106
|
if (childNode) {
|
|
111
107
|
applyLazyOverrides(childNode)
|
|
@@ -113,7 +109,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
loadedKeys.add(id)
|
|
116
|
-
ctx.events.emit({ name: 'lazyload', keys: Array.from(loadedKeys) }
|
|
112
|
+
ctx.events.emit({ name: 'lazyload', keys: Array.from(loadedKeys) })
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
const origExpand = ctx.tree.expand.bind(ctx.tree)
|
|
@@ -127,11 +123,12 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
127
123
|
const list = Array.isArray(ids) ? ids : [ids]
|
|
128
124
|
if (loadChildren) {
|
|
129
125
|
for (const id of list) {
|
|
130
|
-
if (!isLoaded(id))
|
|
126
|
+
if (!isLoaded(id)) {
|
|
131
127
|
await load(id)
|
|
128
|
+
}
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
|
-
origExpand(ids
|
|
131
|
+
origExpand(ids)
|
|
135
132
|
}
|
|
136
133
|
/**
|
|
137
134
|
* 覆盖 toggleExpand:在切换前确保子节点已加载
|
|
@@ -141,20 +138,20 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
141
138
|
const list = Array.isArray(ids) ? ids : [ids]
|
|
142
139
|
if (loadChildren) {
|
|
143
140
|
for (const id of list) {
|
|
144
|
-
if (!isLoaded(id))
|
|
141
|
+
if (!isLoaded(id)) {
|
|
145
142
|
await load(id)
|
|
143
|
+
}
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
|
-
origToggle(ids
|
|
146
|
+
origToggle(ids)
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
return {
|
|
152
150
|
loadedKeys,
|
|
153
151
|
isLoaded,
|
|
154
152
|
load,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
toggleExpand: toggleExpand as any,
|
|
153
|
+
expand,
|
|
154
|
+
toggleExpand,
|
|
158
155
|
}
|
|
159
156
|
},
|
|
160
157
|
/**
|
|
@@ -163,7 +160,7 @@ export const lazyLoad: SpliceTreePlugin = {
|
|
|
163
160
|
* - hasChildren:未加载时返回 true,已加载后按实际子节点判断
|
|
164
161
|
*/
|
|
165
162
|
extendNode(node, ctx) {
|
|
166
|
-
|
|
163
|
+
node.isLoaded = () => ctx.tree.isLoaded?.(node.id)
|
|
167
164
|
node.hasChildren = () => {
|
|
168
165
|
const loaded = ctx.tree.isLoaded?.(node.id)
|
|
169
166
|
if (!loaded) {
|