@haklex/rich-renderer-video 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":"VideoEditRenderer.d.ts","sourceRoot":"","sources":["../src/VideoEditRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"VideoEditRenderer.d.ts","sourceRoot":"","sources":["../src/VideoEditRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAmBxE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,2CAQ1D"}
|
|
@@ -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
|
@@ -2,10 +2,21 @@ import { a as editOverlay, c as editPreview, d as root, f as semanticClassNames,
|
|
|
2
2
|
import { useRendererMode } from "@haklex/rich-editor";
|
|
3
3
|
import { ActionBar, ActionButton, Popover, PopoverPanel, PopoverTrigger } from "@haklex/rich-editor-ui";
|
|
4
4
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
5
|
-
import { $getNearestNodeFromDOMNode } from "lexical";
|
|
5
|
+
import { $getNearestNodeFromDOMNode, REDO_COMMAND, UNDO_COMMAND } from "lexical";
|
|
6
6
|
import { ExternalLink, ImageIcon, Trash2, Video } from "lucide-react";
|
|
7
7
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
//#region src/history-shortcuts.ts
|
|
10
|
+
function getEditorHistoryShortcut(event, options = {}) {
|
|
11
|
+
if (options.isDirty) return null;
|
|
12
|
+
if (event.altKey) return null;
|
|
13
|
+
if (!event.metaKey && !event.ctrlKey) return null;
|
|
14
|
+
const key = event.key.toLowerCase();
|
|
15
|
+
if (key === "z") return event.shiftKey ? "redo" : "undo";
|
|
16
|
+
if (key === "y" && event.ctrlKey && !event.metaKey && !event.shiftKey) return "redo";
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
9
20
|
//#region src/VideoEditRenderer.tsx
|
|
10
21
|
var UNSAFE_VIDEO_URL_RE = /^(?:javascript\s*:|vbscript\s*:|data\s*:(?!video\/))/i;
|
|
11
22
|
function VideoEditRenderer(props) {
|
|
@@ -74,6 +85,19 @@ function VideoEditRendererInner({ src, poster, width, height }) {
|
|
|
74
85
|
src,
|
|
75
86
|
poster
|
|
76
87
|
]);
|
|
88
|
+
const handlePanelKeyDown = useCallback((e) => {
|
|
89
|
+
const shortcut = getEditorHistoryShortcut(e, { isDirty: editSrc !== src || editPoster !== (poster || "") });
|
|
90
|
+
if (!shortcut) return;
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
e.stopPropagation();
|
|
93
|
+
editor.dispatchCommand(shortcut === "undo" ? UNDO_COMMAND : REDO_COMMAND, void 0);
|
|
94
|
+
}, [
|
|
95
|
+
editPoster,
|
|
96
|
+
editSrc,
|
|
97
|
+
editor,
|
|
98
|
+
poster,
|
|
99
|
+
src
|
|
100
|
+
]);
|
|
77
101
|
if (!editable) return /* @__PURE__ */ jsx(VideoRenderer, {
|
|
78
102
|
height,
|
|
79
103
|
poster,
|
|
@@ -122,6 +146,7 @@ function VideoEditRendererInner({ src, poster, width, height }) {
|
|
|
122
146
|
className: `${editPanel} ${semanticClassNames.editPanel}`,
|
|
123
147
|
side: "bottom",
|
|
124
148
|
sideOffset: 8,
|
|
149
|
+
onKeyDown: handlePanelKeyDown,
|
|
125
150
|
children: [
|
|
126
151
|
/* @__PURE__ */ jsxs("div", {
|
|
127
152
|
className: `${editField} ${semanticClassNames.editField}`,
|