@easy-editor/plugin-dashboard 1.0.1 → 1.0.3

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 CHANGED
@@ -1,9 +1,9 @@
1
- MIT License
2
-
3
- Copyright © 2024-PRESENT JinSo <https://github.com/JinSooo>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright © 2024-PRESENT JinSo <https://github.com/JinSooo>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,123 +1,123 @@
1
- # @easy-editor/plugin-dashboard
2
-
3
- Dashboard plugin for EasyEditor. This plugin provides dashboard functionality for managing elements on a canvas-like editor interface, with features like:
4
-
5
- - Element positioning and drag-and-drop
6
- - Grouping and ungrouping elements
7
- - Element layering (move to top, bottom, etc.)
8
- - Guidelines and element alignment
9
- - Visual feedback and layout management
10
-
11
- ## Features
12
-
13
- ### Positioning and Movement
14
-
15
- The dashboard plugin handles precise positioning of elements on your canvas with:
16
-
17
- - Drag-and-drop movement with position tracking
18
- - Automatic alignment guides with element snapping
19
- - Coordinate-based positioning with `x`, `y`, `width`, and `height` properties
20
-
21
- ### Element Grouping
22
-
23
- Easily organize your design by grouping elements together:
24
-
25
- | Action | Description |
26
- |--------|-------------|
27
- | Group Elements | Combine multiple elements into a single manageable group |
28
- | Ungroup | Split a group back into individual elements |
29
- | Nested Groups | Support for groups within groups |
30
-
31
- ### Element Layering
32
-
33
- Control the stacking order of elements on your dashboard:
34
-
35
- | Method | Description |
36
- |--------|-------------|
37
- | `levelTop()` | Move element to the front |
38
- | `levelBottom()` | Send element to the back |
39
- | `levelUp()` | Move element up one layer |
40
- | `levelDown()` | Move element down one layer |
41
- | `moveToLevel(level)` | Move element to a specific layer |
42
-
43
- ### Guide Lines
44
-
45
- The plugin provides smart guide lines that help with precise element alignment:
46
-
47
- - Automatic alignment to element edges and centers
48
- - Configurable guide lines at specific positions
49
- - Visual feedback during element movement
50
-
51
- ## Usage Example
52
-
53
- ```typescript
54
- import { DashboardPlugin } from '@easy-editor/plugin-dashboard';
55
-
56
- // Define your group component metadata
57
- const groupMeta = {
58
- componentName: 'Group',
59
- title: 'Group',
60
- category: 'inner',
61
- configure: {
62
- advanced: {
63
- view: GroupComponent
64
- }
65
- }
66
- };
67
-
68
- // Initialize the plugin with required configuration
69
- DashboardPlugin({
70
- group: {
71
- meta: groupMeta,
72
- initSchema: {
73
- componentName: 'Group',
74
- title: 'Group',
75
- isGroup: true,
76
- },
77
- }
78
- })
79
- ```
80
-
81
- ## Configuration Options
82
-
83
- The plugin accepts a configuration object with the following properties:
84
-
85
- ### Group Component
86
-
87
- The `group` property is required and defines how groups will be handled in the dashboard:
88
-
89
- ```typescript
90
- {
91
- group: {
92
- // Component metadata for the group
93
- meta: ComponentMetadata;
94
-
95
- // Initial schema for new groups
96
- initSchema: NodeSchema;
97
- }
98
- }
99
- ```
100
-
101
- ## API Extensions
102
-
103
- The dashboard plugin extends several core interfaces with additional methods:
104
-
105
- ### Document Extensions
106
-
107
- - `document.group(nodeIdList)` - Group multiple nodes together
108
- - `document.ungroup(group)` - Ungroup a group node
109
-
110
- ### Node Extensions
111
-
112
- - `node.isGroup` - Boolean indicating if node is a group
113
- - `node.getDashboardRect()` - Get positioning rectangle
114
- - `node.updateDashboardRect(rect)` - Update positioning
115
- - `node.getNodesInGroup()` - Get direct child nodes in a group
116
- - `node.getAllNodesInGroup()` - Get all nested nodes in a group
117
- - `node.getCurrentGroup()` - Get immediate parent group
118
- - `node.getTopGroup()` - Get top-most parent group
119
- - `node.getAllGroups()` - Get all parent groups
120
-
121
- ### Designer Extensions
122
-
123
- - `designer.guideline` - Access to guidelines functionality
1
+ # @easy-editor/plugin-dashboard
2
+
3
+ Dashboard plugin for EasyEditor. This plugin provides dashboard functionality for managing elements on a canvas-like editor interface, with features like:
4
+
5
+ - Element positioning and drag-and-drop
6
+ - Grouping and ungrouping elements
7
+ - Element layering (move to top, bottom, etc.)
8
+ - Guidelines and element alignment
9
+ - Visual feedback and layout management
10
+
11
+ ## Features
12
+
13
+ ### Positioning and Movement
14
+
15
+ The dashboard plugin handles precise positioning of elements on your canvas with:
16
+
17
+ - Drag-and-drop movement with position tracking
18
+ - Automatic alignment guides with element snapping
19
+ - Coordinate-based positioning with `x`, `y`, `width`, and `height` properties
20
+
21
+ ### Element Grouping
22
+
23
+ Easily organize your design by grouping elements together:
24
+
25
+ | Action | Description |
26
+ |--------|-------------|
27
+ | Group Elements | Combine multiple elements into a single manageable group |
28
+ | Ungroup | Split a group back into individual elements |
29
+ | Nested Groups | Support for groups within groups |
30
+
31
+ ### Element Layering
32
+
33
+ Control the stacking order of elements on your dashboard:
34
+
35
+ | Method | Description |
36
+ |--------|-------------|
37
+ | `levelTop()` | Move element to the front |
38
+ | `levelBottom()` | Send element to the back |
39
+ | `levelUp()` | Move element up one layer |
40
+ | `levelDown()` | Move element down one layer |
41
+ | `moveToLevel(level)` | Move element to a specific layer |
42
+
43
+ ### Guide Lines
44
+
45
+ The plugin provides smart guide lines that help with precise element alignment:
46
+
47
+ - Automatic alignment to element edges and centers
48
+ - Configurable guide lines at specific positions
49
+ - Visual feedback during element movement
50
+
51
+ ## Usage Example
52
+
53
+ ```typescript
54
+ import { DashboardPlugin } from '@easy-editor/plugin-dashboard';
55
+
56
+ // Define your group component metadata
57
+ const groupMeta = {
58
+ componentName: 'Group',
59
+ title: 'Group',
60
+ category: 'inner',
61
+ configure: {
62
+ advanced: {
63
+ view: GroupComponent
64
+ }
65
+ }
66
+ };
67
+
68
+ // Initialize the plugin with required configuration
69
+ DashboardPlugin({
70
+ group: {
71
+ meta: groupMeta,
72
+ initSchema: {
73
+ componentName: 'Group',
74
+ title: 'Group',
75
+ isGroup: true,
76
+ },
77
+ }
78
+ })
79
+ ```
80
+
81
+ ## Configuration Options
82
+
83
+ The plugin accepts a configuration object with the following properties:
84
+
85
+ ### Group Component
86
+
87
+ The `group` property is required and defines how groups will be handled in the dashboard:
88
+
89
+ ```typescript
90
+ {
91
+ group: {
92
+ // Component metadata for the group
93
+ meta: ComponentMetadata;
94
+
95
+ // Initial schema for new groups
96
+ initSchema: NodeSchema;
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## API Extensions
102
+
103
+ The dashboard plugin extends several core interfaces with additional methods:
104
+
105
+ ### Document Extensions
106
+
107
+ - `document.group(nodeIdList)` - Group multiple nodes together
108
+ - `document.ungroup(group)` - Ungroup a group node
109
+
110
+ ### Node Extensions
111
+
112
+ - `node.isGroup` - Boolean indicating if node is a group
113
+ - `node.getDashboardRect()` - Get positioning rectangle
114
+ - `node.updateDashboardRect(rect)` - Update positioning
115
+ - `node.getNodesInGroup()` - Get direct child nodes in a group
116
+ - `node.getAllNodesInGroup()` - Get all nested nodes in a group
117
+ - `node.getCurrentGroup()` - Get immediate parent group
118
+ - `node.getTopGroup()` - Get top-most parent group
119
+ - `node.getAllGroups()` - Get all parent groups
120
+
121
+ ### Designer Extensions
122
+
123
+ - `designer.guideline` - Access to guidelines functionality
@@ -0,0 +1,55 @@
1
+ import type { Designer } from '@easy-editor/core';
2
+ /**
3
+ * 对齐类型枚举
4
+ */
5
+ export declare enum AlignType {
6
+ LEFT = "left",
7
+ RIGHT = "right",
8
+ TOP = "top",
9
+ BOTTOM = "bottom",
10
+ HORIZONTAL_CENTER = "horizontalCenter",
11
+ VERTICAL_CENTER = "verticalCenter"
12
+ }
13
+ /**
14
+ * 分布类型枚举
15
+ */
16
+ export declare enum DistributeType {
17
+ HORIZONTAL = "horizontal",
18
+ VERTICAL = "vertical"
19
+ }
20
+ /**
21
+ * 多组件对齐功能类
22
+ */
23
+ export declare class Alignment {
24
+ readonly designer: Designer;
25
+ constructor(designer: Designer);
26
+ get selection(): import("@easy-editor/core").Selection;
27
+ /**
28
+ * 获取选中节点(排除 root)
29
+ */
30
+ private getSelectedNodes;
31
+ /**
32
+ * 计算选中组件的包围盒
33
+ */
34
+ private calculateBoundingBox;
35
+ /**
36
+ * 更新节点位置(支持 Group)
37
+ */
38
+ private updateNodePosition;
39
+ /**
40
+ * 执行对齐操作
41
+ */
42
+ align(type: AlignType): boolean;
43
+ /**
44
+ * 执行分布操作
45
+ */
46
+ distribute(type: DistributeType): boolean;
47
+ alignLeft: () => boolean;
48
+ alignRight: () => boolean;
49
+ alignTop: () => boolean;
50
+ alignBottom: () => boolean;
51
+ alignHorizontalCenter: () => boolean;
52
+ alignVerticalCenter: () => boolean;
53
+ distributeHorizontal: () => boolean;
54
+ distributeVertical: () => boolean;
55
+ }
@@ -5,6 +5,14 @@ interface GuideLineItem {
5
5
  type: GuideLineType;
6
6
  position: number;
7
7
  }
8
+ /**
9
+ * 用户辅助线项(从游尺添加)
10
+ */
11
+ export interface UserGuideLineItem {
12
+ id: string;
13
+ type: GuideLineType;
14
+ position: number;
15
+ }
8
16
  interface AlignmentLine {
9
17
  type: GuideLineType;
10
18
  position: number;
@@ -19,6 +27,32 @@ interface AdsorptionLine {
19
27
  adsorption: number;
20
28
  position: number;
21
29
  }
30
+ /**
31
+ * 距离线段信息(用于渲染组件间的距离指示器)
32
+ */
33
+ export interface DistanceSegment {
34
+ /** 距离值(像素) */
35
+ distance: number;
36
+ /** 线段起点坐标 */
37
+ start: number;
38
+ /** 线段终点坐标 */
39
+ end: number;
40
+ /** 线段的固定坐标位置(垂直距离线段的 x 坐标,水平距离线段的 y 坐标) */
41
+ fixedPos: number;
42
+ /** 标签中心位置 */
43
+ labelPos: number;
44
+ }
45
+ /**
46
+ * 吸附辅助线信息(带距离标签)
47
+ */
48
+ export interface AdsorptionLineInfo {
49
+ /** 辅助线位置 */
50
+ position: number;
51
+ /** 辅助线类型 */
52
+ type: 'vertical' | 'horizontal';
53
+ /** 距离线段列表(可能有多个方向的距离) */
54
+ distanceSegments?: DistanceSegment[];
55
+ }
22
56
  export declare class GuideLine {
23
57
  readonly designer: Designer;
24
58
  /**
@@ -47,6 +81,18 @@ export declare class GuideLine {
47
81
  verticalLines: Set<number>;
48
82
  horizontalLines: Set<number>;
49
83
  };
84
+ /**
85
+ * 带距离标签的吸附辅助线信息
86
+ */
87
+ accessor adsorptionLinesWithDistance: AdsorptionLineInfo[];
88
+ /**
89
+ * 用户辅助线(从游尺添加)
90
+ */
91
+ accessor userGuideLines: UserGuideLineItem[];
92
+ /**
93
+ * 用户辅助线 ID 计数器
94
+ */
95
+ private userGuideLineIdCounter;
50
96
  get currentDocument(): import("@easy-editor/core").Document | undefined;
51
97
  constructor(designer: Designer);
52
98
  /**
@@ -61,6 +107,29 @@ export declare class GuideLine {
61
107
  * 修改辅助线
62
108
  */
63
109
  updateGuideLine(id: string, guideLine: GuideLineItem): void;
110
+ /**
111
+ * 获取用户辅助线的计算映射
112
+ */
113
+ get userGuideLinesMap(): {
114
+ verticalLinesMap: Map<number, UserGuideLineItem>;
115
+ horizontalLinesMap: Map<number, UserGuideLineItem>;
116
+ };
117
+ /**
118
+ * 添加用户辅助线(从游尺添加)
119
+ */
120
+ addUserGuideLine(type: GuideLineType, position: number): UserGuideLineItem;
121
+ /**
122
+ * 更新用户辅助线位置
123
+ */
124
+ updateUserGuideLine(id: string, position: number): void;
125
+ /**
126
+ * 删除用户辅助线
127
+ */
128
+ removeUserGuideLine(id: string): void;
129
+ /**
130
+ * 清空所有用户辅助线
131
+ */
132
+ clearUserGuideLines(): void;
64
133
  /**
65
134
  * 计算页面组件的辅助线信息
66
135
  */
@@ -69,6 +138,11 @@ export declare class GuideLine {
69
138
  * 组件的吸附距离
70
139
  */
71
140
  private adsorptionSize;
141
+ /**
142
+ * 距离线段显示的最大距离阈值
143
+ * 只有当组件间距离在 [adsorptionSize, maxDistanceDisplay] 范围内才显示距离线段
144
+ */
145
+ private maxDistanceDisplay;
72
146
  /**
73
147
  * 设置画布上要实时展示的对齐辅助线,返回要吸附的距离
74
148
  * @param rect 为拖动过程中组件的位置信息
@@ -82,5 +156,24 @@ export declare class GuideLine {
82
156
  adsorb: Record<"x" | "y", AdsorptionLine | undefined>;
83
157
  };
84
158
  resetAdsorptionLines(): void;
159
+ /**
160
+ * 计算垂直辅助线上的距离线段(当前组件与对齐组件之间的垂直距离)
161
+ * 返回所有方向的距离线段
162
+ */
163
+ private calculateVerticalLineSegments;
164
+ /**
165
+ * 计算水平辅助线上的距离线段(当前组件与对齐组件之间的水平距离)
166
+ * 返回所有方向的距离线段
167
+ */
168
+ private calculateHorizontalLineSegments;
169
+ /**
170
+ * 获取所有选中节点的 ID(包括组合内的节点)
171
+ */
172
+ private getSelectedNodeIds;
173
+ /**
174
+ * 判断距离是否在显示范围内
175
+ * 范围:[adsorptionSize, maxDistanceDisplay]
176
+ */
177
+ private isDistanceInDisplayRange;
85
178
  }
86
179
  export {};
@@ -0,0 +1,38 @@
1
+ import { type Designer, type Viewport } from '@easy-editor/core';
2
+ export interface MarqueeRect {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export interface MarqueeEvent {
9
+ startX: number;
10
+ startY: number;
11
+ currentX: number;
12
+ currentY: number;
13
+ rect: MarqueeRect;
14
+ isCtrlPressed: boolean;
15
+ }
16
+ /**
17
+ * 框选引擎
18
+ * 用于在画布空白区域拖拽框选多个组件
19
+ */
20
+ export declare class MarqueeSelection {
21
+ readonly designer: Designer;
22
+ private emitter;
23
+ private isMarqueeSelecting;
24
+ enabled: boolean;
25
+ constructor(designer: Designer);
26
+ isSelecting(): boolean;
27
+ /**
28
+ * 绑定框选事件到指定元素
29
+ * @param shell 画布容器元素
30
+ * @param viewport 视口对象,用于坐标转换
31
+ * @param isClickOnNode 检测点击是否在节点上的函数
32
+ */
33
+ from(shell: HTMLElement, viewport: Viewport, isClickOnNode: (target: Element) => boolean): () => void;
34
+ onMarqueeStart(func: (evt: MarqueeEvent) => void): () => void;
35
+ onMarquee(func: (evt: MarqueeEvent) => void): () => void;
36
+ onMarqueeEnd(func: (evt: MarqueeEvent) => void): () => void;
37
+ private getMasterSensors;
38
+ }