@flowgram-vue/fixed-drag-plugin 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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ Copyright (c) 2026 Crayon
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var renderer = require('@flowgram-vue/renderer');
4
+ var core = require('@flowgram-vue/core');
5
+
6
+ // src/create-fixed-drag-plugin.ts
7
+ var createFixedDragPlugin = core.definePluginCreator({
8
+ onInit(ctx, opts) {
9
+ if (opts.enable !== false) {
10
+ ctx.playground.registerLayer(renderer.FlowDragLayer, {
11
+ onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : void 0,
12
+ canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : void 0
13
+ });
14
+ }
15
+ }
16
+ });
17
+ function useStartDragNode() {
18
+ const playground = core.usePlayground();
19
+ const dragLayer = playground.getLayer(renderer.FlowDragLayer);
20
+ return {
21
+ startDrag: dragLayer ? dragLayer.startDrag.bind(dragLayer) : (_e) => {
22
+ },
23
+ dragOffset: dragLayer ? dragLayer.dragOffset : {
24
+ x: 0,
25
+ y: 0
26
+ }
27
+ };
28
+ }
29
+
30
+ exports.createFixedDragPlugin = createFixedDragPlugin;
31
+ exports.useStartDragNode = useStartDragNode;
32
+ //# sourceMappingURL=index.cjs.map
33
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/create-fixed-drag-plugin.ts","../src/hooks/use-start-drag-node.ts"],"names":["definePluginCreator","FlowDragLayer","usePlayground"],"mappings":";;;;;;AAuCO,IAAM,wBAAwBA,wBAAA,CAA0C;AAAA,EAC7E,MAAA,CAAO,KAAK,IAAA,EAAY;AAEtB,IAAA,IAAI,IAAA,CAAK,WAAW,KAAA,EAAO;AACzB,MAAA,GAAA,CAAI,UAAA,CAAW,cAAcC,sBAAA,EAAe;AAAA,QAC1C,MAAA,EAAQ,KAAK,MAAA,GAAS,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA,EAAM,GAAG,CAAA,GAAI,MAAA;AAAA,QACpD,OAAA,EAAS,KAAK,OAAA,GAAU,IAAA,CAAK,QAAQ,IAAA,CAAK,IAAA,EAAM,GAAG,CAAA,GAAI;AAAA,OACxD,CAAA;AAAA,IACH;AAAA,EACF;AACF,CAAC;ACzCM,SAAS,gBAAA,GAAmB;AACjC,EAAA,MAAM,aAAaC,kBAAA,EAAc;AAEjC,EAAA,MAAM,SAAA,GAAY,UAAA,CAAW,QAAA,CAASD,sBAAa,CAAA;AAEnD,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,YAAY,SAAA,CAAU,SAAA,CAAU,KAAK,SAAS,CAAA,GAAI,CAAC,EAAA,KAAgB;AAAA,IAAC,CAAA;AAAA,IAC/E,UAAA,EAAY,SAAA,GACR,SAAA,CAAU,UAAA,GACV;AAAA,MACA,CAAA,EAAG,CAAA;AAAA,MACH,CAAA,EAAG;AAAA;AACL,GACJ;AACF","file":"index.cjs","sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { type Xor } from '@flowgram-vue/utils';\nimport { FlowDragLayer } from '@flowgram-vue/renderer';\nimport { FlowNodeEntity, FlowNodeJSON } from '@flowgram-vue/document';\nimport { definePluginCreator, PluginContext } from '@flowgram-vue/core';\n\n// import { SelectorBounds } from './selector-bounds';\n\nexport interface FixDragPluginOptions<CTX extends PluginContext = PluginContext> {\n enable?: boolean;\n /**\n * Callback when drag drop\n */\n onDrop?: (ctx: CTX, dropData: { dragNodes: FlowNodeEntity[]; dropNode: FlowNodeEntity }) => void;\n /**\n * Check can drop\n * @param ctx\n * @param dropData\n */\n canDrop?: (\n ctx: CTX,\n dropData: {\n dropNode: FlowNodeEntity;\n isBranch?: boolean;\n } & Xor<\n {\n dragNodes: FlowNodeEntity[];\n },\n {\n dragJSON: FlowNodeJSON;\n }\n >\n ) => boolean;\n}\n\nexport const createFixedDragPlugin = definePluginCreator<FixDragPluginOptions>({\n onInit(ctx, opts): void {\n // 默认可用,所以强制判断 false\n if (opts.enable !== false) {\n ctx.playground.registerLayer(FlowDragLayer, {\n onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : undefined,\n canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : undefined,\n });\n }\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { usePlayground } from '@flowgram-vue/core';\nimport { FlowDragLayer } from '@flowgram-vue/renderer';\n\nexport function useStartDragNode() {\n const playground = usePlayground();\n\n const dragLayer = playground.getLayer(FlowDragLayer);\n\n return {\n startDrag: dragLayer ? dragLayer.startDrag.bind(dragLayer) : (_e: unknown) => {},\n dragOffset: dragLayer\n ? dragLayer.dragOffset\n : {\n x: 0,\n y: 0,\n },\n };\n}\n"]}
@@ -0,0 +1,65 @@
1
+ import * as _flowgram_vue_core from '@flowgram-vue/core';
2
+ import { PluginContext } from '@flowgram-vue/core';
3
+ import { Xor } from '@flowgram-vue/utils';
4
+ import * as _flowgram_vue_document from '@flowgram-vue/document';
5
+ import { FlowNodeEntity, FlowNodeJSON } from '@flowgram-vue/document';
6
+
7
+ interface FixDragPluginOptions<CTX extends PluginContext = PluginContext> {
8
+ enable?: boolean;
9
+ /**
10
+ * Callback when drag drop
11
+ */
12
+ onDrop?: (ctx: CTX, dropData: {
13
+ dragNodes: FlowNodeEntity[];
14
+ dropNode: FlowNodeEntity;
15
+ }) => void;
16
+ /**
17
+ * Check can drop
18
+ * @param ctx
19
+ * @param dropData
20
+ */
21
+ canDrop?: (ctx: CTX, dropData: {
22
+ dropNode: FlowNodeEntity;
23
+ isBranch?: boolean;
24
+ } & Xor<{
25
+ dragNodes: FlowNodeEntity[];
26
+ }, {
27
+ dragJSON: FlowNodeJSON;
28
+ }>) => boolean;
29
+ }
30
+ declare const createFixedDragPlugin: _flowgram_vue_core.PluginCreator<FixDragPluginOptions<PluginContext>>;
31
+
32
+ /**
33
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
34
+ * SPDX-License-Identifier: MIT
35
+ */
36
+ declare function useStartDragNode(): {
37
+ startDrag: ((e: {
38
+ clientX: number;
39
+ clientY: number;
40
+ }, { dragStartEntity: startEntityFromProps, dragEntities, dragJSON, isBranch, onCreateNode, }: {
41
+ dragEntities?: _flowgram_vue_document.FlowNodeEntity[];
42
+ } & (({
43
+ dragStartEntity?: undefined;
44
+ } & {
45
+ dragJSON: _flowgram_vue_document.FlowNodeJSON;
46
+ isBranch?: boolean;
47
+ onCreateNode: (json: _flowgram_vue_document.FlowNodeJSON, dropEntity: _flowgram_vue_document.FlowNodeEntity) => Promise<_flowgram_vue_document.FlowNodeEntity>;
48
+ }) | ({
49
+ isBranch?: undefined;
50
+ dragJSON?: undefined;
51
+ onCreateNode?: undefined;
52
+ } & {
53
+ dragStartEntity: _flowgram_vue_document.FlowNodeEntity;
54
+ })), options?: {
55
+ dragOffsetX?: number;
56
+ dragOffsetY?: number;
57
+ disableDragScroll?: boolean;
58
+ }) => Promise<void>) | ((_e: unknown) => void);
59
+ dragOffset: {
60
+ x: number;
61
+ y: number;
62
+ };
63
+ };
64
+
65
+ export { type FixDragPluginOptions, createFixedDragPlugin, useStartDragNode };
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { FlowDragLayer } from '@flowgram-vue/renderer';
2
+ import { definePluginCreator, usePlayground } from '@flowgram-vue/core';
3
+
4
+ // src/create-fixed-drag-plugin.ts
5
+ var createFixedDragPlugin = definePluginCreator({
6
+ onInit(ctx, opts) {
7
+ if (opts.enable !== false) {
8
+ ctx.playground.registerLayer(FlowDragLayer, {
9
+ onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : void 0,
10
+ canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : void 0
11
+ });
12
+ }
13
+ }
14
+ });
15
+ function useStartDragNode() {
16
+ const playground = usePlayground();
17
+ const dragLayer = playground.getLayer(FlowDragLayer);
18
+ return {
19
+ startDrag: dragLayer ? dragLayer.startDrag.bind(dragLayer) : (_e) => {
20
+ },
21
+ dragOffset: dragLayer ? dragLayer.dragOffset : {
22
+ x: 0,
23
+ y: 0
24
+ }
25
+ };
26
+ }
27
+
28
+ export { createFixedDragPlugin, useStartDragNode };
29
+ //# sourceMappingURL=index.js.map
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/create-fixed-drag-plugin.ts","../src/hooks/use-start-drag-node.ts"],"names":["FlowDragLayer"],"mappings":";;;;AAuCO,IAAM,wBAAwB,mBAAA,CAA0C;AAAA,EAC7E,MAAA,CAAO,KAAK,IAAA,EAAY;AAEtB,IAAA,IAAI,IAAA,CAAK,WAAW,KAAA,EAAO;AACzB,MAAA,GAAA,CAAI,UAAA,CAAW,cAAc,aAAA,EAAe;AAAA,QAC1C,MAAA,EAAQ,KAAK,MAAA,GAAS,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA,EAAM,GAAG,CAAA,GAAI,MAAA;AAAA,QACpD,OAAA,EAAS,KAAK,OAAA,GAAU,IAAA,CAAK,QAAQ,IAAA,CAAK,IAAA,EAAM,GAAG,CAAA,GAAI;AAAA,OACxD,CAAA;AAAA,IACH;AAAA,EACF;AACF,CAAC;ACzCM,SAAS,gBAAA,GAAmB;AACjC,EAAA,MAAM,aAAa,aAAA,EAAc;AAEjC,EAAA,MAAM,SAAA,GAAY,UAAA,CAAW,QAAA,CAASA,aAAa,CAAA;AAEnD,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,YAAY,SAAA,CAAU,SAAA,CAAU,KAAK,SAAS,CAAA,GAAI,CAAC,EAAA,KAAgB;AAAA,IAAC,CAAA;AAAA,IAC/E,UAAA,EAAY,SAAA,GACR,SAAA,CAAU,UAAA,GACV;AAAA,MACA,CAAA,EAAG,CAAA;AAAA,MACH,CAAA,EAAG;AAAA;AACL,GACJ;AACF","file":"index.js","sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { type Xor } from '@flowgram-vue/utils';\nimport { FlowDragLayer } from '@flowgram-vue/renderer';\nimport { FlowNodeEntity, FlowNodeJSON } from '@flowgram-vue/document';\nimport { definePluginCreator, PluginContext } from '@flowgram-vue/core';\n\n// import { SelectorBounds } from './selector-bounds';\n\nexport interface FixDragPluginOptions<CTX extends PluginContext = PluginContext> {\n enable?: boolean;\n /**\n * Callback when drag drop\n */\n onDrop?: (ctx: CTX, dropData: { dragNodes: FlowNodeEntity[]; dropNode: FlowNodeEntity }) => void;\n /**\n * Check can drop\n * @param ctx\n * @param dropData\n */\n canDrop?: (\n ctx: CTX,\n dropData: {\n dropNode: FlowNodeEntity;\n isBranch?: boolean;\n } & Xor<\n {\n dragNodes: FlowNodeEntity[];\n },\n {\n dragJSON: FlowNodeJSON;\n }\n >\n ) => boolean;\n}\n\nexport const createFixedDragPlugin = definePluginCreator<FixDragPluginOptions>({\n onInit(ctx, opts): void {\n // 默认可用,所以强制判断 false\n if (opts.enable !== false) {\n ctx.playground.registerLayer(FlowDragLayer, {\n onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : undefined,\n canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : undefined,\n });\n }\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { usePlayground } from '@flowgram-vue/core';\nimport { FlowDragLayer } from '@flowgram-vue/renderer';\n\nexport function useStartDragNode() {\n const playground = usePlayground();\n\n const dragLayer = playground.getLayer(FlowDragLayer);\n\n return {\n startDrag: dragLayer ? dragLayer.startDrag.bind(dragLayer) : (_e: unknown) => {},\n dragOffset: dragLayer\n ? dragLayer.dragOffset\n : {\n x: 0,\n y: 0,\n },\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@flowgram-vue/fixed-drag-plugin",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "homepage": "https://flowgram.ai/",
6
+ "repository": "https://github.com/Crayon-hua/flowgram-vue",
7
+ "license": "MIT",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "src",
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "inversify": "^6.0.1",
24
+ "reflect-metadata": "~0.2.2",
25
+ "@flowgram-vue/core": "0.2.0",
26
+ "@flowgram-vue/document": "0.2.0",
27
+ "@flowgram-vue/renderer": "0.2.0",
28
+ "@flowgram-vue/utils": "0.2.0"
29
+ },
30
+ "peerDependencies": {
31
+ "vue": "^3.3.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20",
35
+ "@vitest/coverage-v8": "^3.2.4",
36
+ "eslint": "^9.0.0",
37
+ "jsdom": "^26.1.0",
38
+ "typescript": "^5.8.3",
39
+ "vitest": "^3.2.4",
40
+ "vue": "^3.5.18",
41
+ "@flowgram-vue/ts-config": "0.2.0",
42
+ "@flowgram-vue/build-config": "0.2.0",
43
+ "@flowgram-vue/eslint-config": "0.2.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "registry": "https://registry.npmjs.org/"
48
+ },
49
+ "scripts": {
50
+ "build": "flowgram-build",
51
+ "test": "vitest run --passWithNoTests",
52
+ "test:cov": "vitest run --coverage --passWithNoTests",
53
+ "lint": "eslint .",
54
+ "ts-check": "tsc --noEmit",
55
+ "type-check": "tsc --noEmit",
56
+ "build:fast": "flowgram-build --fast",
57
+ "build:watch": "flowgram-build --watch"
58
+ }
59
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { type Xor } from '@flowgram-vue/utils';
7
+ import { FlowDragLayer } from '@flowgram-vue/renderer';
8
+ import { FlowNodeEntity, FlowNodeJSON } from '@flowgram-vue/document';
9
+ import { definePluginCreator, PluginContext } from '@flowgram-vue/core';
10
+
11
+ // import { SelectorBounds } from './selector-bounds';
12
+
13
+ export interface FixDragPluginOptions<CTX extends PluginContext = PluginContext> {
14
+ enable?: boolean;
15
+ /**
16
+ * Callback when drag drop
17
+ */
18
+ onDrop?: (ctx: CTX, dropData: { dragNodes: FlowNodeEntity[]; dropNode: FlowNodeEntity }) => void;
19
+ /**
20
+ * Check can drop
21
+ * @param ctx
22
+ * @param dropData
23
+ */
24
+ canDrop?: (
25
+ ctx: CTX,
26
+ dropData: {
27
+ dropNode: FlowNodeEntity;
28
+ isBranch?: boolean;
29
+ } & Xor<
30
+ {
31
+ dragNodes: FlowNodeEntity[];
32
+ },
33
+ {
34
+ dragJSON: FlowNodeJSON;
35
+ }
36
+ >
37
+ ) => boolean;
38
+ }
39
+
40
+ export const createFixedDragPlugin = definePluginCreator<FixDragPluginOptions>({
41
+ onInit(ctx, opts): void {
42
+ // 默认可用,所以强制判断 false
43
+ if (opts.enable !== false) {
44
+ ctx.playground.registerLayer(FlowDragLayer, {
45
+ onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : undefined,
46
+ canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : undefined,
47
+ });
48
+ }
49
+ },
50
+ });
package/src/env.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ declare module '*.vue' {
7
+ import type { DefineComponent } from 'vue';
8
+ const component: DefineComponent<object, object, unknown>;
9
+ export default component;
10
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { usePlayground } from '@flowgram-vue/core';
7
+ import { FlowDragLayer } from '@flowgram-vue/renderer';
8
+
9
+ export function useStartDragNode() {
10
+ const playground = usePlayground();
11
+
12
+ const dragLayer = playground.getLayer(FlowDragLayer);
13
+
14
+ return {
15
+ startDrag: dragLayer ? dragLayer.startDrag.bind(dragLayer) : (_e: unknown) => {},
16
+ dragOffset: dragLayer
17
+ ? dragLayer.dragOffset
18
+ : {
19
+ x: 0,
20
+ y: 0,
21
+ },
22
+ };
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export * from './create-fixed-drag-plugin';
7
+ export { useStartDragNode } from './hooks/use-start-drag-node';