@zero-library/common 2.0.6 → 2.0.8

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/index.d.mts CHANGED
@@ -100,8 +100,9 @@ interface Props$2 {
100
100
  extraNav?: ReactNode;
101
101
  showToolbar?: boolean;
102
102
  onQuote?: (text: string) => void;
103
+ onDownloadFile?: (fileContent: string, targetFormat?: string) => Promise<void>;
103
104
  }
104
- declare const _default$3: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote }: Props$2) => react_jsx_runtime.JSX.Element;
105
+ declare const _default$3: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote, onDownloadFile }: Props$2) => react_jsx_runtime.JSX.Element;
105
106
 
106
107
  interface Props$1 {
107
108
  content?: string;
package/dist/index.d.ts CHANGED
@@ -100,8 +100,9 @@ interface Props$2 {
100
100
  extraNav?: ReactNode;
101
101
  showToolbar?: boolean;
102
102
  onQuote?: (text: string) => void;
103
+ onDownloadFile?: (fileContent: string, targetFormat?: string) => Promise<void>;
103
104
  }
104
- declare const _default$3: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote }: Props$2) => react_jsx_runtime.JSX.Element;
105
+ declare const _default$3: ({ value, onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar, onQuote, onDownloadFile }: Props$2) => react_jsx_runtime.JSX.Element;
105
106
 
