@haklex/rich-renderer-linkcard 0.4.0 → 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":"LinkCardEditDecorator.d.ts","sourceRoot":"","sources":["../src/LinkCardEditDecorator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAYtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK1C,UAAU,0BAA0B;IAClC,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,wBAAgB,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,0BAA0B,2CA0I/F"}
1
+ {"version":3,"file":"LinkCardEditDecorator.d.ts","sourceRoot":"","sources":["../src/LinkCardEditDecorator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAkBtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAM1C,UAAU,0BAA0B;IAClC,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,wBAAgB,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,0BAA0B,2CAuJ/F"}
@@ -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
@@ -1,13 +1,24 @@
1
1
  import { A as fetchJsonWithContext, C as githubIssuePlugin, D as LanguageToColorMap, E as leetcodePlugin, M as arxivPlugin, O as camelcaseKeys, S as githubPrPlugin, T as githubCommitPlugin, _ as tmdbPlugin, a as editInput, b as bangumiPlugin, c as editUrlRow, d as matchUrl, f as useUrlMatcher, g as createMxSpacePlugin, h as plugins, i as useLinkCardFetchContext, j as generateColor, k as fetchGitHubApi, l as editWrapper, m as pluginMap, n as LinkCardSkeleton, o as editLinkIcon, p as getPluginByName, r as LinkCardFetchProvider, s as editPanel, t as LinkCardRenderer, u as semanticClassNames, v as qqMusicPlugin, w as githubDiscussionPlugin, x as githubRepoPlugin, y as neteaseMusicPlugin } from "./LinkCardRenderer-DqaMJub3.js";
2
2
  import { $createLinkNode, $isLinkNode } from "@lexical/link";
3
3
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
4
- import { $createNodeSelection, $createParagraphNode, $createTextNode, $getNodeByKey, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_LOW, PASTE_COMMAND } from "lexical";
4
+ import { $createNodeSelection, $createParagraphNode, $createTextNode, $getNodeByKey, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_LOW, PASTE_COMMAND, REDO_COMMAND, UNDO_COMMAND } from "lexical";
5
5
  import { CreditCard, ExternalLink, Link, RemoveFormatting, Unlink } from "lucide-react";
6
6
  import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { $isLinkCardNode, LinkCardNode } from "@haklex/rich-editor/nodes";
9
9
  import { LinkCardRenderer as LinkCardRenderer$1, createRendererDecoration } from "@haklex/rich-editor/renderers";
10
10
  import { ActionBar, ActionButton, Popover, PopoverPanel, PopoverTrigger } from "@haklex/rich-editor-ui";
11
+ //#region src/history-shortcuts.ts
12
+ function getEditorHistoryShortcut(event, options = {}) {
13
+ if (options.isDirty) return null;
14
+ if (event.altKey) return null;
15
+ if (!event.metaKey && !event.ctrlKey) return null;
16
+ const key = event.key.toLowerCase();
17
+ if (key === "z") return event.shiftKey ? "redo" : "undo";
18
+ if (key === "y" && event.ctrlKey && !event.metaKey && !event.shiftKey) return "redo";
19
+ return null;
20
+ }
21
+ //#endregion
11
22
  //#region src/LinkCardEditDecorator.tsx
12
23
  function LinkCardEditDecorator({ nodeKey, payload, children }) {
13
24
  const [editor] = useLexicalComposerContext();
@@ -71,6 +82,17 @@ function LinkCardEditDecorator({ nodeKey, payload, children }) {
71
82
  setUrl(payload.url);
72
83
  }
73
84
  }, [commitUrl, payload.url]);
85
+ const handlePanelKeyDown = useCallback((e) => {
86
+ const shortcut = getEditorHistoryShortcut(e, { isDirty: url !== payload.url });
87
+ if (!shortcut) return;
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ editor.dispatchCommand(shortcut === "undo" ? UNDO_COMMAND : REDO_COMMAND, void 0);
91
+ }, [
92
+ editor,
93
+ payload.url,
94
+ url
95
+ ]);
74
96
  const handleOpen = useCallback(() => {
75
97
  window.open(payload.url, "_blank", "noopener,noreferrer");
76
98
  }, [payload.url]);
@@ -92,6 +114,7 @@ function LinkCardEditDecorator({ nodeKey, payload, children }) {
92
114
  className: `${editPanel} ${semanticClassNames.editPanel}`,
93
115
  side: "bottom",
94
116
  sideOffset: 8,
117
+ onKeyDown: handlePanelKeyDown,
95
118
  children: [/* @__PURE__ */ jsxs("div", {
96
119
  className: `${editUrlRow} ${semanticClassNames.editUrlRow}`,
97
120
  children: [/* @__PURE__ */ jsx(Link, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-renderer-linkcard",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Rich link preview card renderer with extensible URL plugins",
5
5
  "repository": {
6
6
  "type": "git",