@splicetree/plugin-lazy-load 0.0.1 → 0.2.0

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 CHANGED
@@ -1,25 +1,17 @@
1
1
  # @splicetree/plugin-lazy-load
2
2
 
3
+ ## 0.2.0
4
+
5
+ ## 0.1.1
6
+
7
+ ### Patch Changes
8
+
9
+ - fix: republish plugin-lazy-load after partial release failure
10
+
11
+ ## 0.1.0
12
+
3
13
  ## 0.0.1
4
14
 
5
15
  ### Patch Changes
6
16
 
7
17
  - chore: 搭建 SpliceTree 框架基础架构与工程体系
8
-
9
- 框架架构:
10
- - 建立无头树(Headless Tree)核心模型与数据结构
11
- - 定义节点操作 API、事件系统和状态管理机制
12
- - 设计并实现插件体系(生命周期、注册机制、能力扩展)
13
- - 引入模块化架构,明确 core / plugins / adapters 的边界
14
- - 预留扩展点与内部协议,构建可插拔式架构基础
15
-
16
- 适配层与生态:
17
- - 添加 Vue 3 适配层(渲染无关、纯接口绑定)
18
- - 设计独立的 UI 层解耦策略,确保跨框架可迁移
19
- - 预留未来 React/Svelte/WebComponents 的适配接口
20
-
21
- 工程化与工具链:
22
- - 初始化 monorepo 工程结构(packages + docs)
23
- - 配置构建工具链 tsdown(多包构建、类型输出)
24
- - 构建文档系统(VitePress)与基础导航结构
25
- - 设置开发环境、代码规范(ESLint)、格式化流程
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # @splicetree/plugin-lazy-load
2
2
 
3
+ 提供懒加载子节点能力,在首次展开时动态加载并追加到树。
4
+
3
5
  [![version](https://img.shields.io/npm/v/@splicetree/plugin-lazy-load.svg?label=version)](https://www.npmjs.com/package/@splicetree/plugin-lazy-load)
4
6
  [![downloads](https://img.shields.io/npm/dm/@splicetree/plugin-lazy-load.svg)](https://npmcharts.com/compare/%40splicetree%2Fplugin-lazy-load?minimal=true)
5
7
  [![license](https://img.shields.io/npm/l/@splicetree/plugin-lazy-load.svg)](https://www.npmjs.com/package/@splicetree/plugin-lazy-load)
6
8
  [![Website](https://img.shields.io/static/v1?label=Website&message=splicetree.dev&color=blue)](https://www.splicetree.dev)
7
9
  [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=splicetree%2Fsplicetree&logo=github)](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
- * 选项扩展(Lazy-Load)
7
- * - loadChildren:按需加载指定节点的子节点
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
  /**
@@ -33,7 +33,7 @@ const lazyLoad = {
33
33
  if (children?.length) {
34
34
  ctx.tree.appendChildren(id, children);
35
35
  for (const c of children) {
36
- const childId = String(Reflect.get(c, ctx.tree.options?.keyField ?? "id"));
36
+ const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.keyField ?? ctx.tree.options?.keyField ?? "id"));
37
37
  const childNode = ctx.tree.getNode(childId);
38
38
  if (childNode) applyLazyOverrides(childNode);
39
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/plugin-lazy-load",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.2.0",
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.0.1"
26
+ "@splicetree/core": "0.2.0"
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
- * 选项扩展(Lazy-Load)
7
- * - loadChildren:按需加载指定节点的子节点
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 { loadChildren } = ctx.options
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 as any, ctx.tree.options?.keyField ?? 'id'))
104
+ const childId = String(Reflect.get(c, ctx.tree.options?.configuration?.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) } as any)
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 as any)
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 as any)
146
+ origToggle(ids)
149
147
  }
150
148
 
151
149
  return {
152
150
  loadedKeys,
153
151
  isLoaded,
154
152
  load,
155
- // 覆盖核心方法以接入懒加载
156
- expand: expand as any,
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
- ;(node as any).isLoaded = () => ctx.tree.isLoaded?.(node.id)
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) {