@easy-editor/plugin-hotkey 0.0.14 → 1.0.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/README.md +57 -1
- package/dist/cjs/index.js +144 -117
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +144 -117
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +144 -117
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Hotkey plugin for EasyEditor.
|
|
4
4
|
|
|
5
|
-
## Hotkeys
|
|
5
|
+
## Default Hotkeys
|
|
6
6
|
|
|
7
7
|
| Action | Shortcut |
|
|
8
8
|
|--------|----------|
|
|
@@ -16,3 +16,59 @@ Hotkey plugin for EasyEditor.
|
|
|
16
16
|
| Delete | Backspace / Delete |
|
|
17
17
|
| Clear Selection | Esc |
|
|
18
18
|
|
|
19
|
+
## Customizing Hotkeys
|
|
20
|
+
|
|
21
|
+
The HotkeyPlugin now supports customizing hotkeys. You can modify the key combinations or disable specific hotkeys entirely.
|
|
22
|
+
|
|
23
|
+
### Example Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { HotkeyPlugin } from '@easy-editor/plugin-hotkey';
|
|
27
|
+
|
|
28
|
+
HotkeyPlugin({
|
|
29
|
+
config: {
|
|
30
|
+
// Change the "undo" shortcut to only use Alt+Z
|
|
31
|
+
HISTORY_UNDO: {
|
|
32
|
+
keys: ['alt+z']
|
|
33
|
+
},
|
|
34
|
+
// Disable the "show/hide" shortcut
|
|
35
|
+
SHOW_HIDE: false,
|
|
36
|
+
// Customize "delete" to use only the Delete key
|
|
37
|
+
DELETE: {
|
|
38
|
+
keys: ['del']
|
|
39
|
+
},
|
|
40
|
+
// Explicitly enable a shortcut (default is enabled)
|
|
41
|
+
COPY: true
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Configuration Options
|
|
47
|
+
|
|
48
|
+
The configuration object accepts the following hotkey actions (all lowercase):
|
|
49
|
+
|
|
50
|
+
- `HISTORY_UNDO` - Undo last action
|
|
51
|
+
- `HISTORY_REDO` - Redo last undone action
|
|
52
|
+
- `LOCK_UNLOCK` - Lock or unlock selected elements
|
|
53
|
+
- `SHOW_HIDE` - Show or hide selected elements
|
|
54
|
+
- `COPY` - Copy selected elements
|
|
55
|
+
- `PASTE` - Paste copied elements
|
|
56
|
+
- `CUT` - Cut selected elements
|
|
57
|
+
- `DELETE` - Delete selected elements
|
|
58
|
+
- `CLEAR_SELECTION` - Clear the current selection
|
|
59
|
+
|
|
60
|
+
For each action, you can provide:
|
|
61
|
+
|
|
62
|
+
- A boolean value: `true` to enable (default), `false` to disable
|
|
63
|
+
- Or an object with:
|
|
64
|
+
- `enabled` (boolean, optional) - Set to `false` to disable the hotkey, defaults to `true`
|
|
65
|
+
- `keys` (string[]) - Array of key combinations to use (replaces default keys)
|
|
66
|
+
|
|
67
|
+
### Key Combination Format
|
|
68
|
+
|
|
69
|
+
Key combinations should be specified in the format:
|
|
70
|
+
|
|
71
|
+
- Modifier keys: `ctrl`, `alt`, `shift`, `command` (or `meta`)
|
|
72
|
+
- Regular keys: letter keys (a-z), number keys (0-9), special keys (`esc`, `del`, `backspace`, etc.)
|
|
73
|
+
- Combined with `+` symbol, e.g., `ctrl+s` or `command+shift+z`
|
|
74
|
+
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,7 +28,10 @@ const isFormEvent = e => {
|
|
|
28
28
|
return false;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
const HotkeyPlugin = () => {
|
|
31
|
+
const HotkeyPlugin = (options = {}) => {
|
|
32
|
+
const {
|
|
33
|
+
config = {}
|
|
34
|
+
} = options;
|
|
32
35
|
return {
|
|
33
36
|
name: 'HotkeyPlugin',
|
|
34
37
|
deps: [],
|
|
@@ -36,134 +39,158 @@ const HotkeyPlugin = () => {
|
|
|
36
39
|
const {
|
|
37
40
|
hotkey,
|
|
38
41
|
project,
|
|
39
|
-
logger
|
|
40
|
-
designer
|
|
42
|
+
logger
|
|
41
43
|
} = ctx;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
hotkey.bind(HOTKEY_MAP.HISTORY_REDO, () => {
|
|
51
|
-
const currentHistory = project.currentDocument?.history;
|
|
52
|
-
if (currentHistory?.isRedoable()) {
|
|
53
|
-
currentHistory?.forward();
|
|
54
|
-
} else {
|
|
55
|
-
logger.log('No operations to redo');
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
hotkey.bind(HOTKEY_MAP.LOCK_UNLOCK, () => {
|
|
59
|
-
const selection = designer.selection;
|
|
60
|
-
const doc = project.currentDocument;
|
|
61
|
-
for (const nodeId of selection.selected) {
|
|
62
|
-
const node = doc?.getNode(nodeId);
|
|
63
|
-
if (node?.isLocked) {
|
|
64
|
-
node.lock(false);
|
|
65
|
-
logger.log('Lock');
|
|
44
|
+
const {
|
|
45
|
+
designer
|
|
46
|
+
} = project;
|
|
47
|
+
const handlers = {
|
|
48
|
+
HISTORY_UNDO: () => {
|
|
49
|
+
const currentHistory = project.currentDocument?.history;
|
|
50
|
+
if (currentHistory?.isUndoable()) {
|
|
51
|
+
currentHistory?.back();
|
|
66
52
|
} else {
|
|
67
|
-
|
|
68
|
-
logger.log('Unlock');
|
|
53
|
+
logger.log('No operations to undo');
|
|
69
54
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const doc = project.currentDocument;
|
|
76
|
-
for (const nodeId of selection.selected) {
|
|
77
|
-
const node = doc?.getNode(nodeId);
|
|
78
|
-
if (node?.isHidden) {
|
|
79
|
-
node.hide(false);
|
|
80
|
-
logger.log('Show');
|
|
55
|
+
},
|
|
56
|
+
HISTORY_REDO: () => {
|
|
57
|
+
const currentHistory = project.currentDocument?.history;
|
|
58
|
+
if (currentHistory?.isRedoable()) {
|
|
59
|
+
currentHistory?.forward();
|
|
81
60
|
} else {
|
|
82
|
-
|
|
83
|
-
logger.log('Hide');
|
|
61
|
+
logger.log('No operations to redo');
|
|
84
62
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const componentsTree = selected.map(item => item?.export(core.TRANSFORM_STAGE.CLONE));
|
|
98
|
-
const data = {
|
|
99
|
-
type: 'NodeSchema',
|
|
100
|
-
componentsMap: {},
|
|
101
|
-
componentsTree
|
|
102
|
-
};
|
|
103
|
-
core.clipboard.setData(data);
|
|
104
|
-
});
|
|
105
|
-
hotkey.bind(HOTKEY_MAP.CUT, e => {
|
|
106
|
-
const doc = project.currentDocument;
|
|
107
|
-
if (isFormEvent(e) || !doc) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const selection = designer.selection;
|
|
111
|
-
const selected = selection.getTopNodes(false);
|
|
112
|
-
if (!selected || selected.length < 1) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const componentsTree = selected.map(item => item?.export(core.TRANSFORM_STAGE.CLONE));
|
|
116
|
-
const data = {
|
|
117
|
-
type: 'NodeSchema',
|
|
118
|
-
componentsMap: {},
|
|
119
|
-
componentsTree
|
|
120
|
-
};
|
|
121
|
-
core.clipboard.setData(data);
|
|
122
|
-
for (const node of selected) {
|
|
123
|
-
node?.parent?.select();
|
|
124
|
-
node.remove();
|
|
125
|
-
}
|
|
126
|
-
selection.clear();
|
|
127
|
-
});
|
|
128
|
-
hotkey.bind(HOTKEY_MAP.PASTE, e => {
|
|
129
|
-
const doc = project.currentDocument;
|
|
130
|
-
const selection = designer.selection;
|
|
131
|
-
if (isFormEvent(e) || !doc) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
core.clipboard.waitPasteData(e, ({
|
|
135
|
-
componentsTree
|
|
136
|
-
}) => {
|
|
137
|
-
if (componentsTree) {
|
|
138
|
-
const target = doc?.rootNode;
|
|
139
|
-
if (!target) {
|
|
140
|
-
return;
|
|
63
|
+
},
|
|
64
|
+
LOCK_UNLOCK: () => {
|
|
65
|
+
const selection = designer.selection;
|
|
66
|
+
const doc = project.currentDocument;
|
|
67
|
+
for (const nodeId of selection.selected) {
|
|
68
|
+
const node = doc?.getNode(nodeId);
|
|
69
|
+
if (node?.isLocked) {
|
|
70
|
+
node.lock(false);
|
|
71
|
+
logger.log('Lock');
|
|
72
|
+
} else {
|
|
73
|
+
node?.lock(true);
|
|
74
|
+
logger.log('Unlock');
|
|
141
75
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
76
|
+
}
|
|
77
|
+
selection.clear();
|
|
78
|
+
},
|
|
79
|
+
SHOW_HIDE: () => {
|
|
80
|
+
const selection = designer.selection;
|
|
81
|
+
const doc = project.currentDocument;
|
|
82
|
+
for (const nodeId of selection.selected) {
|
|
83
|
+
const node = doc?.getNode(nodeId);
|
|
84
|
+
if (node?.isHidden) {
|
|
85
|
+
node.hide(false);
|
|
86
|
+
logger.log('Show');
|
|
87
|
+
} else {
|
|
88
|
+
node?.hide(true);
|
|
89
|
+
logger.log('Hide');
|
|
145
90
|
}
|
|
146
91
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
92
|
+
selection.clear();
|
|
93
|
+
},
|
|
94
|
+
COPY: e => {
|
|
95
|
+
const doc = project.currentDocument;
|
|
96
|
+
if (isFormEvent(e) || !doc) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const selected = designer.selection.getTopNodes(false);
|
|
100
|
+
if (!selected || selected.length < 1) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const componentsTree = selected.map(item => item?.export(core.TRANSFORM_STAGE.CLONE));
|
|
104
|
+
const data = {
|
|
105
|
+
type: 'NodeSchema',
|
|
106
|
+
componentsMap: {},
|
|
107
|
+
componentsTree
|
|
108
|
+
};
|
|
109
|
+
core.clipboard.setData(data);
|
|
110
|
+
},
|
|
111
|
+
CUT: e => {
|
|
112
|
+
const doc = project.currentDocument;
|
|
113
|
+
if (isFormEvent(e) || !doc) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const selection = designer.selection;
|
|
117
|
+
const selected = selection.getTopNodes(false);
|
|
118
|
+
if (!selected || selected.length < 1) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const componentsTree = selected.map(item => item?.export(core.TRANSFORM_STAGE.CLONE));
|
|
122
|
+
const data = {
|
|
123
|
+
type: 'NodeSchema',
|
|
124
|
+
componentsMap: {},
|
|
125
|
+
componentsTree
|
|
126
|
+
};
|
|
127
|
+
core.clipboard.setData(data);
|
|
128
|
+
for (const node of selected) {
|
|
129
|
+
node?.parent?.select();
|
|
130
|
+
node.remove();
|
|
131
|
+
}
|
|
132
|
+
selection.clear();
|
|
133
|
+
},
|
|
134
|
+
PASTE: e => {
|
|
135
|
+
const doc = project.currentDocument;
|
|
136
|
+
designer.selection;
|
|
137
|
+
if (isFormEvent(e) || !doc) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
core.clipboard.waitPasteData(e, ({
|
|
141
|
+
componentsTree
|
|
142
|
+
}) => {
|
|
143
|
+
if (componentsTree) {
|
|
144
|
+
const target = doc?.rootNode;
|
|
145
|
+
if (!target) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
core.insertChildren(target, componentsTree);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
DELETE: e => {
|
|
153
|
+
const doc = project.currentDocument;
|
|
154
|
+
const selection = designer.selection;
|
|
155
|
+
if (isFormEvent(e) || !doc) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const nodes = selection.getTopNodes();
|
|
159
|
+
for (const node of nodes) {
|
|
160
|
+
node && doc?.removeNode(node);
|
|
161
|
+
}
|
|
162
|
+
selection.clear();
|
|
163
|
+
},
|
|
164
|
+
CLEAR_SELECTION: e => {
|
|
165
|
+
const selection = designer.selection;
|
|
166
|
+
if (isFormEvent(e) || !selection) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
selection.clear();
|
|
154
170
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
171
|
+
};
|
|
172
|
+
Object.entries(HOTKEY_MAP).forEach(([action, defaultKeys]) => {
|
|
173
|
+
const actionKey = action;
|
|
174
|
+
const customConfig = config[actionKey];
|
|
175
|
+
let isEnabled = true;
|
|
176
|
+
let keysToUse = defaultKeys;
|
|
177
|
+
if (customConfig !== undefined) {
|
|
178
|
+
if (typeof customConfig === 'boolean') {
|
|
179
|
+
isEnabled = customConfig;
|
|
180
|
+
} else {
|
|
181
|
+
isEnabled = customConfig.enabled !== false;
|
|
182
|
+
if (customConfig.keys && customConfig.keys.length > 0) {
|
|
183
|
+
keysToUse = customConfig.keys;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
158
186
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
hotkey.bind(HOTKEY_MAP.CLEAR_SELECTION, e => {
|
|
162
|
-
const selection = designer.selection;
|
|
163
|
-
if (isFormEvent(e) || !selection) {
|
|
187
|
+
if (!isEnabled) {
|
|
188
|
+
logger.log(`Hotkey ${actionKey} is disabled`);
|
|
164
189
|
return;
|
|
165
190
|
}
|
|
166
|
-
|
|
191
|
+
if (keysToUse.length > 0 && handlers[actionKey]) {
|
|
192
|
+
hotkey.bind(keysToUse, handlers[actionKey]);
|
|
193
|
+
}
|
|
167
194
|
});
|
|
168
195
|
}
|
|
169
196
|
};
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/utils.ts","../../src/index.ts"],"sourcesContent":["export const HOTKEY_MAP = {\n /**\n * 历史记录回退\n */\n HISTORY_UNDO: ['command+z', 'ctrl+z'],\n\n /**\n * 历史记录前进\n */\n HISTORY_REDO: ['command+y', 'ctrl+y'],\n\n /**\n * 锁定/解锁\n */\n LOCK_UNLOCK: ['command+shift+l', 'ctrl+shift+l'],\n\n /**\n * 显示/隐藏\n */\n SHOW_HIDE: ['command+shift+h', 'ctrl+shift+h'],\n\n /**\n * 复制\n */\n COPY: ['command+c', 'ctrl+c'],\n\n /**\n * 粘贴\n */\n PASTE: ['command+v', 'ctrl+v'],\n\n /**\n * 剪切\n */\n CUT: ['command+x', 'ctrl+x'],\n\n /**\n * 删除\n */\n DELETE: ['backspace', 'del'],\n\n /**\n * 取消选中\n */\n CLEAR_SELECTION: ['esc'],\n}\n","/**\n * 检查事件是否由表单元素触发\n */\nexport const isFormEvent = (e: KeyboardEvent | MouseEvent) => {\n const t = e.target as HTMLFormElement\n if (!t) {\n return false\n }\n\n if (t.form || /^(INPUT|SELECT|TEXTAREA)$/.test(t.tagName)) {\n return true\n }\n if (t instanceof HTMLElement && /write/.test(window.getComputedStyle(t).getPropertyValue('-webkit-user-modify'))) {\n return true\n }\n return false\n}\n","import { type PluginCreator, TRANSFORM_STAGE, clipboard, insertChildren } from '@easy-editor/core'\nimport { HOTKEY_MAP } from './const'\nimport { isFormEvent } from './utils'\n\nconst HotkeyPlugin: PluginCreator = () => {\n return {\n name: 'HotkeyPlugin',\n deps: [],\n init(ctx) {\n const { hotkey, project, logger, designer } = ctx\n\n hotkey.bind(HOTKEY_MAP.HISTORY_UNDO, () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isUndoable()) {\n currentHistory?.back()\n } else {\n logger.log('No operations to undo')\n }\n })\n\n hotkey.bind(HOTKEY_MAP.HISTORY_REDO, () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isRedoable()) {\n currentHistory?.forward()\n } else {\n logger.log('No operations to redo')\n }\n })\n\n hotkey.bind(HOTKEY_MAP.LOCK_UNLOCK, () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isLocked) {\n node.lock(false)\n logger.log('Lock')\n } else {\n node?.lock(true)\n logger.log('Unlock')\n }\n }\n\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.SHOW_HIDE, () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isHidden) {\n node.hide(false)\n logger.log('Show')\n } else {\n node?.hide(true)\n logger.log('Hide')\n }\n }\n\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.COPY, e => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selected = designer.selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n })\n\n hotkey.bind(HOTKEY_MAP.CUT, e => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selection = designer.selection\n const selected = selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n\n for (const node of selected) {\n node?.parent?.select()\n node.remove()\n }\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.PASTE, e => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n clipboard.waitPasteData(e, ({ componentsTree }) => {\n if (componentsTree) {\n const target = doc?.rootNode\n\n if (!target) {\n return\n }\n\n const nodes = insertChildren(target, componentsTree)\n if (nodes) {\n selection.selectAll(nodes.map(o => o.id))\n }\n }\n })\n })\n\n hotkey.bind(HOTKEY_MAP.DELETE, e => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const nodes = selection.getTopNodes()\n for (const node of nodes) {\n node && doc?.removeNode(node)\n }\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.CLEAR_SELECTION, e => {\n const selection = designer.selection\n\n if (isFormEvent(e) || !selection) {\n return\n }\n\n selection.clear()\n })\n },\n }\n}\n\nexport default HotkeyPlugin\n"],"names":["HOTKEY_MAP","HISTORY_UNDO","HISTORY_REDO","LOCK_UNLOCK","SHOW_HIDE","COPY","PASTE","CUT","DELETE","CLEAR_SELECTION","isFormEvent","e","t","target","form","test","tagName","HTMLElement","window","getComputedStyle","getPropertyValue","HotkeyPlugin","name","deps","init","ctx","hotkey","project","logger","designer","bind","currentHistory","currentDocument","history","isUndoable","back","log","isRedoable","forward","selection","doc","nodeId","selected","node","getNode","isLocked","lock","clear","isHidden","hide","getTopNodes","length","componentsTree","map","item","export","TRANSFORM_STAGE","CLONE","data","type","componentsMap","clipboard","setData","parent","select","remove","waitPasteData","rootNode","nodes","insertChildren","selectAll","o","id","removeNode"],"mappings":";;;;AAAO,MAAMA,UAAU,GAAG;AAIxBC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,WAAW,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAKhDC,EAAAA,SAAS,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAK9CC,EAAAA,IAAI,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK7BC,EAAAA,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK9BC,EAAAA,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,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;AACT7B,cAAAA,SAAS,CAAC+B,SAAS,CAACF,KAAK,CAACf,GAAG,CAACkB,CAAC,IAAIA,CAAC,CAACC,EAAE,CAAC,CAAC;AAC3C;AACF;AACF,SAAC,CAAC;AACJ,OAAC,CAAC;MAEF9C,MAAM,CAACI,IAAI,CAAC9B,UAAU,CAACQ,MAAM,EAAEG,CAAC,IAAI;AAClC,QAAA,MAAM6B,GAAG,GAAGb,OAAO,CAACK,eAAe;AACnC,QAAA,MAAMO,SAAS,GAAGV,QAAQ,CAACU,SAAS;AAEpC,QAAA,IAAI7B,WAAW,CAACC,CAAC,CAAC,IAAI,CAAC6B,GAAG,EAAE;AAC1B,UAAA;AACF;AAEA,QAAA,MAAM4B,KAAK,GAAG7B,SAAS,CAACW,WAAW,EAAE;AACrC,QAAA,KAAK,MAAMP,IAAI,IAAIyB,KAAK,EAAE;AACxBzB,UAAAA,IAAI,IAAIH,GAAG,EAAEiC,UAAU,CAAC9B,IAAI,CAAC;AAC/B;QACAJ,SAAS,CAACQ,KAAK,EAAE;AACnB,OAAC,CAAC;MAEFrB,MAAM,CAACI,IAAI,CAAC9B,UAAU,CAACS,eAAe,EAAEE,CAAC,IAAI;AAC3C,QAAA,MAAM4B,SAAS,GAAGV,QAAQ,CAACU,SAAS;AAEpC,QAAA,IAAI7B,WAAW,CAACC,CAAC,CAAC,IAAI,CAAC4B,SAAS,EAAE;AAChC,UAAA;AACF;QAEAA,SAAS,CAACQ,KAAK,EAAE;AACnB,OAAC,CAAC;AACJ;GACD;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/utils.ts","../../src/index.ts"],"sourcesContent":["export const HOTKEY_MAP = {\n /**\n * 历史记录回退\n */\n HISTORY_UNDO: ['command+z', 'ctrl+z'],\n\n /**\n * 历史记录前进\n */\n HISTORY_REDO: ['command+y', 'ctrl+y'],\n\n /**\n * 锁定/解锁\n */\n LOCK_UNLOCK: ['command+shift+l', 'ctrl+shift+l'],\n\n /**\n * 显示/隐藏\n */\n SHOW_HIDE: ['command+shift+h', 'ctrl+shift+h'],\n\n /**\n * 复制\n */\n COPY: ['command+c', 'ctrl+c'],\n\n /**\n * 粘贴\n */\n PASTE: ['command+v', 'ctrl+v'],\n\n /**\n * 剪切\n */\n CUT: ['command+x', 'ctrl+x'],\n\n /**\n * 删除\n */\n DELETE: ['backspace', 'del'],\n\n /**\n * 取消选中\n */\n CLEAR_SELECTION: ['esc'],\n}\n","/**\n * 检查事件是否由表单元素触发\n */\nexport const isFormEvent = (e: KeyboardEvent | MouseEvent) => {\n const t = e.target as HTMLFormElement\n if (!t) {\n return false\n }\n\n if (t.form || /^(INPUT|SELECT|TEXTAREA)$/.test(t.tagName)) {\n return true\n }\n if (t instanceof HTMLElement && /write/.test(window.getComputedStyle(t).getPropertyValue('-webkit-user-modify'))) {\n return true\n }\n return false\n}\n","import { type PluginCreator, TRANSFORM_STAGE, clipboard, insertChildren } from '@easy-editor/core'\nimport { HOTKEY_MAP } from './const'\nimport { isFormEvent } from './utils'\n\nexport type HotkeyCustomization = {\n enabled?: boolean\n keys?: string[]\n}\n\nexport type HotkeyConfigItem = boolean | HotkeyCustomization\n\nexport type HotkeyConfig = {\n [key in keyof typeof HOTKEY_MAP]?: HotkeyConfigItem\n}\n\ninterface HotkeyPluginOptions {\n config?: HotkeyConfig\n}\n\nconst HotkeyPlugin: PluginCreator<HotkeyPluginOptions> = (options = {} as HotkeyPluginOptions) => {\n const { config = {} } = options\n\n return {\n name: 'HotkeyPlugin',\n deps: [],\n init(ctx) {\n const { hotkey, project, logger } = ctx\n const { designer } = project\n\n // Define the default handler functions\n const handlers = {\n HISTORY_UNDO: () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isUndoable()) {\n currentHistory?.back()\n } else {\n logger.log('No operations to undo')\n }\n },\n\n HISTORY_REDO: () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isRedoable()) {\n currentHistory?.forward()\n } else {\n logger.log('No operations to redo')\n }\n },\n\n LOCK_UNLOCK: () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isLocked) {\n node.lock(false)\n logger.log('Lock')\n } else {\n node?.lock(true)\n logger.log('Unlock')\n }\n }\n\n selection.clear()\n },\n\n SHOW_HIDE: () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isHidden) {\n node.hide(false)\n logger.log('Show')\n } else {\n node?.hide(true)\n logger.log('Hide')\n }\n }\n\n selection.clear()\n },\n\n COPY: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selected = designer.selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n },\n\n CUT: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selection = designer.selection\n const selected = selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n\n for (const node of selected) {\n node?.parent?.select()\n node.remove()\n }\n selection.clear()\n },\n\n PASTE: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n clipboard.waitPasteData(e, ({ componentsTree }) => {\n if (componentsTree) {\n const target = doc?.rootNode\n\n if (!target) {\n return\n }\n\n const nodes = insertChildren(target, componentsTree)\n if (nodes) {\n // Additional logic if needed\n }\n }\n })\n },\n\n DELETE: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const nodes = selection.getTopNodes()\n for (const node of nodes) {\n node && doc?.removeNode(node)\n }\n selection.clear()\n },\n\n CLEAR_SELECTION: (e: KeyboardEvent) => {\n const selection = designer.selection\n\n if (isFormEvent(e) || !selection) {\n return\n }\n\n selection.clear()\n },\n }\n\n // 根据 config 处理 hotkey 的绑定\n Object.entries(HOTKEY_MAP).forEach(([action, defaultKeys]) => {\n const actionKey = action as keyof typeof HOTKEY_MAP\n const customConfig = config[actionKey]\n\n let isEnabled = true\n let keysToUse = defaultKeys\n\n if (customConfig !== undefined) {\n if (typeof customConfig === 'boolean') {\n isEnabled = customConfig\n } else {\n isEnabled = customConfig.enabled !== false\n if (customConfig.keys && customConfig.keys.length > 0) {\n keysToUse = customConfig.keys\n }\n }\n }\n\n if (!isEnabled) {\n logger.log(`Hotkey ${actionKey} is disabled`)\n return\n }\n\n if (keysToUse.length > 0 && handlers[actionKey]) {\n hotkey.bind(keysToUse, handlers[actionKey])\n }\n })\n },\n }\n}\n\nexport default HotkeyPlugin\n"],"names":["HOTKEY_MAP","HISTORY_UNDO","HISTORY_REDO","LOCK_UNLOCK","SHOW_HIDE","COPY","PASTE","CUT","DELETE","CLEAR_SELECTION","isFormEvent","e","t","target","form","test","tagName","HTMLElement","window","getComputedStyle","getPropertyValue","HotkeyPlugin","options","config","name","deps","init","ctx","hotkey","project","logger","designer","handlers","currentHistory","currentDocument","history","isUndoable","back","log","isRedoable","forward","selection","doc","nodeId","selected","node","getNode","isLocked","lock","clear","isHidden","hide","getTopNodes","length","componentsTree","map","item","export","TRANSFORM_STAGE","CLONE","data","type","componentsMap","clipboard","setData","parent","select","remove","waitPasteData","rootNode","insertChildren","nodes","removeNode","Object","entries","forEach","action","defaultKeys","actionKey","customConfig","isEnabled","keysToUse","undefined","enabled","keys","bind"],"mappings":";;;;AAAO,MAAMA,UAAU,GAAG;AAIxBC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA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AK;YAC1C,IAAIJ,YAAY,CAACK,IAAI,IAAIL,YAAY,CAACK,IAAI,CAAC/B,MAAM,GAAG,CAAC,EAAE;cACrD4B,SAAS,GAAGF,YAAY,CAACK,IAAI;AAC/B;AACF;AACF;QAEA,IAAI,CAACJ,SAAS,EAAE;AACdlD,UAAAA,MAAM,CAACQ,GAAG,CAAC,CAAUwC,OAAAA,EAAAA,SAAS,cAAc,CAAC;AAC7C,UAAA;AACF;QAEA,IAAIG,SAAS,CAAC5B,MAAM,GAAG,CAAC,IAAIrB,QAAQ,CAAC8C,SAAS,CAAC,EAAE;UAC/ClD,MAAM,CAACyD,IAAI,CAACJ,SAAS,EAAEjD,QAAQ,CAAC8C,SAAS,CAAC,CAAC;AAC7C;AACF,OAAC,CAAC;AACJ;GACD;AACH;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -26,7 +26,10 @@ const isFormEvent = e => {
|
|
|
26
26
|
return false;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const HotkeyPlugin = () => {
|
|
29
|
+
const HotkeyPlugin = (options = {}) => {
|
|
30
|
+
const {
|
|
31
|
+
config = {}
|
|
32
|
+
} = options;
|
|
30
33
|
return {
|
|
31
34
|
name: 'HotkeyPlugin',
|
|
32
35
|
deps: [],
|
|
@@ -34,134 +37,158 @@ const HotkeyPlugin = () => {
|
|
|
34
37
|
const {
|
|
35
38
|
hotkey,
|
|
36
39
|
project,
|
|
37
|
-
logger
|
|
38
|
-
designer
|
|
40
|
+
logger
|
|
39
41
|
} = ctx;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
hotkey.bind(HOTKEY_MAP.HISTORY_REDO, () => {
|
|
49
|
-
const currentHistory = project.currentDocument?.history;
|
|
50
|
-
if (currentHistory?.isRedoable()) {
|
|
51
|
-
currentHistory?.forward();
|
|
52
|
-
} else {
|
|
53
|
-
logger.log('No operations to redo');
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
hotkey.bind(HOTKEY_MAP.LOCK_UNLOCK, () => {
|
|
57
|
-
const selection = designer.selection;
|
|
58
|
-
const doc = project.currentDocument;
|
|
59
|
-
for (const nodeId of selection.selected) {
|
|
60
|
-
const node = doc?.getNode(nodeId);
|
|
61
|
-
if (node?.isLocked) {
|
|
62
|
-
node.lock(false);
|
|
63
|
-
logger.log('Lock');
|
|
42
|
+
const {
|
|
43
|
+
designer
|
|
44
|
+
} = project;
|
|
45
|
+
const handlers = {
|
|
46
|
+
HISTORY_UNDO: () => {
|
|
47
|
+
const currentHistory = project.currentDocument?.history;
|
|
48
|
+
if (currentHistory?.isUndoable()) {
|
|
49
|
+
currentHistory?.back();
|
|
64
50
|
} else {
|
|
65
|
-
|
|
66
|
-
logger.log('Unlock');
|
|
51
|
+
logger.log('No operations to undo');
|
|
67
52
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const doc = project.currentDocument;
|
|
74
|
-
for (const nodeId of selection.selected) {
|
|
75
|
-
const node = doc?.getNode(nodeId);
|
|
76
|
-
if (node?.isHidden) {
|
|
77
|
-
node.hide(false);
|
|
78
|
-
logger.log('Show');
|
|
53
|
+
},
|
|
54
|
+
HISTORY_REDO: () => {
|
|
55
|
+
const currentHistory = project.currentDocument?.history;
|
|
56
|
+
if (currentHistory?.isRedoable()) {
|
|
57
|
+
currentHistory?.forward();
|
|
79
58
|
} else {
|
|
80
|
-
|
|
81
|
-
logger.log('Hide');
|
|
59
|
+
logger.log('No operations to redo');
|
|
82
60
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
96
|
-
const data = {
|
|
97
|
-
type: 'NodeSchema',
|
|
98
|
-
componentsMap: {},
|
|
99
|
-
componentsTree
|
|
100
|
-
};
|
|
101
|
-
clipboard.setData(data);
|
|
102
|
-
});
|
|
103
|
-
hotkey.bind(HOTKEY_MAP.CUT, e => {
|
|
104
|
-
const doc = project.currentDocument;
|
|
105
|
-
if (isFormEvent(e) || !doc) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const selection = designer.selection;
|
|
109
|
-
const selected = selection.getTopNodes(false);
|
|
110
|
-
if (!selected || selected.length < 1) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
114
|
-
const data = {
|
|
115
|
-
type: 'NodeSchema',
|
|
116
|
-
componentsMap: {},
|
|
117
|
-
componentsTree
|
|
118
|
-
};
|
|
119
|
-
clipboard.setData(data);
|
|
120
|
-
for (const node of selected) {
|
|
121
|
-
node?.parent?.select();
|
|
122
|
-
node.remove();
|
|
123
|
-
}
|
|
124
|
-
selection.clear();
|
|
125
|
-
});
|
|
126
|
-
hotkey.bind(HOTKEY_MAP.PASTE, e => {
|
|
127
|
-
const doc = project.currentDocument;
|
|
128
|
-
const selection = designer.selection;
|
|
129
|
-
if (isFormEvent(e) || !doc) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
clipboard.waitPasteData(e, ({
|
|
133
|
-
componentsTree
|
|
134
|
-
}) => {
|
|
135
|
-
if (componentsTree) {
|
|
136
|
-
const target = doc?.rootNode;
|
|
137
|
-
if (!target) {
|
|
138
|
-
return;
|
|
61
|
+
},
|
|
62
|
+
LOCK_UNLOCK: () => {
|
|
63
|
+
const selection = designer.selection;
|
|
64
|
+
const doc = project.currentDocument;
|
|
65
|
+
for (const nodeId of selection.selected) {
|
|
66
|
+
const node = doc?.getNode(nodeId);
|
|
67
|
+
if (node?.isLocked) {
|
|
68
|
+
node.lock(false);
|
|
69
|
+
logger.log('Lock');
|
|
70
|
+
} else {
|
|
71
|
+
node?.lock(true);
|
|
72
|
+
logger.log('Unlock');
|
|
139
73
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
74
|
+
}
|
|
75
|
+
selection.clear();
|
|
76
|
+
},
|
|
77
|
+
SHOW_HIDE: () => {
|
|
78
|
+
const selection = designer.selection;
|
|
79
|
+
const doc = project.currentDocument;
|
|
80
|
+
for (const nodeId of selection.selected) {
|
|
81
|
+
const node = doc?.getNode(nodeId);
|
|
82
|
+
if (node?.isHidden) {
|
|
83
|
+
node.hide(false);
|
|
84
|
+
logger.log('Show');
|
|
85
|
+
} else {
|
|
86
|
+
node?.hide(true);
|
|
87
|
+
logger.log('Hide');
|
|
143
88
|
}
|
|
144
89
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
90
|
+
selection.clear();
|
|
91
|
+
},
|
|
92
|
+
COPY: e => {
|
|
93
|
+
const doc = project.currentDocument;
|
|
94
|
+
if (isFormEvent(e) || !doc) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const selected = designer.selection.getTopNodes(false);
|
|
98
|
+
if (!selected || selected.length < 1) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
102
|
+
const data = {
|
|
103
|
+
type: 'NodeSchema',
|
|
104
|
+
componentsMap: {},
|
|
105
|
+
componentsTree
|
|
106
|
+
};
|
|
107
|
+
clipboard.setData(data);
|
|
108
|
+
},
|
|
109
|
+
CUT: e => {
|
|
110
|
+
const doc = project.currentDocument;
|
|
111
|
+
if (isFormEvent(e) || !doc) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const selection = designer.selection;
|
|
115
|
+
const selected = selection.getTopNodes(false);
|
|
116
|
+
if (!selected || selected.length < 1) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
120
|
+
const data = {
|
|
121
|
+
type: 'NodeSchema',
|
|
122
|
+
componentsMap: {},
|
|
123
|
+
componentsTree
|
|
124
|
+
};
|
|
125
|
+
clipboard.setData(data);
|
|
126
|
+
for (const node of selected) {
|
|
127
|
+
node?.parent?.select();
|
|
128
|
+
node.remove();
|
|
129
|
+
}
|
|
130
|
+
selection.clear();
|
|
131
|
+
},
|
|
132
|
+
PASTE: e => {
|
|
133
|
+
const doc = project.currentDocument;
|
|
134
|
+
designer.selection;
|
|
135
|
+
if (isFormEvent(e) || !doc) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
clipboard.waitPasteData(e, ({
|
|
139
|
+
componentsTree
|
|
140
|
+
}) => {
|
|
141
|
+
if (componentsTree) {
|
|
142
|
+
const target = doc?.rootNode;
|
|
143
|
+
if (!target) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
insertChildren(target, componentsTree);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
DELETE: e => {
|
|
151
|
+
const doc = project.currentDocument;
|
|
152
|
+
const selection = designer.selection;
|
|
153
|
+
if (isFormEvent(e) || !doc) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const nodes = selection.getTopNodes();
|
|
157
|
+
for (const node of nodes) {
|
|
158
|
+
node && doc?.removeNode(node);
|
|
159
|
+
}
|
|
160
|
+
selection.clear();
|
|
161
|
+
},
|
|
162
|
+
CLEAR_SELECTION: e => {
|
|
163
|
+
const selection = designer.selection;
|
|
164
|
+
if (isFormEvent(e) || !selection) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
selection.clear();
|
|
152
168
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
169
|
+
};
|
|
170
|
+
Object.entries(HOTKEY_MAP).forEach(([action, defaultKeys]) => {
|
|
171
|
+
const actionKey = action;
|
|
172
|
+
const customConfig = config[actionKey];
|
|
173
|
+
let isEnabled = true;
|
|
174
|
+
let keysToUse = defaultKeys;
|
|
175
|
+
if (customConfig !== undefined) {
|
|
176
|
+
if (typeof customConfig === 'boolean') {
|
|
177
|
+
isEnabled = customConfig;
|
|
178
|
+
} else {
|
|
179
|
+
isEnabled = customConfig.enabled !== false;
|
|
180
|
+
if (customConfig.keys && customConfig.keys.length > 0) {
|
|
181
|
+
keysToUse = customConfig.keys;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
156
184
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
hotkey.bind(HOTKEY_MAP.CLEAR_SELECTION, e => {
|
|
160
|
-
const selection = designer.selection;
|
|
161
|
-
if (isFormEvent(e) || !selection) {
|
|
185
|
+
if (!isEnabled) {
|
|
186
|
+
logger.log(`Hotkey ${actionKey} is disabled`);
|
|
162
187
|
return;
|
|
163
188
|
}
|
|
164
|
-
|
|
189
|
+
if (keysToUse.length > 0 && handlers[actionKey]) {
|
|
190
|
+
hotkey.bind(keysToUse, handlers[actionKey]);
|
|
191
|
+
}
|
|
165
192
|
});
|
|
166
193
|
}
|
|
167
194
|
};
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/utils.ts","../../src/index.ts"],"sourcesContent":["export const HOTKEY_MAP = {\n /**\n * 历史记录回退\n */\n HISTORY_UNDO: ['command+z', 'ctrl+z'],\n\n /**\n * 历史记录前进\n */\n HISTORY_REDO: ['command+y', 'ctrl+y'],\n\n /**\n * 锁定/解锁\n */\n LOCK_UNLOCK: ['command+shift+l', 'ctrl+shift+l'],\n\n /**\n * 显示/隐藏\n */\n SHOW_HIDE: ['command+shift+h', 'ctrl+shift+h'],\n\n /**\n * 复制\n */\n COPY: ['command+c', 'ctrl+c'],\n\n /**\n * 粘贴\n */\n PASTE: ['command+v', 'ctrl+v'],\n\n /**\n * 剪切\n */\n CUT: ['command+x', 'ctrl+x'],\n\n /**\n * 删除\n */\n DELETE: ['backspace', 'del'],\n\n /**\n * 取消选中\n */\n CLEAR_SELECTION: ['esc'],\n}\n","/**\n * 检查事件是否由表单元素触发\n */\nexport const isFormEvent = (e: KeyboardEvent | MouseEvent) => {\n const t = e.target as HTMLFormElement\n if (!t) {\n return false\n }\n\n if (t.form || /^(INPUT|SELECT|TEXTAREA)$/.test(t.tagName)) {\n return true\n }\n if (t instanceof HTMLElement && /write/.test(window.getComputedStyle(t).getPropertyValue('-webkit-user-modify'))) {\n return true\n }\n return false\n}\n","import { type PluginCreator, TRANSFORM_STAGE, clipboard, insertChildren } from '@easy-editor/core'\nimport { HOTKEY_MAP } from './const'\nimport { isFormEvent } from './utils'\n\nconst HotkeyPlugin: PluginCreator = () => {\n return {\n name: 'HotkeyPlugin',\n deps: [],\n init(ctx) {\n const { hotkey, project, logger, designer } = ctx\n\n hotkey.bind(HOTKEY_MAP.HISTORY_UNDO, () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isUndoable()) {\n currentHistory?.back()\n } else {\n logger.log('No operations to undo')\n }\n })\n\n hotkey.bind(HOTKEY_MAP.HISTORY_REDO, () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isRedoable()) {\n currentHistory?.forward()\n } else {\n logger.log('No operations to redo')\n }\n })\n\n hotkey.bind(HOTKEY_MAP.LOCK_UNLOCK, () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isLocked) {\n node.lock(false)\n logger.log('Lock')\n } else {\n node?.lock(true)\n logger.log('Unlock')\n }\n }\n\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.SHOW_HIDE, () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isHidden) {\n node.hide(false)\n logger.log('Show')\n } else {\n node?.hide(true)\n logger.log('Hide')\n }\n }\n\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.COPY, e => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selected = designer.selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n })\n\n hotkey.bind(HOTKEY_MAP.CUT, e => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selection = designer.selection\n const selected = selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n\n for (const node of selected) {\n node?.parent?.select()\n node.remove()\n }\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.PASTE, e => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n clipboard.waitPasteData(e, ({ componentsTree }) => {\n if (componentsTree) {\n const target = doc?.rootNode\n\n if (!target) {\n return\n }\n\n const nodes = insertChildren(target, componentsTree)\n if (nodes) {\n selection.selectAll(nodes.map(o => o.id))\n }\n }\n })\n })\n\n hotkey.bind(HOTKEY_MAP.DELETE, e => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const nodes = selection.getTopNodes()\n for (const node of nodes) {\n node && doc?.removeNode(node)\n }\n selection.clear()\n })\n\n hotkey.bind(HOTKEY_MAP.CLEAR_SELECTION, e => {\n const selection = designer.selection\n\n if (isFormEvent(e) || !selection) {\n return\n }\n\n selection.clear()\n })\n },\n }\n}\n\nexport default HotkeyPlugin\n"],"names":["HOTKEY_MAP","HISTORY_UNDO","HISTORY_REDO","LOCK_UNLOCK","SHOW_HIDE","COPY","PASTE","CUT","DELETE","CLEAR_SELECTION","isFormEvent","e","t","target","form","test","tagName","HTMLElement","window","getComputedStyle","getPropertyValue","HotkeyPlugin","name","deps","init","ctx","hotkey","project","logger","designer","bind","currentHistory","currentDocument","history","isUndoable","back","log","isRedoable","forward","selection","doc","nodeId","selected","node","getNode","isLocked","lock","clear","isHidden","hide","getTopNodes","length","componentsTree","map","item","export","TRANSFORM_STAGE","CLONE","data","type","componentsMap","clipboard","setData","parent","select","remove","waitPasteData","rootNode","nodes","insertChildren","selectAll","o","id","removeNode"],"mappings":";;AAAO,MAAMA,UAAU,GAAG;AAIxBC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,WAAW,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAKhDC,EAAAA,SAAS,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAK9CC,EAAAA,IAAI,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK7BC,EAAAA,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK9BC,EAAAA,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK5BC,EAAAA,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC;EAK5BC,eAAe,EAAE,CAAC,KAAK;AACzB,CAAC;;AC1CM,MAAMC,WAAW,GAAIC,CAA6B,IAAK;AAC5D,EAAA,MAAMC,CAAC,GAAGD,CAAC,CAACE,MAAyB;EACrC,IAAI,CAACD,CAAC,EAAE;AACN,IAAA,OAAO,KAAK;AACd;AAEA,EAAA,IAAIA,CAAC,CAACE,IAAI,IAAI,2BAA2B,CAACC,IAAI,CAACH,CAAC,CAACI,OAAO,CAAC,EAAE;AACzD,IAAA,OAAO,IAAI;AACb;EACA,IAAIJ,CAAC,YAAYK,WAAW,IAAI,OAAO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MAAM4B,KAAK,GAAG7B,SAAS,CAACW,WAAW,EAAE;AACrC,QAAA,KAAK,MAAMP,IAAI,IAAIyB,KAAK,EAAE;AACxBzB,UAAAA,IAAI,IAAIH,GAAG,EAAEiC,UAAU,CAAC9B,IAAI,CAAC;AAC/B;QACAJ,SAAS,CAACQ,KAAK,EAAE;AACnB,OAAC,CAAC;MAEFrB,MAAM,CAACI,IAAI,CAAC9B,UAAU,CAACS,eAAe,EAAEE,CAAC,IAAI;AAC3C,QAAA,MAAM4B,SAAS,GAAGV,QAAQ,CAACU,SAAS;AAEpC,QAAA,IAAI7B,WAAW,CAACC,CAAC,CAAC,IAAI,CAAC4B,SAAS,EAAE;AAChC,UAAA;AACF;QAEAA,SAAS,CAACQ,KAAK,EAAE;AACnB,OAAC,CAAC;AACJ;GACD;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/const.ts","../../src/utils.ts","../../src/index.ts"],"sourcesContent":["export const HOTKEY_MAP = {\n /**\n * 历史记录回退\n */\n HISTORY_UNDO: ['command+z', 'ctrl+z'],\n\n /**\n * 历史记录前进\n */\n HISTORY_REDO: ['command+y', 'ctrl+y'],\n\n /**\n * 锁定/解锁\n */\n LOCK_UNLOCK: ['command+shift+l', 'ctrl+shift+l'],\n\n /**\n * 显示/隐藏\n */\n SHOW_HIDE: ['command+shift+h', 'ctrl+shift+h'],\n\n /**\n * 复制\n */\n COPY: ['command+c', 'ctrl+c'],\n\n /**\n * 粘贴\n */\n PASTE: ['command+v', 'ctrl+v'],\n\n /**\n * 剪切\n */\n CUT: ['command+x', 'ctrl+x'],\n\n /**\n * 删除\n */\n DELETE: ['backspace', 'del'],\n\n /**\n * 取消选中\n */\n CLEAR_SELECTION: ['esc'],\n}\n","/**\n * 检查事件是否由表单元素触发\n */\nexport const isFormEvent = (e: KeyboardEvent | MouseEvent) => {\n const t = e.target as HTMLFormElement\n if (!t) {\n return false\n }\n\n if (t.form || /^(INPUT|SELECT|TEXTAREA)$/.test(t.tagName)) {\n return true\n }\n if (t instanceof HTMLElement && /write/.test(window.getComputedStyle(t).getPropertyValue('-webkit-user-modify'))) {\n return true\n }\n return false\n}\n","import { type PluginCreator, TRANSFORM_STAGE, clipboard, insertChildren } from '@easy-editor/core'\nimport { HOTKEY_MAP } from './const'\nimport { isFormEvent } from './utils'\n\nexport type HotkeyCustomization = {\n enabled?: boolean\n keys?: string[]\n}\n\nexport type HotkeyConfigItem = boolean | HotkeyCustomization\n\nexport type HotkeyConfig = {\n [key in keyof typeof HOTKEY_MAP]?: HotkeyConfigItem\n}\n\ninterface HotkeyPluginOptions {\n config?: HotkeyConfig\n}\n\nconst HotkeyPlugin: PluginCreator<HotkeyPluginOptions> = (options = {} as HotkeyPluginOptions) => {\n const { config = {} } = options\n\n return {\n name: 'HotkeyPlugin',\n deps: [],\n init(ctx) {\n const { hotkey, project, logger } = ctx\n const { designer } = project\n\n // Define the default handler functions\n const handlers = {\n HISTORY_UNDO: () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isUndoable()) {\n currentHistory?.back()\n } else {\n logger.log('No operations to undo')\n }\n },\n\n HISTORY_REDO: () => {\n const currentHistory = project.currentDocument?.history\n if (currentHistory?.isRedoable()) {\n currentHistory?.forward()\n } else {\n logger.log('No operations to redo')\n }\n },\n\n LOCK_UNLOCK: () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isLocked) {\n node.lock(false)\n logger.log('Lock')\n } else {\n node?.lock(true)\n logger.log('Unlock')\n }\n }\n\n selection.clear()\n },\n\n SHOW_HIDE: () => {\n const selection = designer.selection\n const doc = project.currentDocument\n\n for (const nodeId of selection.selected) {\n const node = doc?.getNode(nodeId)\n if (node?.isHidden) {\n node.hide(false)\n logger.log('Show')\n } else {\n node?.hide(true)\n logger.log('Hide')\n }\n }\n\n selection.clear()\n },\n\n COPY: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selected = designer.selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n },\n\n CUT: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const selection = designer.selection\n const selected = selection.getTopNodes(false)\n if (!selected || selected.length < 1) {\n return\n }\n\n const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE))\n const data = { type: 'NodeSchema', componentsMap: {}, componentsTree }\n\n clipboard.setData(data)\n\n for (const node of selected) {\n node?.parent?.select()\n node.remove()\n }\n selection.clear()\n },\n\n PASTE: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n clipboard.waitPasteData(e, ({ componentsTree }) => {\n if (componentsTree) {\n const target = doc?.rootNode\n\n if (!target) {\n return\n }\n\n const nodes = insertChildren(target, componentsTree)\n if (nodes) {\n // Additional logic if needed\n }\n }\n })\n },\n\n DELETE: (e: KeyboardEvent) => {\n const doc = project.currentDocument\n const selection = designer.selection\n\n if (isFormEvent(e) || !doc) {\n return\n }\n\n const nodes = selection.getTopNodes()\n for (const node of nodes) {\n node && doc?.removeNode(node)\n }\n selection.clear()\n },\n\n CLEAR_SELECTION: (e: KeyboardEvent) => {\n const selection = designer.selection\n\n if (isFormEvent(e) || !selection) {\n return\n }\n\n selection.clear()\n },\n }\n\n // 根据 config 处理 hotkey 的绑定\n Object.entries(HOTKEY_MAP).forEach(([action, defaultKeys]) => {\n const actionKey = action as keyof typeof HOTKEY_MAP\n const customConfig = config[actionKey]\n\n let isEnabled = true\n let keysToUse = defaultKeys\n\n if (customConfig !== undefined) {\n if (typeof customConfig === 'boolean') {\n isEnabled = customConfig\n } else {\n isEnabled = customConfig.enabled !== false\n if (customConfig.keys && customConfig.keys.length > 0) {\n keysToUse = customConfig.keys\n }\n }\n }\n\n if (!isEnabled) {\n logger.log(`Hotkey ${actionKey} is disabled`)\n return\n }\n\n if (keysToUse.length > 0 && handlers[actionKey]) {\n hotkey.bind(keysToUse, handlers[actionKey])\n }\n })\n },\n }\n}\n\nexport default HotkeyPlugin\n"],"names":["HOTKEY_MAP","HISTORY_UNDO","HISTORY_REDO","LOCK_UNLOCK","SHOW_HIDE","COPY","PASTE","CUT","DELETE","CLEAR_SELECTION","isFormEvent","e","t","target","form","test","tagName","HTMLElement","window","getComputedStyle","getPropertyValue","HotkeyPlugin","options","config","name","deps","init","ctx","hotkey","project","logger","designer","handlers","currentHistory","currentDocument","history","isUndoable","back","log","isRedoable","forward","selection","doc","nodeId","selected","node","getNode","isLocked","lock","clear","isHidden","hide","getTopNodes","length","componentsTree","map","item","export","TRANSFORM_STAGE","CLONE","data","type","componentsMap","clipboard","setData","parent","select","remove","waitPasteData","rootNode","insertChildren","nodes","removeNode","Object","entries","forEach","action","defaultKeys","actionKey","customConfig","isEnabled","keysToUse","undefined","enabled","keys","bind"],"mappings":";;AAAO,MAAMA,UAAU,GAAG;AAIxBC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,YAAY,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAKrCC,EAAAA,WAAW,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAKhDC,EAAAA,SAAS,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;AAK9CC,EAAAA,IAAI,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK7BC,EAAAA,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK9BC,EAAAA,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;AAK5BC,EAAAA,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC;EAK5BC,eAAe,EAAE,CAAC,KAAK;AACzB,C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AAC,CAAC;AAC7C;AACF,OAAC,CAAC;AACJ;GACD;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { type PluginCreator } from '@easy-editor/core';
|
|
2
|
-
|
|
2
|
+
import { HOTKEY_MAP } from './const';
|
|
3
|
+
export type HotkeyCustomization = {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
keys?: string[];
|
|
6
|
+
};
|
|
7
|
+
export type HotkeyConfigItem = boolean | HotkeyCustomization;
|
|
8
|
+
export type HotkeyConfig = {
|
|
9
|
+
[key in keyof typeof HOTKEY_MAP]?: HotkeyConfigItem;
|
|
10
|
+
};
|
|
11
|
+
interface HotkeyPluginOptions {
|
|
12
|
+
config?: HotkeyConfig;
|
|
13
|
+
}
|
|
14
|
+
declare const HotkeyPlugin: PluginCreator<HotkeyPluginOptions>;
|
|
3
15
|
export default HotkeyPlugin;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,10 @@ const isFormEvent = e => {
|
|
|
26
26
|
return false;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const HotkeyPlugin = () => {
|
|
29
|
+
const HotkeyPlugin = (options = {}) => {
|
|
30
|
+
const {
|
|
31
|
+
config = {}
|
|
32
|
+
} = options;
|
|
30
33
|
return {
|
|
31
34
|
name: 'HotkeyPlugin',
|
|
32
35
|
deps: [],
|
|
@@ -34,134 +37,158 @@ const HotkeyPlugin = () => {
|
|
|
34
37
|
const {
|
|
35
38
|
hotkey,
|
|
36
39
|
project,
|
|
37
|
-
logger
|
|
38
|
-
designer
|
|
40
|
+
logger
|
|
39
41
|
} = ctx;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
hotkey.bind(HOTKEY_MAP.HISTORY_REDO, () => {
|
|
49
|
-
const currentHistory = project.currentDocument?.history;
|
|
50
|
-
if (currentHistory?.isRedoable()) {
|
|
51
|
-
currentHistory?.forward();
|
|
52
|
-
} else {
|
|
53
|
-
logger.log('No operations to redo');
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
hotkey.bind(HOTKEY_MAP.LOCK_UNLOCK, () => {
|
|
57
|
-
const selection = designer.selection;
|
|
58
|
-
const doc = project.currentDocument;
|
|
59
|
-
for (const nodeId of selection.selected) {
|
|
60
|
-
const node = doc?.getNode(nodeId);
|
|
61
|
-
if (node?.isLocked) {
|
|
62
|
-
node.lock(false);
|
|
63
|
-
logger.log('Lock');
|
|
42
|
+
const {
|
|
43
|
+
designer
|
|
44
|
+
} = project;
|
|
45
|
+
const handlers = {
|
|
46
|
+
HISTORY_UNDO: () => {
|
|
47
|
+
const currentHistory = project.currentDocument?.history;
|
|
48
|
+
if (currentHistory?.isUndoable()) {
|
|
49
|
+
currentHistory?.back();
|
|
64
50
|
} else {
|
|
65
|
-
|
|
66
|
-
logger.log('Unlock');
|
|
51
|
+
logger.log('No operations to undo');
|
|
67
52
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const doc = project.currentDocument;
|
|
74
|
-
for (const nodeId of selection.selected) {
|
|
75
|
-
const node = doc?.getNode(nodeId);
|
|
76
|
-
if (node?.isHidden) {
|
|
77
|
-
node.hide(false);
|
|
78
|
-
logger.log('Show');
|
|
53
|
+
},
|
|
54
|
+
HISTORY_REDO: () => {
|
|
55
|
+
const currentHistory = project.currentDocument?.history;
|
|
56
|
+
if (currentHistory?.isRedoable()) {
|
|
57
|
+
currentHistory?.forward();
|
|
79
58
|
} else {
|
|
80
|
-
|
|
81
|
-
logger.log('Hide');
|
|
59
|
+
logger.log('No operations to redo');
|
|
82
60
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
96
|
-
const data = {
|
|
97
|
-
type: 'NodeSchema',
|
|
98
|
-
componentsMap: {},
|
|
99
|
-
componentsTree
|
|
100
|
-
};
|
|
101
|
-
clipboard.setData(data);
|
|
102
|
-
});
|
|
103
|
-
hotkey.bind(HOTKEY_MAP.CUT, e => {
|
|
104
|
-
const doc = project.currentDocument;
|
|
105
|
-
if (isFormEvent(e) || !doc) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const selection = designer.selection;
|
|
109
|
-
const selected = selection.getTopNodes(false);
|
|
110
|
-
if (!selected || selected.length < 1) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
114
|
-
const data = {
|
|
115
|
-
type: 'NodeSchema',
|
|
116
|
-
componentsMap: {},
|
|
117
|
-
componentsTree
|
|
118
|
-
};
|
|
119
|
-
clipboard.setData(data);
|
|
120
|
-
for (const node of selected) {
|
|
121
|
-
node?.parent?.select();
|
|
122
|
-
node.remove();
|
|
123
|
-
}
|
|
124
|
-
selection.clear();
|
|
125
|
-
});
|
|
126
|
-
hotkey.bind(HOTKEY_MAP.PASTE, e => {
|
|
127
|
-
const doc = project.currentDocument;
|
|
128
|
-
const selection = designer.selection;
|
|
129
|
-
if (isFormEvent(e) || !doc) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
clipboard.waitPasteData(e, ({
|
|
133
|
-
componentsTree
|
|
134
|
-
}) => {
|
|
135
|
-
if (componentsTree) {
|
|
136
|
-
const target = doc?.rootNode;
|
|
137
|
-
if (!target) {
|
|
138
|
-
return;
|
|
61
|
+
},
|
|
62
|
+
LOCK_UNLOCK: () => {
|
|
63
|
+
const selection = designer.selection;
|
|
64
|
+
const doc = project.currentDocument;
|
|
65
|
+
for (const nodeId of selection.selected) {
|
|
66
|
+
const node = doc?.getNode(nodeId);
|
|
67
|
+
if (node?.isLocked) {
|
|
68
|
+
node.lock(false);
|
|
69
|
+
logger.log('Lock');
|
|
70
|
+
} else {
|
|
71
|
+
node?.lock(true);
|
|
72
|
+
logger.log('Unlock');
|
|
139
73
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
74
|
+
}
|
|
75
|
+
selection.clear();
|
|
76
|
+
},
|
|
77
|
+
SHOW_HIDE: () => {
|
|
78
|
+
const selection = designer.selection;
|
|
79
|
+
const doc = project.currentDocument;
|
|
80
|
+
for (const nodeId of selection.selected) {
|
|
81
|
+
const node = doc?.getNode(nodeId);
|
|
82
|
+
if (node?.isHidden) {
|
|
83
|
+
node.hide(false);
|
|
84
|
+
logger.log('Show');
|
|
85
|
+
} else {
|
|
86
|
+
node?.hide(true);
|
|
87
|
+
logger.log('Hide');
|
|
143
88
|
}
|
|
144
89
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
90
|
+
selection.clear();
|
|
91
|
+
},
|
|
92
|
+
COPY: e => {
|
|
93
|
+
const doc = project.currentDocument;
|
|
94
|
+
if (isFormEvent(e) || !doc) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const selected = designer.selection.getTopNodes(false);
|
|
98
|
+
if (!selected || selected.length < 1) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
102
|
+
const data = {
|
|
103
|
+
type: 'NodeSchema',
|
|
104
|
+
componentsMap: {},
|
|
105
|
+
componentsTree
|
|
106
|
+
};
|
|
107
|
+
clipboard.setData(data);
|
|
108
|
+
},
|
|
109
|
+
CUT: e => {
|
|
110
|
+
const doc = project.currentDocument;
|
|
111
|
+
if (isFormEvent(e) || !doc) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const selection = designer.selection;
|
|
115
|
+
const selected = selection.getTopNodes(false);
|
|
116
|
+
if (!selected || selected.length < 1) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const componentsTree = selected.map(item => item?.export(TRANSFORM_STAGE.CLONE));
|
|
120
|
+
const data = {
|
|
121
|
+
type: 'NodeSchema',
|
|
122
|
+
componentsMap: {},
|
|
123
|
+
componentsTree
|
|
124
|
+
};
|
|
125
|
+
clipboard.setData(data);
|
|
126
|
+
for (const node of selected) {
|
|
127
|
+
node?.parent?.select();
|
|
128
|
+
node.remove();
|
|
129
|
+
}
|
|
130
|
+
selection.clear();
|
|
131
|
+
},
|
|
132
|
+
PASTE: e => {
|
|
133
|
+
const doc = project.currentDocument;
|
|
134
|
+
designer.selection;
|
|
135
|
+
if (isFormEvent(e) || !doc) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
clipboard.waitPasteData(e, ({
|
|
139
|
+
componentsTree
|
|
140
|
+
}) => {
|
|
141
|
+
if (componentsTree) {
|
|
142
|
+
const target = doc?.rootNode;
|
|
143
|
+
if (!target) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
insertChildren(target, componentsTree);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
DELETE: e => {
|
|
151
|
+
const doc = project.currentDocument;
|
|
152
|
+
const selection = designer.selection;
|
|
153
|
+
if (isFormEvent(e) || !doc) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const nodes = selection.getTopNodes();
|
|
157
|
+
for (const node of nodes) {
|
|
158
|
+
node && doc?.removeNode(node);
|
|
159
|
+
}
|
|
160
|
+
selection.clear();
|
|
161
|
+
},
|
|
162
|
+
CLEAR_SELECTION: e => {
|
|
163
|
+
const selection = designer.selection;
|
|
164
|
+
if (isFormEvent(e) || !selection) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
selection.clear();
|
|
152
168
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
169
|
+
};
|
|
170
|
+
Object.entries(HOTKEY_MAP).forEach(([action, defaultKeys]) => {
|
|
171
|
+
const actionKey = action;
|
|
172
|
+
const customConfig = config[actionKey];
|
|
173
|
+
let isEnabled = true;
|
|
174
|
+
let keysToUse = defaultKeys;
|
|
175
|
+
if (customConfig !== undefined) {
|
|
176
|
+
if (typeof customConfig === 'boolean') {
|
|
177
|
+
isEnabled = customConfig;
|
|
178
|
+
} else {
|
|
179
|
+
isEnabled = customConfig.enabled !== false;
|
|
180
|
+
if (customConfig.keys && customConfig.keys.length > 0) {
|
|
181
|
+
keysToUse = customConfig.keys;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
156
184
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
hotkey.bind(HOTKEY_MAP.CLEAR_SELECTION, e => {
|
|
160
|
-
const selection = designer.selection;
|
|
161
|
-
if (isFormEvent(e) || !selection) {
|
|
185
|
+
if (!isEnabled) {
|
|
186
|
+
logger.log(`Hotkey ${actionKey} is disabled`);
|
|
162
187
|
return;
|
|
163
188
|
}
|
|
164
|
-
|
|
189
|
+
if (keysToUse.length > 0 && handlers[actionKey]) {
|
|
190
|
+
hotkey.bind(keysToUse, handlers[actionKey]);
|
|
191
|
+
}
|
|
165
192
|
});
|
|
166
193
|
}
|
|
167
194
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-editor/plugin-hotkey",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Hotkey plugin for EasyEditor
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Hotkey plugin for EasyEditor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist",
|
|
9
17
|
"LICENSE",
|
|
@@ -22,7 +30,7 @@
|
|
|
22
30
|
"editor",
|
|
23
31
|
"engine",
|
|
24
32
|
"plugin",
|
|
25
|
-
"
|
|
33
|
+
"hotkey"
|
|
26
34
|
],
|
|
27
35
|
"repository": {
|
|
28
36
|
"type": "git",
|
|
@@ -32,7 +40,7 @@
|
|
|
32
40
|
"url": "https://github.com/Easy-Editor/EasyEditor/issues"
|
|
33
41
|
},
|
|
34
42
|
"peerDependencies": {
|
|
35
|
-
"@easy-editor/core": "^
|
|
43
|
+
"@easy-editor/core": "^1.0.1"
|
|
36
44
|
},
|
|
37
45
|
"scripts": {
|
|
38
46
|
"dev": "deno run --watch ./src/index.ts",
|
|
@@ -45,14 +53,6 @@
|
|
|
45
53
|
"types:src": "tsc --project tsconfig.build.json",
|
|
46
54
|
"test-types": "tsc --project tsconfig.test.json"
|
|
47
55
|
},
|
|
48
|
-
"types": "dist/index.d.ts",
|
|
49
|
-
"typings": "dist/index.d.ts",
|
|
50
56
|
"module": "dist/index.js",
|
|
51
|
-
"
|
|
52
|
-
".": {
|
|
53
|
-
"import": "./dist/index.js",
|
|
54
|
-
"require": "./dist/cjs/index.js",
|
|
55
|
-
"default": "./dist/index.js"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
57
|
+
"unpkg": "dist/index.js"
|
|
58
58
|
}
|