@splicetree/plugin-dnd 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,15 @@
1
1
  # @splicetree/plugin-dnd
2
2
 
3
- ## 0.0.1
3
+ ## 0.1.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - chore: 搭建 SpliceTree 框架基础架构与工程体系
7
+ - fix: republish plugin-dnd 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-dnd
2
2
 
3
+ 为树节点提供拖拽移动能力,支持插入到目标之前、之后或作为子节点。
4
+
3
5
  [![version](https://img.shields.io/npm/v/@splicetree/plugin-dnd.svg?label=version)](https://www.npmjs.com/package/@splicetree/plugin-dnd)
4
6
  [![downloads](https://img.shields.io/npm/dm/@splicetree/plugin-dnd.svg)](https://npmcharts.com/compare/%40splicetree%2Fplugin-dnd?minimal=true)
5
7
  [![license](https://img.shields.io/npm/l/@splicetree/plugin-dnd.svg)](https://www.npmjs.com/package/@splicetree/plugin-dnd)
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-dnd`
package/dist/index.d.ts CHANGED
@@ -14,22 +14,11 @@ declare enum DropPosition {
14
14
  AFTER = 1,
15
15
  }
16
16
  declare module '@splicetree/core' {
17
- /**
18
- * 插件配置项扩展(DnD)
19
- */
20
- interface UseSpliceTreeOptions {
21
- /**
22
- * 自动更新父节点
23
- * 如果为 false,则不会自动更新父节点
24
- * 需要监听 move 事件,手动更新父节点
25
- * @default true
26
- */
27
- autoUpdateParent?: boolean;
28
- /**
29
- * 拖入后自动展开目标节点
30
- * @default true
31
- */
32
- autoExpandOnDrop?: boolean;
17
+ interface SpliceTreeConfiguration {
18
+ dnd?: {
19
+ autoUpdateParent?: boolean;
20
+ autoExpandOnDrop?: boolean;
21
+ };
33
22
  }
34
23
  interface SpliceTreeEventPayloadMap {
35
24
  /**
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ let DropPosition = /* @__PURE__ */ function(DropPosition$1) {
14
14
  const dnd = {
15
15
  name: "dnd",
16
16
  setup(ctx) {
17
- const { autoUpdateParent = true, autoExpandOnDrop = true } = ctx.tree.options || {};
17
+ const { autoUpdateParent = true, autoExpandOnDrop = true } = ctx.options?.configuration?.dnd ?? {};
18
18
  const parentField = ctx.tree.options?.parentField ?? "parent";
19
19
  let draggingId;
20
20
  const hoverPositions = /* @__PURE__ */ new Map();
@@ -125,8 +125,9 @@ const dnd = {
125
125
  });
126
126
  return;
127
127
  }
128
- const siblings = parentId ? ctx.tree.getNode(parentId).getChildren() : ctx.tree.items().filter((n) => !n.getParent());
129
- const afterSibling = siblings[siblings.findIndex((n) => n.id === targetId) + 1]?.id;
128
+ const siblings = (parentId ? ctx.tree.getNode(parentId).getChildren() : ctx.tree.items().filter((n) => !n.getParent())).filter((n) => n.id !== srcId);
129
+ const idx = siblings.findIndex((n) => n.id === targetId);
130
+ const afterSibling = idx >= 0 ? siblings[idx + 1]?.id : void 0;
130
131
  if (autoUpdateParent) {
131
132
  ctx.tree.moveNode(srcId, parentId, afterSibling);
132
133
  Reflect.set(src.original, parentField, parentId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/plugin-dnd",
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
@@ -13,23 +13,11 @@ export enum DropPosition {
13
13
  AFTER = 1,
14
14
  }
15
15
  declare module '@splicetree/core' {
16
- /**
17
- * 插件配置项扩展(DnD)
18
- */
19
-
20
- interface UseSpliceTreeOptions {
21
- /**
22
- * 自动更新父节点
23
- * 如果为 false,则不会自动更新父节点
24
- * 需要监听 move 事件,手动更新父节点
25
- * @default true
26
- */
27
- autoUpdateParent?: boolean
28
- /**
29
- * 拖入后自动展开目标节点
30
- * @default true
31
- */
32
- autoExpandOnDrop?: boolean
16
+ interface SpliceTreeConfiguration {
17
+ dnd?: {
18
+ autoUpdateParent?: boolean
19
+ autoExpandOnDrop?: boolean
20
+ }
33
21
  }
34
22
  interface SpliceTreeEventPayloadMap {
35
23
  /**
@@ -125,7 +113,11 @@ export const dnd: SpliceTreePlugin = {
125
113
  * - 通过 events 派发 move 与 visibility 事件驱动视图刷新
126
114
  */
127
115
  setup(ctx: SpliceTreePluginContext) {
128
- const { autoUpdateParent = true, autoExpandOnDrop = true } = ctx.tree.options || {}
116
+ const cfg = (ctx.options?.configuration?.dnd ?? {}) as {
117
+ autoUpdateParent?: boolean
118
+ autoExpandOnDrop?: boolean
119
+ }
120
+ const { autoUpdateParent = true, autoExpandOnDrop = true } = cfg
129
121
  const parentField = ctx.tree.options?.parentField ?? 'parent'
130
122
  let draggingId: string | undefined
131
123
  const hoverPositions = new Map<string, DropPosition>()
@@ -239,9 +231,10 @@ export const dnd: SpliceTreePlugin = {
239
231
  return
240
232
  }
241
233
 
242
- const siblings = parentId ? ctx.tree.getNode(parentId)!.getChildren() : ctx.tree.items().filter(n => !n.getParent())
234
+ const rawSiblings = parentId ? ctx.tree.getNode(parentId)!.getChildren() : ctx.tree.items().filter(n => !n.getParent())
235
+ const siblings = rawSiblings.filter(n => n.id !== srcId)
243
236
  const idx = siblings.findIndex(n => n.id === targetId)
244
- const afterSibling = siblings[idx + 1]?.id
237
+ const afterSibling = idx >= 0 ? siblings[idx + 1]?.id : undefined
245
238
  if (autoUpdateParent) {
246
239
  ctx.tree.moveNode(srcId, parentId, afterSibling)
247
240
  Reflect.set(src.original, parentField, parentId)