@splicetree/plugin-checkable 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 CHANGED
@@ -1,25 +1,17 @@
1
1
  # @splicetree/plugin-checkable
2
2
 
3
- ## 0.0.1
3
+ ## 0.1.1
4
4
 
5
- ### Patch Changes
5
+ ## 0.1.0
6
6
 
7
- - chore: 搭建 SpliceTree 框架基础架构与工程体系
7
+ ### Minor Changes
8
8
 
9
- 框架架构:
10
- - 建立无头树(Headless Tree)核心模型与数据结构
11
- - 定义节点操作 API、事件系统和状态管理机制
12
- - 设计并实现插件体系(生命周期、注册机制、能力扩展)
13
- - 引入模块化架构,明确 core / plugins / adapters 的边界
14
- - 预留扩展点与内部协议,构建可插拔式架构基础
9
+ - ### @splicetree/plugin-checkable
10
+ - 更新为配置聚合:`configuration.checkable.defaultChecked/triggerByClick`
11
+ - 可选:通过点击节点触发勾选切换(与 Pointer 协同)
15
12
 
16
- 适配层与生态:
17
- - 添加 Vue 3 适配层(渲染无关、纯接口绑定)
18
- - 设计独立的 UI 层解耦策略,确保跨框架可迁移
19
- - 预留未来 React/Svelte/WebComponents 的适配接口
13
+ ## 0.0.1
20
14
 
21
- 工程化与工具链:
22
- - 初始化 monorepo 工程结构(packages + docs)
23
- - 配置构建工具链 tsdown(多包构建、类型输出)
24
- - 构建文档系统(VitePress)与基础导航结构
25
- - 设置开发环境、代码规范(ESLint)、格式化流程
15
+ ### Patch Changes
16
+
17
+ - chore: 搭建 SpliceTree 框架基础架构与工程体系
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # @splicetree/plugin-checkable
2
2
 
