PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / QuickEdit / lib / global-escape.js

global-escape.js in Extendify 3.2.1, at src/QuickEdit/lib/global-escape.js

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEditModeStore } from '../state/edit-mode';
2 import { useQuickEditStore } from '../state/store';
3 import { decideEscapeAction } from './escape-rule';
4
5 const CANCEL_EVENT = 'extendify-agent:cancel-workflow';
6
7 const onKey = (e) => {
8 if (e.key !== 'Escape') return;
9 const editModeOn = useEditModeStore.getState().on;
10 if (!editModeOn) return;
11
12 const {
13 agentBlock,
14 selected,
15 committedSelection,
16 setAgentBlock,
17 clearSelected,
18 setCommittedSelection,
19 } = useQuickEditStore.getState();
20 const sameBlock =
21 selected?.blockId != null &&
22 agentBlock?.id != null &&
23 String(selected.blockId) === String(agentBlock.id);
24 const { action } = decideEscapeAction({
25 editModeOn: true,
26 hasAgentBlock: !!agentBlock,
27 hasQuickEditSelection: !!selected,
28 hasCommittedSelection: !!committedSelection,
29 sameBlock,
30 });
31
32 if (action === 'clear-selection-and-agent-block') {
33 window.dispatchEvent(new CustomEvent(CANCEL_EVENT));
34 setAgentBlock(null);
35 clearSelected();
36 e.preventDefault();
37 e.stopPropagation();
38 return;
39 }
40 if (action === 'clear-agent-block') {
41 window.dispatchEvent(new CustomEvent(CANCEL_EVENT));
42 setAgentBlock(null);
43 e.preventDefault();
44 e.stopPropagation();
45 return;
46 }
47 if (action === 'clear-selection') {
48 clearSelected();
49 e.preventDefault();
50 e.stopPropagation();
51 return;
52 }
53 if (action === 'clear-committed-selection') {
54 setCommittedSelection(null);
55 e.preventDefault();
56 e.stopPropagation();
57 return;
58 }
59 // noop: stop propagation so the old window-level fallback (which
60 // would have toggled edit mode off) stays quiet. preventDefault is
61 // intentionally not called — there's nothing to suppress.
62 e.stopPropagation();
63 };
64
65 export const wireGlobalEscape = () => {
66 document.addEventListener('keydown', onKey);
67 return () => document.removeEventListener('keydown', onKey);
68 };
69