106
107
  interface Props$1 {
107
108
  content?: string;
package/dist/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import { FileUnknownOutlined, FileZipOutlined, FileMarkdownOutlined, FileGifOutlined, FileImageOutlined, FileJpgOutlined, NotificationOutlined, VideoCameraOutlined, FilePptOutlined, FileExcelOutlined, FileWordOutlined, FilePdfOutlined, FileTextOutlined } from '@ant-design/icons';
3
3
  import * as React16 from 'react';
4
4
  import { forwardRef, useState, useMemo, useEffect, lazy, Suspense, createContext, useRef, useCallback, useContext } from 'react';
5
- import { Spin, notification, Modal, Result, Splitter, Empty, Image, Flex, Drawer, Avatar, Alert, Form, Input, Button } from 'antd';
5
+ import { Spin, notification, Modal, Result, Splitter, Empty, Image, Flex, Drawer, Tag, Avatar, Alert, Form, Input, Button } from 'antd';
6
6
  import parse from 'html-react-parser';
7
7
  import { jsonrepair } from 'jsonrepair';
8
8
  import markdownit from 'markdown-it';
@@ -43,6 +43,7 @@ import TiptapLink from '@tiptap/extension-link';
43
43
  import { Plugin, TextSelection, PluginKey } from '@tiptap/pm/state';
44
44
  import { DecorationSet, Decoration } from '@tiptap/pm/view';
45
45
  import { useMergeRefs, FloatingPortal, FloatingFocusManager, useListItem, FloatingDelayGroup, useFloating, offset, flip, shift, autoUpdate, useHover, useFocus, useDismiss, useRole, useInteractions, FloatingList, useClick, useListNavigation, useTypeahead, limitShift } from '@floating-ui/react';
46
+ import TurndownService from 'turndown';
46
47
  import { Node, mergeAttributes, Extension as Extension$1 } from '@tiptap/core';
47
48
 
48
49
  // src/components/File/styles.module.less
@@ -663,6 +664,7 @@ var downloadFile = (url, name) => {
663
664
  document.body.appendChild(a);
664
665
  a.click();
665
666
  document.body.removeChild(a);
667
+ window.URL.revokeObjectURL(url);
666
668
  };
667
669
  var addUrlLastSlash = (url = "") => {
668
670
  const u = new URL(url, "https://logosdata.cn");
@@ -980,6 +982,9 @@ axios.interceptors.request.use(
980
982
  );
981
983
  axios.interceptors.response.use(
982
984
  function(response) {
985
+ if (isBlob(response.data)) {
986
+ return response;
987
+ }
983
988
  if (response.data?.code !== OK && response.data?.code !== OK2) {
984
989
  const isPermission = response.data?.code === PERMISSION_DENIED;
985
990
  if (response.config?.showError !== false) {
@@ -4909,6 +4914,7 @@ var SearchAndReplace = Extension$1.create({
4909
4914
  }
4910
4915
  });
4911
4916
  var searchAndReplace_default = SearchAndReplace;
4917
+ var turndown = new TurndownService();
4912
4918
  var MainToolbarContent = ({
4913
4919
  onHighlighterClick,
4914
4920
  onLinkClick,
@@ -4968,7 +4974,7 @@ var MobileToolbarContent = ({ type, onBack }) => /* @__PURE__ */ jsxs(Fragment,
4968
4974
  /* @__PURE__ */ jsx(ToolbarSeparator, {}),
4969
4975
  type === "highlighter" ? /* @__PURE__ */ jsx(HighlightContent, {}) : /* @__PURE__ */ jsx(LinkContent, {})
4970
4976
  ] });
4971
- var MarkdownEditor_default = ({ value = "", onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar = true, onQuote }) => {
4977
+ var MarkdownEditor_default = ({ value = "", onChange, onScrollPage, searchValue, disabled, extraNav, showToolbar = true, onQuote, onDownloadFile }) => {
4972
4978
  const isMobile = useMobile();
4973
4979
  const windowSize = useWindowSize();
4974
4980
  const lastContentRef = useRef("");
@@ -5029,13 +5035,17 @@ var MarkdownEditor_default = ({ value = "", onChange, onScrollPage, searchValue,
5029
5035
  // })
5030
5036
  ],
5031
5037
  content: "",
5032
- onUpdate: ({ editor: editor2 }) => {
5033
- const markdownOutput = editor2.storage.markdown.getMarkdown();
5038
+ onUpdate: () => {
5039
+ const markdownOutput = getMarkdown();
5034
5040
  if (markdownOutput === lastContentRef.current) return;
5035
5041
  lastContentRef.current = markdownOutput;
5036
5042
  onChange?.(markdownOutput);
5037
5043
  }
5038
5044
  });
5045
+ const getMarkdown = () => {
5046
+ if (!editor) return "";
5047
+ return turndown.turndown(editor.getHTML());
5048
+ };
5039
5049
  const bodyRect = useCursorVisibility({
5040
5050
  editor,
5041
5051
  overlayHeight: toolbarRef.current?.getBoundingClientRect().height ?? 0
@@ -5143,11 +5153,17 @@ var MarkdownEditor_default = ({ value = "", onChange, onScrollPage, searchValue,
5143
5153
  ) : /* @__PURE__ */ jsx(MobileToolbarContent, { type: mobileView === "highlighter" ? "highlighter" : "link", onBack: () => setMobileView("main") })
5144
5154
  }
5145
5155
  ) });
5156
+ const downloadFile2 = () => {
5157
+ onDownloadFile?.(getMarkdown(), "docx");
5158
+ };
5146
5159
  return /* @__PURE__ */ jsx("div", { className: classNames2("height-full", "editor-parent"), children: /* @__PURE__ */ jsxs(EditorContext.Provider, { value: { editor }, children: [
5147
5160
  showToolbar && /* @__PURE__ */ jsxs(Fragment, { children: [
5148
5161
  /* @__PURE__ */ jsxs(Flex, { justify: "end", align: "center", children: [
5149
5162
  NsToolBar({ isBubble: false }),
5150
- extraNav && /* @__PURE__ */ jsx("div", { className: "m-l-16 m-r-16", children: extraNav })
5163
+ extraNav && /* @__PURE__ */ jsxs(Flex, { align: "center", className: "m-l-16 m-r-16", children: [
5164
+ onDownloadFile && /* @__PURE__ */ jsx(Tag, { bordered: false, color: "default", className: "cursor-pointer", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
5165
+ extraNav
5166
+ ] })
5151
5167
  ] }),
5152
5168
  !isMobile && /* @__PURE__ */ jsx(BubbleMenu, { editor, children: NsToolBar({ isBubble: true }) })
5153
5169
  ] }),