@djangocfg/ui-tools 2.1.376 → 2.1.378

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.
@@ -0,0 +1,67 @@
1
+ // SubmitOnEnter — Tiptap extension that hooks ProseMirror's keymap
2
+ // before StarterKit's HardBreak so Enter consistently submits and
3
+ // Shift+Enter inserts a newline (ChatGPT / Telegram behaviour).
4
+ //
5
+ // Why an extension and not a wrapper `onKeyDown` handler:
6
+ //
7
+ // Tiptap registers its keymaps inside the ProseMirror keymap
8
+ // plugin, which runs in the ProseMirror dispatch pipeline. A React
9
+ // `onKeyDown` / `onKeyDownCapture` on a wrapper div fires AFTER
10
+ // ProseMirror has already committed the HardBreak transaction in
11
+ // the same event tick — so calling `preventDefault()` there is too
12
+ // late: the user sees a hard-break flash in, the React handler
13
+ // then runs its preventDefault, and the next Enter submits.
14
+ //
15
+ // Registering the keybinding via `addKeyboardShortcuts` puts us in
16
+ // the same keymap pipeline at a higher priority than StarterKit's
17
+ // default Enter binding, so we intercept before HardBreak runs.
18
+ //
19
+ // The handler also respects IME composition and the mention popover
20
+ // (Tiptap's suggestion plugin captures Enter when its popover is
21
+ // open — we mirror that by checking `.markdown-mention-list` in the
22
+ // DOM; same predicate the wrapper used).
23
+
24
+ import { Extension } from '@tiptap/core';
25
+
26
+ export interface SubmitOnEnterOptions {
27
+ /** Fired when Enter is pressed without Shift, no IME composition,
28
+ * and no mention popover open. Return `true` to consume the key
29
+ * (default behaviour), `false` to let ProseMirror handle it (i.e.
30
+ * fall back to HardBreak). */
31
+ onSubmit: () => boolean | void;
32
+ }
33
+
34
+ export const SubmitOnEnter = Extension.create<SubmitOnEnterOptions>({
35
+ name: 'submitOnEnter',
36
+
37
+ addOptions() {
38
+ return {
39
+ // Default no-op — explicit consumer must override. We never
40
+ // intercept Enter unless an onSubmit is wired, so leaving the
41
+ // extension installed with no handler is safe.
42
+ onSubmit: () => false,
43
+ };
44
+ },
45
+
46
+ addKeyboardShortcuts() {
47
+ return {
48
+ Enter: () => {
49
+ // Mention suggestion popover owns Enter while open.
50
+ // The suggestion plugin renders the list with this class
51
+ // (see createMentionSuggestion.ts).
52
+ if (typeof document !== 'undefined' && document.querySelector('.markdown-mention-list')) {
53
+ return false;
54
+ }
55
+ const result = this.options.onSubmit();
56
+ // Default: consume the key (true). Only let it fall through
57
+ // to HardBreak if onSubmit explicitly returned false.
58
+ return result !== false;
59
+ },
60
+ // Shift+Enter — always insert a newline. Tiptap's StarterKit
61
+ // already binds this to HardBreak; we re-bind to `false` (not
62
+ // handled) so the chain falls through cleanly even if other
63
+ // extensions try to grab Shift+Enter.
64
+ 'Shift-Enter': () => false,
65
+ };
66
+ },
67
+ });
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkUVIFD3TH_cjs = require('./chunk-UVIFD3TH.cjs');
4
- require('./chunk-XACCHZH2.cjs');
5
- require('./chunk-OLISEQHS.cjs');
6
-
7
-
8
-
9
- Object.defineProperty(exports, "ChatRoot", {
10
- enumerable: true,
11
- get: function () { return chunkUVIFD3TH_cjs.ChatRoot; }
12
- });
13
- //# sourceMappingURL=ChatRoot-F5XXERXU.cjs.map
14
- //# sourceMappingURL=ChatRoot-F5XXERXU.cjs.map
@@ -1,5 +0,0 @@
1
- export { ChatRoot } from './chunk-JXBEKSNT.mjs';
2
- import './chunk-NWUT327A.mjs';
3
- import './chunk-N2XQF2OL.mjs';
4
- //# sourceMappingURL=ChatRoot-T7D7QRCH.mjs.map
5
- //# sourceMappingURL=ChatRoot-T7D7QRCH.mjs.map