@haklex/rich-renderer-mention 0.3.4 → 0.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MentionEditRenderer.d.ts","sourceRoot":"","sources":["../src/MentionEditRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MentionEditRenderer.d.ts","sourceRoot":"","sources":["../src/MentionEditRenderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAM9D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,oBAAoB,2CAQ9D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type EditorHistoryShortcut = 'redo' | 'undo';
|
|
2
|
+
export interface EditorHistoryShortcutEvent {
|
|
3
|
+
altKey?: boolean;
|
|
4
|
+
ctrlKey: boolean;
|
|
5
|
+
key: string;
|
|
6
|
+
metaKey: boolean;
|
|
7
|
+
shiftKey: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface EditorHistoryShortcutOptions {
|
|
10
|
+
isDirty?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function getEditorHistoryShortcut(event: EditorHistoryShortcutEvent, options?: EditorHistoryShortcutOptions): EditorHistoryShortcut | null;
|
|
13
|
+
//# sourceMappingURL=history-shortcuts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-shortcuts.d.ts","sourceRoot":"","sources":["../src/history-shortcuts.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,0BAA0B,EACjC,OAAO,GAAE,4BAAiC,GACzC,qBAAqB,GAAG,IAAI,CAgB9B"}
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,21 @@ import { useRendererMode } from "@haklex/rich-editor";
|
|
|
3
3
|
import { ActionBar, ActionButton, Popover, PopoverPanel, PopoverTrigger } from "@haklex/rich-editor-ui";
|
|
4
4
|
import { vars } from "@haklex/rich-style-token";
|
|
5
5
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
6
|
-
import { $getNearestNodeFromDOMNode } from "lexical";
|
|
6
|
+
import { $getNearestNodeFromDOMNode, REDO_COMMAND, UNDO_COMMAND } from "lexical";
|
|
7
7
|
import { AtSign, ExternalLink, Trash2, User } from "lucide-react";
|
|
8
8
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
//#region src/history-shortcuts.ts
|
|
11
|
+
function getEditorHistoryShortcut(event, options = {}) {
|
|
12
|
+
if (options.isDirty) return null;
|
|
13
|
+
if (event.altKey) return null;
|
|
14
|
+
if (!event.metaKey && !event.ctrlKey) return null;
|
|
15
|
+
const key = event.key.toLowerCase();
|
|
16
|
+
if (key === "z") return event.shiftKey ? "redo" : "undo";
|
|
17
|
+
if (key === "y" && event.ctrlKey && !event.metaKey && !event.shiftKey) return "redo";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
10
21
|
//#region src/MentionEditRenderer.tsx
|
|
11
22
|
var LEADING_AT_RE = /^@+/;
|
|
12
23
|
function MentionEditRenderer(props) {
|
|
@@ -79,6 +90,21 @@ function MentionEditRendererInner({ platform, handle, displayName }) {
|
|
|
79
90
|
handle,
|
|
80
91
|
displayName
|
|
81
92
|
]);
|
|
93
|
+
const handlePanelKeyDown = useCallback((e) => {
|
|
94
|
+
const shortcut = getEditorHistoryShortcut(e, { isDirty: editPlatform !== platform || editHandle !== handle || editDisplayName !== (displayName || "") });
|
|
95
|
+
if (!shortcut) return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
editor.dispatchCommand(shortcut === "undo" ? UNDO_COMMAND : REDO_COMMAND, void 0);
|
|
99
|
+
}, [
|
|
100
|
+
displayName,
|
|
101
|
+
editDisplayName,
|
|
102
|
+
editHandle,
|
|
103
|
+
editPlatform,
|
|
104
|
+
editor,
|
|
105
|
+
handle,
|
|
106
|
+
platform
|
|
107
|
+
]);
|
|
82
108
|
if (!editable) return /* @__PURE__ */ jsx(MentionRenderer, {
|
|
83
109
|
displayName,
|
|
84
110
|
handle,
|
|
@@ -109,6 +135,7 @@ function MentionEditRendererInner({ platform, handle, displayName }) {
|
|
|
109
135
|
className: `${editPanel} ${semanticClassNames.editPanel}`,
|
|
110
136
|
side: "bottom",
|
|
111
137
|
sideOffset: 8,
|
|
138
|
+
onKeyDown: handlePanelKeyDown,
|
|
112
139
|
children: [
|
|
113
140
|
/* @__PURE__ */ jsxs("div", {
|
|
114
141
|
className: `${editField} ${semanticClassNames.editField}`,
|