@rtif-sdk/web 1.5.0 → 1.7.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/dist/context-menu.d.ts +54 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +470 -0
- package/dist/context-menu.js.map +1 -0
- package/dist/editor.d.ts +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +130 -1
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/preset-full.d.ts.map +1 -1
- package/dist/preset-full.js +8 -1
- package/dist/preset-full.js.map +1 -1
- package/dist/types.d.ts +202 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/styles/all.css +1 -0
- package/styles/context-menu.css +58 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context menu — right-click menu with Cut/Copy/Paste/Select All.
|
|
3
|
+
*
|
|
4
|
+
* Shows a positioned menu on `contextmenu` events with keyboard navigation,
|
|
5
|
+
* viewport clamping, and ARIA roles. Items are configurable via
|
|
6
|
+
* `ContextMenuConfig` on {@link WebEditorConfig}.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { IEditorEngine } from '@rtif-sdk/engine';
|
|
11
|
+
import type { WebEditor, ContextMenuItem, ContextMenuHandle } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get the default context menu items (Cut, Copy, Paste, Paste as Plain Text,
|
|
14
|
+
* separator, Select All).
|
|
15
|
+
*
|
|
16
|
+
* @returns An array of default context menu items
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const items = getDefaultItems();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDefaultItems(): ContextMenuItem[];
|
|
24
|
+
/**
|
|
25
|
+
* Dependencies for creating a context menu. Internal — not exported as a
|
|
26
|
+
* public type. The `createWebEditor` factory wires these from its own scope.
|
|
27
|
+
*/
|
|
28
|
+
interface ContextMenuDeps {
|
|
29
|
+
readonly editor: WebEditor;
|
|
30
|
+
readonly root: HTMLElement;
|
|
31
|
+
readonly engine: IEditorEngine;
|
|
32
|
+
readonly isReadOnly: () => boolean;
|
|
33
|
+
readonly items?: ReadonlyArray<ContextMenuItem>;
|
|
34
|
+
readonly additionalItems?: ReadonlyArray<ContextMenuItem>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a context menu attached to the editor root.
|
|
38
|
+
*
|
|
39
|
+
* Intercepts the `contextmenu` event, builds the menu DOM, and manages
|
|
40
|
+
* keyboard navigation plus outside-click dismissal.
|
|
41
|
+
*
|
|
42
|
+
* @param deps - Dependencies injected by the editor factory
|
|
43
|
+
* @returns A {@link ContextMenuHandle} for programmatic control and cleanup
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const handle = createContextMenu({ editor, root, engine, isReadOnly: () => false });
|
|
48
|
+
* // later:
|
|
49
|
+
* handle.dispose();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createContextMenu(deps: ContextMenuDeps): ContextMenuHandle;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=context-menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.d.ts","sourceRoot":"","sources":["../src/context-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EAGf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAcpB;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,eAAe,EAAE,CA6DnD;AA0GD;;;GAGG;AACH,UAAU,eAAe;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CAC3D;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CAyS1E"}
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context menu — right-click menu with Cut/Copy/Paste/Select All.
|
|
3
|
+
*
|
|
4
|
+
* Shows a positioned menu on `contextmenu` events with keyboard navigation,
|
|
5
|
+
* viewport clamping, and ARIA roles. Items are configurable via
|
|
6
|
+
* `ContextMenuConfig` on {@link WebEditorConfig}.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { docLength } from '@rtif-sdk/core';
|
|
11
|
+
import { isMac } from './cursor-nav.js';
|
|
12
|
+
import { deleteSelectionOps } from './clipboard.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Module-scoped counter for unique IDs
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
let instanceCounter = 0;
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Default items
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Get the default context menu items (Cut, Copy, Paste, Paste as Plain Text,
|
|
22
|
+
* separator, Select All).
|
|
23
|
+
*
|
|
24
|
+
* @returns An array of default context menu items
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const items = getDefaultItems();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function getDefaultItems() {
|
|
32
|
+
const mac = isMac();
|
|
33
|
+
const mod = mac ? '\u2318' : 'Ctrl+';
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
type: 'action',
|
|
37
|
+
id: 'cut',
|
|
38
|
+
label: 'Cut',
|
|
39
|
+
shortcutHint: `${mod}X`,
|
|
40
|
+
// execCommand('cut') triggers a ClipboardEvent which the RTIF
|
|
41
|
+
// ClipboardHandler intercepts — writing RTIF JSON + plain text
|
|
42
|
+
// to the clipboard and deleting the selection via ops.
|
|
43
|
+
action: () => { document.execCommand('cut'); },
|
|
44
|
+
isDisabled: (ctx) => ctx.isCollapsed || ctx.readOnly,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'action',
|
|
48
|
+
id: 'copy',
|
|
49
|
+
label: 'Copy',
|
|
50
|
+
shortcutHint: `${mod}C`,
|
|
51
|
+
// Same as cut — the ClipboardHandler writes RTIF JSON + plain text.
|
|
52
|
+
action: () => { document.execCommand('copy'); },
|
|
53
|
+
isDisabled: (ctx) => ctx.isCollapsed,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'action',
|
|
57
|
+
id: 'paste',
|
|
58
|
+
label: 'Paste',
|
|
59
|
+
shortcutHint: `${mod}V`,
|
|
60
|
+
action: (editor) => {
|
|
61
|
+
// Read from navigator.clipboard and feed through the content
|
|
62
|
+
// pipeline. This preserves RTIF JSON if available, otherwise
|
|
63
|
+
// falls back to HTML → plain text.
|
|
64
|
+
pasteViaClipboardApi(editor);
|
|
65
|
+
},
|
|
66
|
+
isDisabled: (ctx) => ctx.readOnly,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'action',
|
|
70
|
+
id: 'paste-plain',
|
|
71
|
+
label: 'Paste as Plain Text',
|
|
72
|
+
shortcutHint: mac ? '\u21e7\u2318V' : 'Ctrl+Shift+V',
|
|
73
|
+
action: (editor) => { pasteAsPlainText(editor); },
|
|
74
|
+
isDisabled: (ctx) => ctx.readOnly,
|
|
75
|
+
},
|
|
76
|
+
{ type: 'separator' },
|
|
77
|
+
{
|
|
78
|
+
type: 'action',
|
|
79
|
+
id: 'select-all',
|
|
80
|
+
label: 'Select All',
|
|
81
|
+
shortcutHint: `${mod}A`,
|
|
82
|
+
action: (editor) => {
|
|
83
|
+
const len = docLength(editor.engine.state.doc);
|
|
84
|
+
editor.engine.setSelection({
|
|
85
|
+
anchor: { offset: 0 },
|
|
86
|
+
focus: { offset: len },
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Paste helpers
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
/**
|
|
96
|
+
* Read clipboard contents and feed through the content pipeline.
|
|
97
|
+
* Uses the async Clipboard API (`navigator.clipboard.read()`) when available,
|
|
98
|
+
* falling back to `readText()` for plain text only.
|
|
99
|
+
*/
|
|
100
|
+
function pasteViaClipboardApi(editor) {
|
|
101
|
+
// Try the full ClipboardItem API first for rich paste
|
|
102
|
+
if (typeof navigator.clipboard?.read === 'function') {
|
|
103
|
+
void navigator.clipboard.read().then((clipboardItems) => {
|
|
104
|
+
const items = [];
|
|
105
|
+
for (const ci of clipboardItems) {
|
|
106
|
+
for (const type of ci.types) {
|
|
107
|
+
items.push({
|
|
108
|
+
type,
|
|
109
|
+
source: 'paste',
|
|
110
|
+
getString: async () => {
|
|
111
|
+
try {
|
|
112
|
+
const blob = await ci.getType(type);
|
|
113
|
+
return await blob.text();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
getFile: async () => null,
|
|
120
|
+
getBlob: async () => {
|
|
121
|
+
try {
|
|
122
|
+
return await ci.getType(type);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (items.length > 0) {
|
|
132
|
+
void editor.content.process(items, {
|
|
133
|
+
engine: editor.engine,
|
|
134
|
+
commands: editor.commandBus,
|
|
135
|
+
source: 'paste',
|
|
136
|
+
generateBlockId: () => `b_cm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}).catch(() => {
|
|
140
|
+
// Clipboard API denied — fall back to plain text
|
|
141
|
+
pasteAsPlainText(editor);
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Fallback: plain text only
|
|
146
|
+
pasteAsPlainText(editor);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Read plain text from the clipboard and insert it, stripping all formatting.
|
|
150
|
+
* Handles selection deletion and newline splitting.
|
|
151
|
+
*/
|
|
152
|
+
function pasteAsPlainText(editor) {
|
|
153
|
+
if (typeof navigator.clipboard?.readText !== 'function')
|
|
154
|
+
return;
|
|
155
|
+
void navigator.clipboard.readText().then((text) => {
|
|
156
|
+
if (!text)
|
|
157
|
+
return;
|
|
158
|
+
const doc = editor.engine.state.doc;
|
|
159
|
+
const sel = editor.engine.state.selection;
|
|
160
|
+
const ops = [];
|
|
161
|
+
const start = Math.min(sel.anchor.offset, sel.focus.offset);
|
|
162
|
+
// Delete selection if non-collapsed
|
|
163
|
+
if (sel.anchor.offset !== sel.focus.offset) {
|
|
164
|
+
ops.push(...deleteSelectionOps(doc, sel));
|
|
165
|
+
}
|
|
166
|
+
// Insert plain text — split on newlines into insert_text + split_block
|
|
167
|
+
const lines = text.split('\n');
|
|
168
|
+
let offset = start;
|
|
169
|
+
for (let i = 0; i < lines.length; i++) {
|
|
170
|
+
if (i > 0) {
|
|
171
|
+
ops.push({
|
|
172
|
+
type: 'split_block',
|
|
173
|
+
offset,
|
|
174
|
+
newBlockId: `b_cm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
175
|
+
});
|
|
176
|
+
offset += 1;
|
|
177
|
+
}
|
|
178
|
+
const line = lines[i];
|
|
179
|
+
if (line.length > 0) {
|
|
180
|
+
ops.push({ type: 'insert_text', offset, text: line });
|
|
181
|
+
offset += line.length;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (ops.length > 0) {
|
|
185
|
+
editor.engine.dispatch(ops);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Factory
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
/**
|
|
193
|
+
* Create a context menu attached to the editor root.
|
|
194
|
+
*
|
|
195
|
+
* Intercepts the `contextmenu` event, builds the menu DOM, and manages
|
|
196
|
+
* keyboard navigation plus outside-click dismissal.
|
|
197
|
+
*
|
|
198
|
+
* @param deps - Dependencies injected by the editor factory
|
|
199
|
+
* @returns A {@link ContextMenuHandle} for programmatic control and cleanup
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const handle = createContextMenu({ editor, root, engine, isReadOnly: () => false });
|
|
204
|
+
* // later:
|
|
205
|
+
* handle.dispose();
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export function createContextMenu(deps) {
|
|
209
|
+
const { editor, root, engine, isReadOnly } = deps;
|
|
210
|
+
const id = ++instanceCounter;
|
|
211
|
+
let menuEl = null;
|
|
212
|
+
let isMenuOpen = false;
|
|
213
|
+
let justShown = false;
|
|
214
|
+
let highlightIndex = -1;
|
|
215
|
+
let actionItems = [];
|
|
216
|
+
let itemEls = [];
|
|
217
|
+
// Resolve items
|
|
218
|
+
const resolvedItems = deps.items
|
|
219
|
+
? deps.items
|
|
220
|
+
: [...getDefaultItems(), ...(deps.additionalItems ?? [])];
|
|
221
|
+
// -------------------------------------------------------------------
|
|
222
|
+
// Context building
|
|
223
|
+
// -------------------------------------------------------------------
|
|
224
|
+
function buildContext() {
|
|
225
|
+
const sel = engine.state.selection;
|
|
226
|
+
const isCollapsed = sel.anchor.offset === sel.focus.offset;
|
|
227
|
+
const block = engine.getBlockAtOffset(sel.focus.offset);
|
|
228
|
+
const marks = engine.getMarksAtOffset(sel.focus.offset);
|
|
229
|
+
return {
|
|
230
|
+
isCollapsed,
|
|
231
|
+
readOnly: isReadOnly(),
|
|
232
|
+
blockType: block?.type ?? 'text',
|
|
233
|
+
marks,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
// -------------------------------------------------------------------
|
|
237
|
+
// DOM creation
|
|
238
|
+
// -------------------------------------------------------------------
|
|
239
|
+
function createMenuElement(x, y) {
|
|
240
|
+
const ctx = buildContext();
|
|
241
|
+
const container = document.createElement('div');
|
|
242
|
+
container.className = 'rtif-context-menu';
|
|
243
|
+
container.setAttribute('role', 'menu');
|
|
244
|
+
container.setAttribute('aria-label', 'Context menu');
|
|
245
|
+
actionItems = [];
|
|
246
|
+
itemEls = [];
|
|
247
|
+
let itemCounter = 0;
|
|
248
|
+
for (const item of resolvedItems) {
|
|
249
|
+
if (item.type === 'separator') {
|
|
250
|
+
const sep = document.createElement('div');
|
|
251
|
+
sep.setAttribute('role', 'separator');
|
|
252
|
+
sep.className = 'rtif-context-menu-separator';
|
|
253
|
+
container.appendChild(sep);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
// Action item
|
|
257
|
+
if (item.canShow && !item.canShow(ctx))
|
|
258
|
+
continue;
|
|
259
|
+
const disabled = item.isDisabled ? item.isDisabled(ctx) : false;
|
|
260
|
+
const itemEl = document.createElement('div');
|
|
261
|
+
itemEl.className = 'rtif-context-menu-item';
|
|
262
|
+
itemEl.id = `rtif-cm-item-${id}-${itemCounter++}`;
|
|
263
|
+
itemEl.setAttribute('role', 'menuitem');
|
|
264
|
+
if (disabled) {
|
|
265
|
+
itemEl.setAttribute('aria-disabled', 'true');
|
|
266
|
+
}
|
|
267
|
+
// Label
|
|
268
|
+
const label = document.createElement('span');
|
|
269
|
+
label.className = 'rtif-context-menu-item-label';
|
|
270
|
+
label.textContent = item.label;
|
|
271
|
+
itemEl.appendChild(label);
|
|
272
|
+
// Shortcut hint
|
|
273
|
+
if (item.shortcutHint) {
|
|
274
|
+
const hint = document.createElement('span');
|
|
275
|
+
hint.className = 'rtif-context-menu-item-shortcut';
|
|
276
|
+
hint.textContent = item.shortcutHint;
|
|
277
|
+
itemEl.appendChild(hint);
|
|
278
|
+
}
|
|
279
|
+
// Click handler
|
|
280
|
+
if (!disabled) {
|
|
281
|
+
itemEl.addEventListener('mousedown', (e) => {
|
|
282
|
+
e.preventDefault();
|
|
283
|
+
e.stopPropagation();
|
|
284
|
+
item.action(editor);
|
|
285
|
+
hide();
|
|
286
|
+
editor.focus();
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// Prevent focus steal on disabled items
|
|
291
|
+
itemEl.addEventListener('mousedown', (e) => {
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
// Hover highlight
|
|
296
|
+
itemEl.addEventListener('mouseenter', () => {
|
|
297
|
+
if (!disabled) {
|
|
298
|
+
const idx = actionItems.indexOf(item);
|
|
299
|
+
if (idx !== -1) {
|
|
300
|
+
highlightIndex = idx;
|
|
301
|
+
updateHighlight();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
container.appendChild(itemEl);
|
|
306
|
+
actionItems.push(item);
|
|
307
|
+
itemEls.push(itemEl);
|
|
308
|
+
}
|
|
309
|
+
// Prevent editor focus loss when interacting with menu
|
|
310
|
+
container.addEventListener('mousedown', (e) => {
|
|
311
|
+
e.preventDefault();
|
|
312
|
+
});
|
|
313
|
+
// Position with viewport clamping
|
|
314
|
+
document.body.appendChild(container);
|
|
315
|
+
const menuRect = container.getBoundingClientRect();
|
|
316
|
+
let left = x;
|
|
317
|
+
let top = y;
|
|
318
|
+
// Clamp right edge
|
|
319
|
+
if (left + menuRect.width > window.innerWidth - 4) {
|
|
320
|
+
left = window.innerWidth - menuRect.width - 4;
|
|
321
|
+
}
|
|
322
|
+
if (left < 4) {
|
|
323
|
+
left = 4;
|
|
324
|
+
}
|
|
325
|
+
// Flip above if near bottom
|
|
326
|
+
if (top + menuRect.height > window.innerHeight - 4) {
|
|
327
|
+
top = y - menuRect.height;
|
|
328
|
+
}
|
|
329
|
+
if (top < 4) {
|
|
330
|
+
top = 4;
|
|
331
|
+
}
|
|
332
|
+
container.style.left = `${left}px`;
|
|
333
|
+
container.style.top = `${top}px`;
|
|
334
|
+
return container;
|
|
335
|
+
}
|
|
336
|
+
// -------------------------------------------------------------------
|
|
337
|
+
// Show / hide
|
|
338
|
+
// -------------------------------------------------------------------
|
|
339
|
+
function show(x, y) {
|
|
340
|
+
hide();
|
|
341
|
+
menuEl = createMenuElement(x, y);
|
|
342
|
+
isMenuOpen = true;
|
|
343
|
+
highlightIndex = -1;
|
|
344
|
+
// Prevent the same-tick outside-click from immediately closing
|
|
345
|
+
justShown = true;
|
|
346
|
+
requestAnimationFrame(() => { justShown = false; });
|
|
347
|
+
// Attach dismiss listeners
|
|
348
|
+
document.addEventListener('mousedown', onDocumentMouseDown);
|
|
349
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
350
|
+
}
|
|
351
|
+
function hide() {
|
|
352
|
+
if (!menuEl)
|
|
353
|
+
return;
|
|
354
|
+
menuEl.remove();
|
|
355
|
+
menuEl = null;
|
|
356
|
+
isMenuOpen = false;
|
|
357
|
+
highlightIndex = -1;
|
|
358
|
+
actionItems = [];
|
|
359
|
+
itemEls = [];
|
|
360
|
+
document.removeEventListener('mousedown', onDocumentMouseDown);
|
|
361
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
362
|
+
}
|
|
363
|
+
// -------------------------------------------------------------------
|
|
364
|
+
// Keyboard navigation
|
|
365
|
+
// -------------------------------------------------------------------
|
|
366
|
+
function findNextEnabledIndex(from, direction) {
|
|
367
|
+
const len = actionItems.length;
|
|
368
|
+
if (len === 0)
|
|
369
|
+
return -1;
|
|
370
|
+
let idx = from;
|
|
371
|
+
for (let i = 0; i < len; i++) {
|
|
372
|
+
idx = ((idx + direction) % len + len) % len;
|
|
373
|
+
const item = actionItems[idx];
|
|
374
|
+
const ctx = buildContext();
|
|
375
|
+
const disabled = item.isDisabled ? item.isDisabled(ctx) : false;
|
|
376
|
+
if (!disabled)
|
|
377
|
+
return idx;
|
|
378
|
+
}
|
|
379
|
+
return -1;
|
|
380
|
+
}
|
|
381
|
+
function updateHighlight() {
|
|
382
|
+
for (let i = 0; i < itemEls.length; i++) {
|
|
383
|
+
const el = itemEls[i];
|
|
384
|
+
if (i === highlightIndex) {
|
|
385
|
+
el.classList.add('rtif-context-menu-item-highlighted');
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
el.classList.remove('rtif-context-menu-item-highlighted');
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (highlightIndex >= 0 && highlightIndex < itemEls.length) {
|
|
392
|
+
menuEl?.setAttribute('aria-activedescendant', itemEls[highlightIndex].id);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
menuEl?.removeAttribute('aria-activedescendant');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function onKeyDown(e) {
|
|
399
|
+
if (!isMenuOpen)
|
|
400
|
+
return;
|
|
401
|
+
switch (e.key) {
|
|
402
|
+
case 'ArrowDown': {
|
|
403
|
+
e.preventDefault();
|
|
404
|
+
e.stopPropagation();
|
|
405
|
+
highlightIndex = findNextEnabledIndex(highlightIndex, 1);
|
|
406
|
+
updateHighlight();
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case 'ArrowUp': {
|
|
410
|
+
e.preventDefault();
|
|
411
|
+
e.stopPropagation();
|
|
412
|
+
highlightIndex = findNextEnabledIndex(highlightIndex, -1);
|
|
413
|
+
updateHighlight();
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
case 'Enter': {
|
|
417
|
+
e.preventDefault();
|
|
418
|
+
e.stopPropagation();
|
|
419
|
+
if (highlightIndex >= 0 && highlightIndex < actionItems.length) {
|
|
420
|
+
const item = actionItems[highlightIndex];
|
|
421
|
+
item.action(editor);
|
|
422
|
+
hide();
|
|
423
|
+
editor.focus();
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case 'Escape': {
|
|
428
|
+
e.preventDefault();
|
|
429
|
+
e.stopPropagation();
|
|
430
|
+
hide();
|
|
431
|
+
editor.focus();
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// -------------------------------------------------------------------
|
|
437
|
+
// Event handlers
|
|
438
|
+
// -------------------------------------------------------------------
|
|
439
|
+
function onDocumentMouseDown(e) {
|
|
440
|
+
if (!menuEl)
|
|
441
|
+
return;
|
|
442
|
+
if (justShown)
|
|
443
|
+
return;
|
|
444
|
+
if (menuEl.contains(e.target))
|
|
445
|
+
return;
|
|
446
|
+
hide();
|
|
447
|
+
}
|
|
448
|
+
function onContextMenu(e) {
|
|
449
|
+
e.preventDefault();
|
|
450
|
+
show(e.clientX, e.clientY);
|
|
451
|
+
}
|
|
452
|
+
// -------------------------------------------------------------------
|
|
453
|
+
// Attach
|
|
454
|
+
// -------------------------------------------------------------------
|
|
455
|
+
root.addEventListener('contextmenu', onContextMenu);
|
|
456
|
+
// -------------------------------------------------------------------
|
|
457
|
+
// Handle
|
|
458
|
+
// -------------------------------------------------------------------
|
|
459
|
+
const handle = {
|
|
460
|
+
get isOpen() { return isMenuOpen; },
|
|
461
|
+
show,
|
|
462
|
+
hide,
|
|
463
|
+
dispose() {
|
|
464
|
+
hide();
|
|
465
|
+
root.removeEventListener('contextmenu', onContextMenu);
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
return handle;
|
|
469
|
+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CAAC;IAED,SAAS,aAAa,CAAC,CAAa;QAClC,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,sEAAsE;IACtE,SAAS;IACT,sEAAsE;IAEtE,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAEpD,sEAAsE;IACtE,SAAS;IACT,sEAAsE;IAEtE,MAAM,MAAM,GAAsB;QAChC,IAAI,MAAM,KAAK,OAAO,UAAU,CAAC,CAAC,CAAC;QAEnC,IAAI;QACJ,IAAI;QAEJ,OAAO;YACL,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QACzD,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/editor.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { WebEditorConfig, WebEditor } from './types.js';
|
|
|
14
14
|
* Create a web editor instance backed by the RTIF engine.
|
|
15
15
|
*
|
|
16
16
|
* Sets up `contenteditable`, attaches all event handlers, performs the initial
|
|
17
|
-
* render, and optionally auto-focuses. Returns a {@link WebEditor}
|
|
17
|
+
* render, and optionally auto-focuses. Returns a {@link WebEditor} instance with imperative control methods.
|
|
18
18
|
*
|
|
19
19
|
* @param config - Editor configuration (root element, engine, options)
|
|
20
20
|
* @returns A WebEditor instance with imperative control methods
|
package/dist/editor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EAKV,MAAM,YAAY,CAAC;AAgIpB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAq5BlE"}
|