3
+ 为树节点提供勾选与半选能力,支持向下级联与向上计算半选。
4
+
3
5
  [![version](https://img.shields.io/npm/v/@splicetree/plugin-checkable.svg?label=version)](https://www.npmjs.com/package/@splicetree/plugin-checkable)
4
6
  [![downloads](https://img.shields.io/npm/dm/@splicetree/plugin-checkable.svg)](https://npmcharts.com/compare/%40splicetree%2Fplugin-checkable?minimal=true)
5
7
  [![license](https://img.shields.io/npm/l/@splicetree/plugin-checkable.svg)](https://www.npmjs.com/package/@splicetree/plugin-checkable)
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-checkable`
@@ -20,36 +20,34 @@ import checkable from '@splicetree/plugin-checkable'
20
20
 
21
21
  const tree = createSpliceTree(data, {
22
22
  plugins: [checkable],
23
- defaultExpanded: ['a'],
24
- defaultChecked: ['a'],
23
+ configuration: {
24
+ checkable: {
25
+ defaultChecked: ['a'],
26
+ // 可选:点击节点即切换勾选
27
+ triggerByClick: true,
28
+ },
29
+ },
25
30
  })
26
31
  ```
27
32
 
28
33
  ## Api
29
34
 
30
- ### Options
35
+ ### Configuration
31
36
 
32
- | 选项 | 类型 | 默认值 | 说明 |
33
- | ---------------- | ---------- | ------ | ------------ |
34
- | `defaultChecked` | `string[]` | `[]` | 初始勾选集合 |
37
+ - `configuration.checkable.defaultChecked: string[]` 初始勾选集合
38
+ - `configuration.checkable.triggerByClick: boolean` 点击节点切换勾选
35
39
 
36
40
  ### Events
37
41
 
38
- | 事件 | 负载 | 说明 |
39
- | --------- | -------------------- | ------------------ |
40
- | `checked` | `{ keys: string[] }` | 勾选状态变化时触发 |
42
+ - `checked` 负载:`{ keys: string[] }` 勾选状态变化时触发
41
43
 
42
44
  ### 实例方法
43
45
 
44
- | 名称 | 参数 | 说明 |
45
- | ------------------- | ---- | ------------ |
46
- | `checkedKeys` | `无` | 当前勾选集合 |
47
- | `indeterminateKeys` | `无` | 当前半选集合 |
46
+ - `checkedKeys` 当前勾选集合
47
+ - `indeterminateKeys` 当前半选集合
48
48
 
49
49
  ### 节点方法
50
50
 
51
- | 名称 | 参数 | 说明 |
52
- | ----------------------- | ------------------- | -------------- |
53
- | `isChecked()` | `无` | 是否勾选 |
54
- | `isIndeterminate()` | `无` | 是否半选 |
55
- | `toggleCheck(checked?)` | `checked?: boolean` | 切换或显式设置 |
51
+ - `isChecked(): boolean` 是否勾选
52
+ - `isIndeterminate(): boolean` 是否半选
53
+ - `toggleCheck(checked?: boolean)` 切换或显式设置
package/dist/index.d.ts CHANGED
@@ -2,16 +2,22 @@ import { SpliceTreePlugin } from "@splicetree/core";
2
2
 
3
3
  //#region src/index.d.ts
4
4
  declare module '@splicetree/core' {
5
- /**
6
- * 选项扩展(Checkable)
7
- * - defaultChecked:初始勾选的节点 id 列表
8
- */
9
- interface UseSpliceTreeOptions {
10
- /**
11
- * 初始勾选的节点 id 列表
12
- * 在初始化时将这些节点设置为已勾选
13
- */
14
- defaultChecked?: string[];
5
+ interface SpliceTreeConfiguration {
6
+ checkable?: {
7
+ defaultChecked?: string[];
8
+ triggerByClick?: boolean;
9
+ };
10
+ }
11
+ interface SpliceTreeEventPayloadMap {
12
+ 'input:node-click': {
13
+ nodeId: string;
14
+ modifiers: {
15
+ shift: boolean;
16
+ ctrl: boolean;
17
+ meta: boolean;
18
+ alt: boolean;
19
+ };
20
+ };
15
21
  }
16
22
  /**
17
23
  * 节点扩展(Checkable)
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ function setChecked(id, state, checked, indeterminate) {
21
21
  const checkable = {
22
22
  name: "checkable",
23
23
  setup(ctx) {
24
- const { defaultChecked = [] } = ctx.options;
24
+ const cfg = ctx.options?.configuration?.checkable ?? {};
25
+ const { defaultChecked = [] } = cfg;
25
26
  const checkedKeys = new Set(defaultChecked);
26
27
  const indeterminateKeys = /* @__PURE__ */ new Set();
27
28
  const isChecked = (id) => checkedKeys.has(id);
@@ -103,6 +104,11 @@ const checkable = {
103
104
  name: "checked",
104
105
  keys: Array.from(checkedKeys)
105
106
  });
107
+ if (!!cfg?.triggerByClick) ctx.events.on("input:node-click", (p) => {
108
+ const nodeId = p.nodeId;
109
+ if (!ctx.tree.getNode(nodeId)) return;
110
+ toggleCheck(nodeId);
111
+ });
106
112
  return {
107
113
  checkedKeys,
108
114
  indeterminateKeys,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/plugin-checkable",
3
3
  "type": "module",
4
- "version": "0.0.1",
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.0.1"
26
+ "@splicetree/core": "0.1.1"
27
27
  },
28
28
  "scripts": {
29
29
  "dev": "tsdown --watch",
package/src/index.ts CHANGED
@@ -2,16 +2,22 @@ import type { SpliceTreePlugin, SpliceTreePluginContext } from '@splicetree/core
2
2
  import '@splicetree/core'
3
3
 
4
4
  declare module '@splicetree/core' {
5
- /**
6
- * 选项扩展(Checkable)
7
- * - defaultChecked:初始勾选的节点 id 列表
8
- */
9
- interface UseSpliceTreeOptions {
10
- /**
11
- * 初始勾选的节点 id 列表
12
- * 在初始化时将这些节点设置为已勾选
13
- */
14
- defaultChecked?: string[]
5
+ export interface SpliceTreeConfiguration {
6
+ checkable?: {
7
+ defaultChecked?: string[]
8
+ triggerByClick?: boolean
9
+ }
10
+ }
11
+ export interface SpliceTreeEventPayloadMap {
12
+ 'input:node-click': {
13
+ nodeId: string
14
+ modifiers: {
15
+ shift: boolean
16
+ ctrl: boolean
17
+ meta: boolean
18
+ alt: boolean
19
+ }
20
+ }
15
21
  }
16
22
 
17
23
  /**
@@ -118,7 +124,11 @@ export const checkable: SpliceTreePlugin = {
118
124
  * 勾选/半选插件:支持向下级联与向上计算半选
119
125
  */
120
126
  setup(ctx: SpliceTreePluginContext) {
121
- const { defaultChecked = [] } = ctx.options
127
+ const cfg = (ctx.options?.configuration?.checkable ?? {}) as {
128
+ defaultChecked?: string[]
129
+ triggerByClick?: boolean
130
+ }
131
+ const { defaultChecked = [] } = cfg
122
132
 
123
133
  const checkedKeys = new Set<string>(defaultChecked)
124
134
  const indeterminateKeys = new Set<string>()
@@ -207,7 +217,18 @@ export const checkable: SpliceTreePlugin = {
207
217
  check(id)
208
218
  }
209
219
  ctx.events.emit({ name: 'visibility', keys: ctx.tree.expandedKeys() })
210
- ctx.events.emit({ name: 'checked', keys: Array.from(checkedKeys) } as any)
220
+ ctx.events.emit({ name: 'checked', keys: Array.from(checkedKeys) })
221
+
222
+ const triggerByClick = !!cfg?.triggerByClick
223
+ if (triggerByClick) {
224
+ ctx.events.on('input:node-click', (p) => {
225
+ const nodeId = (p as any).nodeId as string
226
+ if (!ctx.tree.getNode(nodeId)) {
227
+ return
228
+ }
229
+ toggleCheck(nodeId)
230
+ })
231
+ }
211
232
 
212
233
  return {
213
234
  checkedKeys,