@splicetree/plugin-pointer 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 ADDED
@@ -0,0 +1,9 @@
1
+ # @splicetree/plugin-pointer
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ### @splicetree/plugin-pointer
8
+ - 新增输入插件,采集节点点击事件并派发 `input:node-click`
9
+ - 事件负载包含修饰键:`shift/ctrl/meta/alt`
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Michael Cocova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @splicetree/plugin-pointer
2
+
3
+ 采集节点点击事件,统一派发 `input:node-click` 语义事件,供行为插件消费(如 `@splicetree/plugin-selectable`、`@splicetree/plugin-checkable`)。
4
+
5
+ [![version](https://img.shields.io/npm/v/@splicetree/plugin-pointer.svg?label=version)](https://www.npmjs.com/package/@splicetree/plugin-pointer)
6
+ [![downloads](https://img.shields.io/npm/dm/@splicetree/plugin-pointer.svg)](https://npmcharts.com/compare/%40splicetree%2Fplugin-pointer?minimal=true)
7
+ [![license](https://img.shields.io/npm/l/@splicetree/plugin-pointer.svg)](https://www.npmjs.com/package/@splicetree/plugin-pointer)
8
+ [![Website](https://img.shields.io/static/v1?label=Website&message=splicetree.dev&color=blue)](https://www.splicetree.dev)
9
+ [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=splicetree%2Fsplicetree&logo=github)](https://github.com/michaelcocova/splicetree)
10
+
11
+ ## 安装
12
+
13
+ `pnpm add @splicetree/plugin-pointer`
14
+
15
+ ## 使用
16
+
17
+ ```ts
18
+ import { createSpliceTree } from '@splicetree/core'
19
+ import pointer from '@splicetree/plugin-pointer'
20
+
21
+ const tree = createSpliceTree(data, {
22
+ plugins: [pointer],
23
+ })
24
+
25
+ // 在视图中调用
26
+ // onClick(nodeId, e) 会派发 input:node-click 事件(包含修饰键)
27
+ tree.onClick('a', mouseEvent)
28
+ ```
29
+
30
+ ## Api
31
+
32
+ - 事件派发
33
+ - `onClick(nodeId, e: MouseEvent)` 派发 `input:node-click`
34
+ - 事件负载
35
+ - `nodeId: string`
36
+ - `modifiers: { shift: boolean; ctrl: boolean; meta: boolean; alt: boolean }`
@@ -0,0 +1,23 @@
1
+ import { SpliceTreePlugin } from "@splicetree/core";
2
+
3
+ //#region src/index.d.ts
4
+ interface Modifiers {
5
+ shift: boolean;
6
+ ctrl: boolean;
7
+ meta: boolean;
8
+ alt: boolean;
9
+ }
10
+ declare module '@splicetree/core' {
11
+ interface SpliceTreeEventPayloadMap {
12
+ 'input:node-click': {
13
+ nodeId: string;
14
+ modifiers: Modifiers;
15
+ };
16
+ }
17
+ interface SpliceTreeInstance {
18
+ onClick: (nodeId: string, e: MouseEvent) => void;
19
+ }
20
+ }
21
+ declare const pointerPlugin: SpliceTreePlugin;
22
+ //#endregion
23
+ export { pointerPlugin as default, pointerPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ //#region src/index.ts
2
+ function getModifiers(e) {
3
+ return {
4
+ shift: e.shiftKey,
5
+ ctrl: e.ctrlKey,
6
+ meta: e.metaKey,
7
+ alt: e.altKey
8
+ };
9
+ }
10
+ const pointerPlugin = {
11
+ name: "pointer",
12
+ setup(ctx) {
13
+ const onClick = (nodeId, e) => {
14
+ ctx.events.emit({
15
+ name: "input:node-click",
16
+ nodeId,
17
+ modifiers: getModifiers(e)
18
+ });
19
+ };
20
+ return { onClick };
21
+ }
22
+ };
23
+ var src_default = pointerPlugin;
24
+
25
+ //#endregion
26
+ export { src_default as default, pointerPlugin };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@splicetree/plugin-pointer",
3
+ "type": "module",
4
+ "version": "0.1.1",
5
+ "author": {
6
+ "email": "michael.cocova@gmail.com",
7
+ "name": "Michael Cocova"
8
+ },
9
+ "license": "MIT",
10
+ "homepage": "https://www.splicetree.dev",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/michaelcocova/splicetree"
14
+ },
15
+ "exports": {
16
+ ".": "./dist/index.js",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "devDependencies": {
26
+ "@splicetree/core": "0.1.1"
27
+ },
28
+ "scripts": {
29
+ "dev": "tsdown --watch",
30
+ "build": "tsdown"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+ import type { SpliceTreePlugin, SpliceTreePluginContext } from '@splicetree/core'
2
+ import '@splicetree/core'
3
+
4
+ interface Modifiers {
5
+ shift: boolean
6
+ ctrl: boolean
7
+ meta: boolean
8
+ alt: boolean
9
+ }
10
+
11
+ declare module '@splicetree/core' {
12
+ export interface SpliceTreeEventPayloadMap {
13
+ 'input:node-click': {
14
+ nodeId: string
15
+ modifiers: Modifiers
16
+ }
17
+ }
18
+ export interface SpliceTreeInstance {
19
+ onClick: (nodeId: string, e: MouseEvent) => void
20
+ }
21
+ }
22
+
23
+ function getModifiers(e: MouseEvent) {
24
+ return {
25
+ shift: e.shiftKey,
26
+ ctrl: e.ctrlKey,
27
+ meta: e.metaKey,
28
+ alt: e.altKey,
29
+ }
30
+ }
31
+
32
+ export const pointerPlugin: SpliceTreePlugin = {
33
+ name: 'pointer',
34
+ setup(ctx: SpliceTreePluginContext) {
35
+ const onClick = (nodeId: string, e: MouseEvent) => {
36
+ ctx.events.emit({
37
+ name: 'input:node-click',
38
+ nodeId,
39
+ modifiers: getModifiers(e),
40
+ })
41
+ }
42
+ return { onClick }
43
+ },
44
+ }
45
+
46
+ export default pointerPlugin
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'tsdown'
2
+
3
+ export default defineConfig({
4
+ clean: true,
5
+ sourcemap: false,
6
+ treeshake: true,
7
+ unused: true,
8
+ unbundle: false,
9
+ platform: 'neutral',
10
+ entry: ['./src/index.ts'],
11
+ })