@zero-library/common 2.4.4 → 2.5.0

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.esm.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
- import { MinusCircleOutlined, PlusCircleOutlined, RedoOutlined, FileUnknownOutlined, FileZipOutlined, FileMarkdownOutlined, FileGifOutlined, FileImageOutlined, FileJpgOutlined, NotificationOutlined, VideoCameraOutlined, FilePptOutlined, FileExcelOutlined, FileWordOutlined, FilePdfOutlined, FileTextOutlined, ColumnWidthOutlined, MessageOutlined, BookOutlined, EditOutlined, DeleteOutlined, CloseOutlined } from '@ant-design/icons';
3
- import { Spin, Input, Typography, Tooltip as Tooltip$1, Button, message, Flex, Alert, Skeleton, Result, Splitter, Empty, Image, Drawer, Avatar, notification, Modal, Form, Card, List, Space, Popconfirm } from 'antd';
2
+ import { MessageOutlined, BookOutlined, EditOutlined, DeleteOutlined, CloseOutlined, MinusCircleOutlined, PlusCircleOutlined, RedoOutlined, FileUnknownOutlined, FileZipOutlined, FileMarkdownOutlined, FileGifOutlined, FileImageOutlined, FileJpgOutlined, NotificationOutlined, VideoCameraOutlined, FilePptOutlined, FileExcelOutlined, FileWordOutlined, FilePdfOutlined, FileTextOutlined, ColumnWidthOutlined } from '@ant-design/icons';
3
+ import { Spin, Input, Typography, Tooltip as Tooltip$1, Button, Flex, Form, Card, List, Space, Popconfirm, Empty, Modal, message, Alert, Skeleton, Result, Splitter, Image as Image$1, Drawer, Avatar, notification } from 'antd';
4
4
  import classNames2 from 'classnames';
5
5
  import { renderAsync } from 'docx-preview';
6
6
  import * as React from 'react';
7
- import React__default, { forwardRef, useState, useMemo, useEffect, useRef, useCallback, createContext, isValidElement, version, cloneElement, memo, useContext, Fragment as Fragment$1, lazy, Suspense } from 'react';
7
+ import React__default, { forwardRef, useState, useMemo, useEffect, useRef, useCallback, createContext, isValidElement, version, cloneElement, memo, useImperativeHandle, useContext, Fragment as Fragment$1, lazy, Suspense } from 'react';
8
8
  import AES from 'crypto-js/aes';
9
9
  import encUtf8 from 'crypto-js/enc-utf8';
10
10
  import { convert } from 'html-to-text';
@@ -32,20 +32,22 @@ import zh_CN from '@react-pdf-viewer/locales/lib/zh_CN.json';
32
32
  import '@react-pdf-viewer/page-navigation/lib/styles/index.css';
33
33
  import '@react-pdf-viewer/thumbnail/lib/styles/index.css';
34
34
  import '@react-pdf-viewer/zoom/lib/styles/index.css';
35
- import { mergeAttributes, isNodeSelection, posToDOMRect, useCurrentEditor, useEditorState, isTextSelection, useEditor, EditorContext, EditorContent } from '@tiptap/react';
35
+ import microApp from '@micro-zoe/micro-app';
36
+ import jsxCustomEvent from '@micro-zoe/micro-app/polyfill/jsx-custom-event';
37
+ import { mergeAttributes, useEditor, EditorContext, EditorContent, isNodeSelection, posToDOMRect, useCurrentEditor, useEditorState, isTextSelection } from '@tiptap/react';
36
38
  import { Highlight } from '@tiptap/extension-highlight';
37
- import { Image as Image$1 } from '@tiptap/extension-image';
39
+ import { Image } from '@tiptap/extension-image';
38
40
  import { TaskList, TaskItem } from '@tiptap/extension-list';
39
41
  import { Subscript } from '@tiptap/extension-subscript';
40
42
  import { Superscript } from '@tiptap/extension-superscript';
41
43
  import { TextAlign } from '@tiptap/extension-text-align';
42
44
  import { Typography as Typography$1 } from '@tiptap/extension-typography';
43
- import { Selection as Selection$1 } from '@tiptap/extensions';
45
+ import { Selection } from '@tiptap/extensions';
44
46
  import { StarterKit } from '@tiptap/starter-kit';
45
47
  import { TableHeader, TableRow, TableCell, Table } from '@tiptap/extension-table';
46
48
  import TiptapHorizontalRule from '@tiptap/extension-horizontal-rule';
47
49
  import { Node as Node$1, mergeAttributes as mergeAttributes$1, Extension, Mark } from '@tiptap/core';
48
- import { PluginKey, Plugin, TextSelection, Selection, NodeSelection, AllSelection } from '@tiptap/pm/state';
50
+ import { PluginKey, Plugin, TextSelection, Selection as Selection$1, NodeSelection, AllSelection } from '@tiptap/pm/state';
49
51
  import { shift, flip, offset, useMergeRefs, FloatingPortal, useFloating, autoUpdate, useTransitionStyles, useDismiss, useInteractions, FloatingDelayGroup, useHover, useFocus, useRole } from '@floating-ui/react';
50
52
  import { CellSelection } from '@tiptap/pm/tables';
51
53
  import { createPortal } from 'react-dom';
@@ -1528,9 +1530,9 @@ ${fence}`;
1528
1530
  function emit(type, data, to = "top") {
1529
1531
  const payload = { type, data, to };
1530
1532
  try {
1531
- window.parent.postMessage(payload, "*");
1533
+ window.postMessage(payload, "*");
1532
1534
  } catch (err) {
1533
- console.warn("emit parent failed", err);
1535
+ console.warn("emit failed", err);
1534
1536
  }
1535
1537
  }
1536
1538
  function emitToChild(iframeWindow, type, data, origin = "*") {
@@ -1545,33 +1547,91 @@ function emitToChild(iframeWindow, type, data, origin = "*") {
1545
1547
  console.warn("emit to child failed", err);
1546
1548
  }
1547
1549
  }
1548
- var useIframeRelayBridge_default = (allowedOrigins = ["*"]) => {
1549
- const handlers = useRef({});
1550
- useEffect(() => {
1551
- const onMessage = (evt) => {
1552
- const { data, source, origin } = evt;
1553
- if (!data || !isObject(data) || !data.type) return;
1554
- if (allowedOrigins[0] !== "*" && !allowedOrigins.includes(origin)) return;
1555
- const { type, data: params, to = "parent" } = data;
1556
- const isTop = window.parent === window;
1557
- if (to === "top" && !isTop) {
1558
- window.parent.postMessage(data, allowedOrigins[0] === "*" ? "*" : origin);
1559
- return;
1550
+ var hookInstances = /* @__PURE__ */ new Set();
1551
+ var handleGlobalMessage = (evt) => {
1552
+ const { data, source, origin } = evt;
1553
+ if (!data || !isObject(data) || !data.type) return;
1554
+ const { type, data: params, to = "top" } = data;
1555
+ const safeOrigin = origin || "*";
1556
+ const fns = [];
1557
+ let isAllowed = hookInstances.size === 0;
1558
+ hookInstances.forEach((ctx) => {
1559
+ const isMatch = ctx.allowedOrigins[0] === "*" || ctx.allowedOrigins.includes(safeOrigin);
1560
+ if (isMatch) {
1561
+ isAllowed = true;
1562
+ if (ctx.handlers[type]) {
1563
+ fns.push(...ctx.handlers[type]);
1560
1564
  }
1561
- const fns = handlers.current[type] || [];
1562
- fns.forEach((fn) => fn(params, source, origin));
1563
- };
1564
- window.addEventListener("message", onMessage);
1565
- return () => window.removeEventListener("message", onMessage);
1566
- }, [allowedOrigins]);
1567
- function on(type, handler) {
1568
- handlers.current[type] = handlers.current[type] || [];
1569
- handlers.current[type].push(handler);
1565
+ }
1566
+ });
1567
+ if (!isAllowed) return;
1568
+ const isTop = window.parent === window;
1569
+ const hasHandler = fns.length > 0;
1570
+ let shouldExecute = false;
1571
+ let shouldForward = false;
1572
+ switch (to) {
1573
+ case "nearest":
1574
+ shouldExecute = hasHandler;
1575
+ shouldForward = !hasHandler && !isTop;
1576
+ break;
1577
+ case "broadcast":
1578
+ shouldExecute = true;
1579
+ shouldForward = !isTop;
1580
+ break;
1581
+ case "top":
1582
+ shouldExecute = isTop;
1583
+ shouldForward = !isTop;
1584
+ break;
1585
+ case "parent":
1586
+ shouldExecute = true;
1587
+ shouldForward = source === window && !isTop;
1588
+ break;
1589
+ case "sibling":
1590
+ case "child":
1591
+ default:
1592
+ shouldExecute = true;
1593
+ shouldForward = false;
1594
+ break;
1570
1595
  }
1571
- function off(type, handler) {
1572
- handlers.current[type] = (handlers.current[type] || []).filter((fn) => fn !== handler);
1596
+ if (shouldExecute && hasHandler) {
1597
+ fns.forEach((fn) => fn(params, source, origin));
1573
1598
  }
1574
- return { on, off };
1599
+ if (shouldForward && !isTop && window.parent !== window) {
1600
+ try {
1601
+ window.parent.postMessage(data, "*");
1602
+ } catch (err) {
1603
+ console.warn("IframeRelayBridge forward failed:", err);
1604
+ }
1605
+ }
1606
+ };
1607
+ if (window) {
1608
+ window.addEventListener("message", handleGlobalMessage);
1609
+ }
1610
+ var useIframeRelayBridge_default = (allowedOrigins = ["*"]) => {
1611
+ const ctxRef = useRef({
1612
+ handlers: {},
1613
+ allowedOrigins
1614
+ });
1615
+ ctxRef.current.allowedOrigins = allowedOrigins;
1616
+ useEffect(() => {
1617
+ const ctx = ctxRef.current;
1618
+ hookInstances.add(ctx);
1619
+ return () => {
1620
+ hookInstances.delete(ctx);
1621
+ };
1622
+ }, []);
1623
+ const on = useCallback((type, handler) => {
1624
+ const handlers = ctxRef.current.handlers;
1625
+ handlers[type] = handlers[type] || [];
1626
+ handlers[type].push(handler);
1627
+ }, []);
1628
+ const off = useCallback((type, handler) => {
1629
+ const handlers = ctxRef.current.handlers;
1630
+ if (handlers[type]) {
1631
+ handlers[type] = handlers[type].filter((fn) => fn !== handler);
1632
+ }
1633
+ }, []);
1634
+ return useMemo(() => ({ on, off }), [on, off]);
1575
1635
  };
1576
1636
  var useRefState_default = (init) => {
1577
1637
  const [state, setState] = useState(init);
@@ -2343,7 +2403,7 @@ var FilePreview_default = ({ suffix, fileUrl, pdfParams, password, searchValue,
2343
2403
  case "JPG":
2344
2404
  case "JPEG":
2345
2405
  case "GIF":
2346
- return /* @__PURE__ */ jsx(Image, { rootClassName: styles_module_default.nsPreviewImage, src: fileUrl, alt: "\u9884\u89C8\u56FE\u7247" });
2406
+ return /* @__PURE__ */ jsx(Image$1, { rootClassName: styles_module_default.nsPreviewImage, src: fileUrl, alt: "\u9884\u89C8\u56FE\u7247" });
2347
2407
  case "PDF":
2348
2408
  return /* @__PURE__ */ jsx(PdfPreview_default, { fileUrl, ...pdfParams, password, onSetPassword });
2349
2409
  case "PDF_IMG":
@@ -2382,6 +2442,110 @@ var FilePreviewDrawer_default = ({ open, title = "\u6587\u4EF6\u9884\u89C8", onC
2382
2442
  );
2383
2443
  };
2384
2444
 
2445
+ // src/components/MicroApp/styles.less
2446
+ var styles_default = {};
2447
+ var MicroApp_default = ({ name, url, className, onMounted, onError, data, ...rest }) => {
2448
+ const [loading, setLoading] = useState(false);
2449
+ useEffect(() => {
2450
+ setLoading(true);
2451
+ }, [url]);
2452
+ const handleLoad = () => {
2453
+ setLoading(false);
2454
+ onMounted?.();
2455
+ };
2456
+ const handleError = (e) => {
2457
+ setLoading(false);
2458
+ onError?.(e);
2459
+ };
2460
+ const microAppData = useMemo(() => {
2461
+ const parentMainSource = window?.microApp?.getData?.()?.mainSource || [];
2462
+ return { mainSource: [...parentMainSource, name], ...data };
2463
+ }, [data, name]);
2464
+ const TagName = microApp.tagName || "micro-app";
2465
+ return /* @__PURE__ */ jsxCustomEvent(Spin, { spinning: loading, wrapperClassName: "full-spin", tip: "\u52A0\u8F7D\u4E2D..." }, /* @__PURE__ */ jsxCustomEvent(
2466
+ TagName,
2467
+ {
2468
+ name,
2469
+ url,
2470
+ data: microAppData,
2471
+ class: classNames2(styles_default.microApp, className),
2472
+ onMounted: handleLoad,
2473
+ onError: handleError,
2474
+ ...rest
2475
+ }
2476
+ ));
2477
+ };
2478
+ var Drawer_default = ({ name: podName }) => {
2479
+ const [currentPod, setCurrentPod] = useState({ title: "", url: "" });
2480
+ const [fullPodOpen, setFullPodOpen] = useState(false);
2481
+ const { on, off } = useIframeRelayBridge_default();
2482
+ const openPod = useCallback(({ title, url, name }) => {
2483
+ if (name === podName) {
2484
+ setCurrentPod({ title, url });
2485
+ setFullPodOpen(true);
2486
+ }
2487
+ }, []);
2488
+ const onClosePod = useCallback(() => {
2489
+ setFullPodOpen(false);
2490
+ }, []);
2491
+ useEffect(() => {
2492
+ on("openPod", openPod);
2493
+ on("onClosePod", onClosePod);
2494
+ return () => {
2495
+ off("openPod", openPod);
2496
+ off("onClosePod", onClosePod);
2497
+ };
2498
+ }, [openPod, onClosePod]);
2499
+ return /* @__PURE__ */ jsx(
2500
+ Drawer,
2501
+ {
2502
+ className: "no-padding-drawer",
2503
+ destroyOnHidden: true,
2504
+ title: currentPod.title,
2505
+ classNames: {
2506
+ header: currentPod.title === false ? "hidden" : ""
2507
+ },
2508
+ width: "100%",
2509
+ open: fullPodOpen,
2510
+ onClose: () => setFullPodOpen(false),
2511
+ children: /* @__PURE__ */ jsx(MicroApp_default, { iframe: true, name: podName, url: currentPod.url, "router-mode": "pure" }, currentPod.url)
2512
+ }
2513
+ );
2514
+ };
2515
+ var Window_default = ({ defaultUrl, name: appName }) => {
2516
+ const [windowUrl, setWindowUrl] = useState("");
2517
+ const [windowUrlKey, setWindowUrlKey, getWindowUrlKey] = useRefState_default(0);
2518
+ const { on, off } = useIframeRelayBridge_default();
2519
+ const onWindowUrlChange = (url) => {
2520
+ setWindowUrl(url);
2521
+ setWindowUrlKey(getWindowUrlKey() + 1);
2522
+ };
2523
+ useEffect(() => {
2524
+ const urlParams = getAllUrlParams(location.href);
2525
+ if (urlParams[appName]) {
2526
+ const url = microApp.router.decode(urlParams[appName]);
2527
+ onWindowUrlChange(url);
2528
+ } else {
2529
+ onWindowUrlChange(defaultUrl);
2530
+ }
2531
+ }, [defaultUrl, appName]);
2532
+ const openWindow = useCallback(
2533
+ ({ url, name }) => {
2534
+ if (appName === name) {
2535
+ onWindowUrlChange(url);
2536
+ }
2537
+ },
2538
+ [appName]
2539
+ );
2540
+ useEffect(() => {
2541
+ on("openWindow", openWindow);
2542
+ return () => {
2543
+ off("openWindow", openWindow);
2544
+ };
2545
+ }, [openWindow]);
2546
+ return windowUrl ? /* @__PURE__ */ jsx(MicroApp_default, { name: appName, url: windowUrl }, windowUrlKey) : null;
2547
+ };
2548
+
2385
2549
  // src/components/Iframe/styles.module.less
2386
2550
  var styles_module_default3 = {
2387
2551
  iframe: "styles_module_iframe"
@@ -2904,7 +3068,7 @@ var FloatingElement = forwardRef(
2904
3068
  const handleFloatingOpenChange = (open2) => {
2905
3069
  if (!open2 && editor && resetTextSelectionOnClose) {
2906
3070
  const tr = editor.state.tr.setSelection(
2907
- Selection.near(editor.state.doc.resolve(0))
3071
+ Selection$1.near(editor.state.doc.resolve(0))
2908
3072
  );
2909
3073
  editor.view.dispatch(tr);
2910
3074
  }
@@ -3017,7 +3181,7 @@ var FloatingElement = forwardRef(
3017
3181
  const nodeBefore = $pos.nodeBefore;
3018
3182
  if (!nodeBefore || nodeBefore.isBlock) return;
3019
3183
  const tr = state.tr.setSelection(
3020
- Selection.near(state.doc.resolve(posCoords.pos))
3184
+ Selection$1.near(state.doc.resolve(posCoords.pos))
3021
3185
  );
3022
3186
  view.dispatch(tr);
3023
3187
  };
@@ -3242,7 +3406,7 @@ var AnnotationSidebar_default = ({
3242
3406
  }
3243
3407
  return createPortal(sidebarContent, container);
3244
3408
  };
3245
- var createHtmlMark = (markName, ATTRS, classNames7) => {
3409
+ var createHtmlMark = (markName, ATTRS, classNames8) => {
3246
3410
  return Mark.create({
3247
3411
  name: markName,
3248
3412
  priority: 1e3,
@@ -3271,7 +3435,7 @@ var createHtmlMark = (markName, ATTRS, classNames7) => {
3271
3435
  return [
3272
3436
  "div",
3273
3437
  mergeAttributes$1(attrs, {
3274
- class: classNames7
3438
+ class: classNames8
3275
3439
  }),
3276
3440
  0
3277
3441
  ];
@@ -8568,271 +8732,293 @@ var usePageNo = (pageNoConfig) => {
8568
8732
  onPageChange
8569
8733
  };
8570
8734
  };
8571
- var MarkdownEditor_default = ({
8572
- value = ``,
8573
- onChange,
8574
- searchValue,
8575
- disabled,
8576
- extraNav,
8577
- fixedToolbar = true,
8578
- floatToolbar = true,
8579
- onQuote,
8580
- onDownloadFile,
8581
- annotationConfig,
8582
- collectionConfig,
8583
- pageNoConfig
8584
- }) => {
8585
- const isMobile = useIsBreakpoint();
8586
- const lastContentRef = useRef("");
8587
- const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
8588
- const {
8589
- setAnnotationEditor,
8590
- annotations,
8591
- setAnnotations,
8592
- selectedAnnotationId,
8593
- handleSelectAnnotation,
8594
- showAnnotationModal,
8595
- showAnnotation,
8596
- onCreateAnnotation,
8597
- closeAnnotationCreateModal,
8598
- onCreateAnnotationConfirm,
8599
- handleDeleteAnnotation,
8600
- handleEditAnnotation,
8601
- setShowAnnotation
8602
- } = useAnnotations(annotationConfig);
8603
- const {
8604
- setCollectionEditor,
8605
- collections,
8606
- setCollections,
8607
- selectedCollectionId,
8608
- handleSelectCollection,
8609
- showCollection,
8610
- setShowCollection,
8611
- onCreateCollection,
8612
- handleDeleteCollection
8613
- } = useCollections(collectionConfig);
8614
- const editor = useEditor({
8615
- immediatelyRender: false,
8616
- editorProps: {
8617
- attributes: {
8618
- autocomplete: "off",
8619
- autocorrect: "off",
8620
- autocapitalize: "off",
8621
- "aria-label": "\u4E3B\u5185\u5BB9\u533A\u57DF\uFF0C\u5F00\u59CB\u8F93\u5165\u6587\u672C..."
8622
- }
8623
- },
8624
- extensions: [
8625
- Markdown,
8626
- Mathematics.configure({
8627
- // 可选:KaTeX 自定义配置
8628
- katexOptions: {
8629
- throwOnError: false
8630
- }
8631
- // 可选:内联公式点击回调
8632
- // inlineOptions: {
8633
- // onClick: (node, pos) => {
8634
- // const newLaTeX = prompt('编辑公式 LaTeX:', node.attrs.latex)
8635
- // if (newLaTeX) {
8636
- // editor?.chain().setNodeSelection(pos).updateInlineMath({ latex: newLaTeX }).run()
8637
- // }
8638
- // }
8639
- // }
8640
- }),
8641
- StarterKit.configure({
8642
- horizontalRule: false,
8643
- link: {
8644
- openOnClick: false,
8645
- enableClickSelection: true
8735
+ var MarkdownEditor_default = forwardRef(
8736
+ ({
8737
+ value = ``,
8738
+ onChange,
8739
+ searchValue,
8740
+ disabled,
8741
+ extraNav,
8742
+ fixedToolbar = true,
8743
+ floatToolbar = true,
8744
+ onQuote,
8745
+ onDownloadFile,
8746
+ annotationConfig,
8747
+ collectionConfig,
8748
+ pageNoConfig
8749
+ }, ref) => {
8750
+ const isMobile = useIsBreakpoint();
8751
+ const lastContentRef = useRef("");
8752
+ const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
8753
+ const {
8754
+ setAnnotationEditor,
8755
+ annotations,
8756
+ setAnnotations,
8757
+ selectedAnnotationId,
8758
+ handleSelectAnnotation,
8759
+ showAnnotationModal,
8760
+ showAnnotation,
8761
+ onCreateAnnotation,
8762
+ closeAnnotationCreateModal,
8763
+ onCreateAnnotationConfirm,
8764
+ handleDeleteAnnotation,
8765
+ handleEditAnnotation,
8766
+ setShowAnnotation
8767
+ } = useAnnotations(annotationConfig);
8768
+ const {
8769
+ setCollectionEditor,
8770
+ collections,
8771
+ setCollections,
8772
+ selectedCollectionId,
8773
+ handleSelectCollection,
8774
+ showCollection,
8775
+ setShowCollection,
8776
+ onCreateCollection,
8777
+ handleDeleteCollection
8778
+ } = useCollections(collectionConfig);
8779
+ const editor = useEditor({
8780
+ immediatelyRender: false,
8781
+ editorProps: {
8782
+ attributes: {
8783
+ autocomplete: "off",
8784
+ autocorrect: "off",
8785
+ autocapitalize: "off",
8786
+ "aria-label": "\u4E3B\u5185\u5BB9\u533A\u57DF\uFF0C\u5F00\u59CB\u8F93\u5165\u6587\u672C..."
8646
8787
  }
8647
- }),
8648
- HorizontalRule,
8649
- TextAlign.configure({ types: ["heading", "paragraph"] }),
8650
- TaskList,
8651
- TaskItem.configure({ nested: true }),
8652
- Highlight.configure({ multicolor: true }),
8653
- Image$1,
8654
- Typography$1,
8655
- Superscript,
8656
- Subscript,
8657
- Selection$1,
8658
- Table.configure({
8659
- resizable: true
8660
- // 可选,允许调整表格大小
8661
- }),
8662
- TableHeader,
8663
- TableRow,
8664
- TableCell,
8665
- // ImageUploadNode.configure({
8666
- // accept: 'image/*',
8667
- // maxSize: MAX_FILE_SIZE,
8668
- // limit: 3,
8669
- // upload: handleImageUpload,
8670
- // onError: (error) => console.error('上传失败:', error)
8671
- // }),
8672
- ...pageNoConfig?.enabled ? [
8673
- pageNoMark_default,
8674
- PageNoExtension.configure({
8675
- onPageChange,
8676
- containerSelector: "#contentWrapper"
8677
- })
8678
- ] : [],
8679
- searchAndReplace_default.configure({
8680
- searchResultClass: "cube-hl",
8681
- // class to give to found items. default 'cube-hl'
8682
- disableRegex: false
8683
- // also no need to explain
8684
- }),
8685
- ...annotationConfig?.enabled ? [
8686
- AnnotationMark,
8687
- AnnotationPlugin.configure({
8688
- onAnnotationsChange: setAnnotations,
8689
- onSelectAnnotation: (annotation) => {
8690
- handleSelectAnnotation(annotation?.[ANNOTATION_ATTRS[0]]);
8788
+ },
8789
+ extensions: [
8790
+ Markdown,
8791
+ Mathematics.configure({
8792
+ // 可选:KaTeX 自定义配置
8793
+ katexOptions: {
8794
+ throwOnError: false
8691
8795
  }
8692
- })
8693
- ] : [],
8694
- // 摘录功能扩展
8695
- ...collectionConfig?.enabled ? [
8696
- CollectionMark,
8697
- CollectionPlugin.configure({
8698
- onCollectionsChange: setCollections,
8699
- onSelectCollection: (collection) => {
8700
- handleSelectCollection(collection?.[COLLECTION_ATTRS[0]]);
8796
+ // 可选:内联公式点击回调
8797
+ // inlineOptions: {
8798
+ // onClick: (node, pos) => {
8799
+ // const newLaTeX = prompt('编辑公式 LaTeX:', node.attrs.latex)
8800
+ // if (newLaTeX) {
8801
+ // editor?.chain().setNodeSelection(pos).updateInlineMath({ latex: newLaTeX }).run()
8802
+ // }
8803
+ // }
8804
+ // }
8805
+ }),
8806
+ StarterKit.configure({
8807
+ horizontalRule: false,
8808
+ link: {
8809
+ openOnClick: false,
8810
+ enableClickSelection: true
8701
8811
  }
8702
- })
8703
- ] : []
8704
- ],
8705
- content: value,
8706
- contentType: "markdown",
8707
- onUpdate: () => {
8708
- const markdownOutput = getMarkdown();
8709
- if (markdownOutput === lastContentRef.current) return;
8710
- lastContentRef.current = markdownOutput;
8711
- onChange?.(markdownOutput);
8712
- }
8713
- });
8714
- const getMarkdown = () => {
8715
- if (!editor) return "";
8716
- if (editor.isEmpty) return "";
8717
- return editor.getMarkdown();
8718
- };
8719
- useEffect(() => {
8720
- if (!editor) return;
8721
- setAnnotationEditor(editor);
8722
- setCollectionEditor(editor);
8723
- setPageNoEditor(editor);
8724
- }, [editor]);
8725
- useEffect(() => {
8726
- if (!editor) return;
8727
- if (lastContentRef.current === value) return;
8728
- editor?.commands.setContent(value, { contentType: "markdown" });
8729
- editor?.commands.focus("start");
8730
- lastContentRef.current = value;
8731
- }, [value, editor]);
8732
- useEffect(() => {
8733
- editor?.commands.setSearchTerm(searchValue || "");
8734
- }, [searchValue, value, editor]);
8735
- useEffect(() => {
8736
- editor?.setEditable(!disabled);
8737
- }, [disabled, editor]);
8738
- const downloadFile2 = () => {
8739
- onDownloadFile?.(getMarkdown(), "docx");
8740
- };
8741
- const fixedTools = useMemo(() => isArray(fixedToolbar) ? fixedToolbar : void 0, [fixedToolbar]);
8742
- const floatTools = useMemo(() => isArray(floatToolbar) ? floatToolbar : void 0, [floatToolbar]);
8743
- return /* @__PURE__ */ jsxs(Flex, { className: "height-full width-full", children: [
8744
- /* @__PURE__ */ jsx("div", { className: classNames2("height-full", "flex-1", styles_module_default4.editorParent), children: /* @__PURE__ */ jsxs(EditorContext.Provider, { value: { editor }, children: [
8745
- /* @__PURE__ */ jsxs(Fragment, { children: [
8746
- /* @__PURE__ */ jsxs(Flex, { justify: "end", align: "center", children: [
8747
- fixedToolbar !== false && /* @__PURE__ */ jsx(
8812
+ }),
8813
+ HorizontalRule,
8814
+ TextAlign.configure({ types: ["heading", "paragraph"] }),
8815
+ TaskList,
8816
+ TaskItem.configure({ nested: true }),
8817
+ Highlight.configure({ multicolor: true }),
8818
+ Image,
8819
+ Typography$1,
8820
+ Superscript,
8821
+ Subscript,
8822
+ Selection,
8823
+ Table.configure({
8824
+ resizable: true
8825
+ // 可选,允许调整表格大小
8826
+ }),
8827
+ TableHeader,
8828
+ TableRow,
8829
+ TableCell,
8830
+ // ImageUploadNode.configure({
8831
+ // accept: 'image/*',
8832
+ // maxSize: MAX_FILE_SIZE,
8833
+ // limit: 3,
8834
+ // upload: handleImageUpload,
8835
+ // onError: (error) => console.error('上传失败:', error)
8836
+ // }),
8837
+ ...pageNoConfig?.enabled ? [
8838
+ pageNoMark_default,
8839
+ PageNoExtension.configure({
8840
+ onPageChange,
8841
+ containerSelector: "#contentWrapper"
8842
+ })
8843
+ ] : [],
8844
+ searchAndReplace_default.configure({
8845
+ searchResultClass: "cube-hl",
8846
+ // class to give to found items. default 'cube-hl'
8847
+ disableRegex: false
8848
+ // also no need to explain
8849
+ }),
8850
+ ...annotationConfig?.enabled ? [
8851
+ AnnotationMark,
8852
+ AnnotationPlugin.configure({
8853
+ onAnnotationsChange: setAnnotations,
8854
+ onSelectAnnotation: (annotation) => {
8855
+ handleSelectAnnotation(annotation?.[ANNOTATION_ATTRS[0]]);
8856
+ }
8857
+ })
8858
+ ] : [],
8859
+ // 摘录功能扩展
8860
+ ...collectionConfig?.enabled ? [
8861
+ CollectionMark,
8862
+ CollectionPlugin.configure({
8863
+ onCollectionsChange: setCollections,
8864
+ onSelectCollection: (collection) => {
8865
+ handleSelectCollection(collection?.[COLLECTION_ATTRS[0]]);
8866
+ }
8867
+ })
8868
+ ] : []
8869
+ ],
8870
+ content: value,
8871
+ contentType: "markdown",
8872
+ onUpdate: () => {
8873
+ const markdownOutput = getMarkdown();
8874
+ if (markdownOutput === lastContentRef.current) return;
8875
+ lastContentRef.current = markdownOutput;
8876
+ onChange?.(markdownOutput);
8877
+ }
8878
+ });
8879
+ const getMarkdown = () => {
8880
+ if (!editor) return "";
8881
+ if (editor.isEmpty) return "";
8882
+ return editor.getMarkdown();
8883
+ };
8884
+ useImperativeHandle(
8885
+ ref,
8886
+ () => ({
8887
+ getEditor: () => editor,
8888
+ getMarkdown,
8889
+ focus: (pos) => {
8890
+ if (!editor) return;
8891
+ editor.commands.focus(pos);
8892
+ },
8893
+ insertContent: (value2, options) => {
8894
+ if (!editor) return;
8895
+ editor.chain().focus().insertContent(value2, options).run();
8896
+ },
8897
+ insertContentAt: (position, value2, options) => {
8898
+ if (!editor) return;
8899
+ editor.chain().focus().insertContentAt(position, value2, options).run();
8900
+ }
8901
+ }),
8902
+ [editor]
8903
+ );
8904
+ useEffect(() => {
8905
+ if (!editor) return;
8906
+ setAnnotationEditor(editor);
8907
+ setCollectionEditor(editor);
8908
+ setPageNoEditor(editor);
8909
+ }, [editor]);
8910
+ useEffect(() => {
8911
+ if (!editor) return;
8912
+ if (lastContentRef.current === value) return;
8913
+ editor?.commands.setContent(value, { contentType: "markdown" });
8914
+ editor?.commands.focus("start");
8915
+ lastContentRef.current = value;
8916
+ }, [value, editor]);
8917
+ useEffect(() => {
8918
+ editor?.commands.setSearchTerm(searchValue || "");
8919
+ }, [searchValue, value, editor]);
8920
+ useEffect(() => {
8921
+ editor?.setEditable(!disabled);
8922
+ }, [disabled, editor]);
8923
+ const downloadFile2 = () => {
8924
+ onDownloadFile?.(getMarkdown(), "docx");
8925
+ };
8926
+ const fixedTools = useMemo(() => isArray(fixedToolbar) ? fixedToolbar : void 0, [fixedToolbar]);
8927
+ const floatTools = useMemo(() => isArray(floatToolbar) ? floatToolbar : void 0, [floatToolbar]);
8928
+ return /* @__PURE__ */ jsxs(Flex, { className: "height-full width-full", children: [
8929
+ /* @__PURE__ */ jsx("div", { className: classNames2("height-full", "flex-1", styles_module_default4.editorParent), children: /* @__PURE__ */ jsxs(EditorContext.Provider, { value: { editor }, children: [
8930
+ /* @__PURE__ */ jsxs(Fragment, { children: [
8931
+ /* @__PURE__ */ jsxs(Flex, { justify: "end", align: "center", children: [
8932
+ fixedToolbar !== false && /* @__PURE__ */ jsx(
8933
+ EditorToolbar,
8934
+ {
8935
+ isBubble: false,
8936
+ onQuote,
8937
+ onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8938
+ onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8939
+ tools: fixedTools
8940
+ }
8941
+ ),
8942
+ /* @__PURE__ */ jsxs(Flex, { gap: 8, align: "center", className: classNames2(styles_module_default4.extraToolbar), children: [
8943
+ annotationConfig?.enabled && annotationConfig?.showListButton !== false && /* @__PURE__ */ jsx(
8944
+ Button,
8945
+ {
8946
+ size: "small",
8947
+ title: "\u6279\u6CE8\u5217\u8868",
8948
+ icon: /* @__PURE__ */ jsx(MessageOutlined, {}),
8949
+ color: "primary",
8950
+ variant: "text",
8951
+ onClick: () => setShowAnnotation(!showAnnotation)
8952
+ }
8953
+ ),
8954
+ collectionConfig?.enabled && collectionConfig?.showListButton !== false && /* @__PURE__ */ jsx(
8955
+ Button,
8956
+ {
8957
+ style: { gap: "2px" },
8958
+ size: "small",
8959
+ title: "\u6458\u5F55\u5217\u8868",
8960
+ icon: /* @__PURE__ */ jsx(BookOutlined, {}),
8961
+ color: "primary",
8962
+ variant: "text",
8963
+ onClick: () => setShowCollection(!showCollection),
8964
+ children: "\u6458\u5F55"
8965
+ }
8966
+ ),
8967
+ onDownloadFile && /* @__PURE__ */ jsx(Button, { size: "small", color: "primary", variant: "text", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
8968
+ extraNav
8969
+ ] })
8970
+ ] }),
8971
+ !isMobile && floatToolbar !== false && /* @__PURE__ */ jsx(FloatingElement, { editor, zIndex: 188, resetTextSelectionOnClose: false, className: styles_module_default4.editorFloatingToolbar, children: /* @__PURE__ */ jsx(
8748
8972
  EditorToolbar,
8749
8973
  {
8750
- isBubble: false,
8974
+ isBubble: true,
8751
8975
  onQuote,
8752
8976
  onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8753
8977
  onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8754
- tools: fixedTools
8978
+ tools: floatTools
8755
8979
  }
8756
- ),
8757
- /* @__PURE__ */ jsxs(Flex, { gap: 8, align: "center", className: classNames2(styles_module_default4.extraToolbar), children: [
8758
- annotationConfig?.enabled && annotationConfig?.showListButton !== false && /* @__PURE__ */ jsx(
8759
- Button,
8760
- {
8761
- size: "small",
8762
- title: "\u6279\u6CE8\u5217\u8868",
8763
- icon: /* @__PURE__ */ jsx(MessageOutlined, {}),
8764
- color: "primary",
8765
- variant: "text",
8766
- onClick: () => setShowAnnotation(!showAnnotation)
8767
- }
8768
- ),
8769
- collectionConfig?.enabled && collectionConfig?.showListButton !== false && /* @__PURE__ */ jsx(
8770
- Button,
8771
- {
8772
- style: { gap: "2px" },
8773
- size: "small",
8774
- title: "\u6458\u5F55\u5217\u8868",
8775
- icon: /* @__PURE__ */ jsx(BookOutlined, {}),
8776
- color: "primary",
8777
- variant: "text",
8778
- onClick: () => setShowCollection(!showCollection),
8779
- children: "\u6458\u5F55"
8780
- }
8781
- ),
8782
- onDownloadFile && /* @__PURE__ */ jsx(Button, { size: "small", color: "primary", variant: "text", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
8783
- extraNav
8784
- ] })
8980
+ ) })
8785
8981
  ] }),
8786
- !isMobile && floatToolbar !== false && /* @__PURE__ */ jsx(FloatingElement, { editor, zIndex: 188, resetTextSelectionOnClose: false, className: styles_module_default4.editorFloatingToolbar, children: /* @__PURE__ */ jsx(
8787
- EditorToolbar,
8982
+ /* @__PURE__ */ jsx("div", { id: "contentWrapper", className: classNames2(styles_module_default4.contentWrapper, "scroll-fade-in"), children: /* @__PURE__ */ jsx(
8983
+ EditorContent,
8788
8984
  {
8789
- isBubble: true,
8790
- onQuote,
8791
- onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8792
- onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8793
- tools: floatTools
8985
+ editor,
8986
+ role: "presentation",
8987
+ className: classNames2(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8794
8988
  }
8795
8989
  ) })
8990
+ ] }) }),
8991
+ annotationConfig?.enabled && /* @__PURE__ */ jsxs(Fragment, { children: [
8992
+ showAnnotation && /* @__PURE__ */ jsx("div", { className: classNames2("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsx(
8993
+ AnnotationSidebar_default,
8994
+ {
8995
+ disabled,
8996
+ annotations,
8997
+ selectedAnnotationId,
8998
+ handleSelectAnnotation: (id) => handleSelectAnnotation(id, "sidebar"),
8999
+ onEditAnnotation: handleEditAnnotation,
9000
+ onDeleteAnnotation: handleDeleteAnnotation,
9001
+ annotationConfig,
9002
+ onClose: () => setShowAnnotation(false)
9003
+ }
9004
+ ) }),
9005
+ showAnnotationModal && /* @__PURE__ */ jsx(AnnotationModal_default, { visible: showAnnotationModal, onCancel: closeAnnotationCreateModal, onConfirm: onCreateAnnotationConfirm })
8796
9006
  ] }),
8797
- /* @__PURE__ */ jsx("div", { id: "contentWrapper", className: classNames2(styles_module_default4.contentWrapper, "scroll-fade-in"), children: /* @__PURE__ */ jsx(
8798
- EditorContent,
8799
- {
8800
- editor,
8801
- role: "presentation",
8802
- className: classNames2(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8803
- }
8804
- ) })
8805
- ] }) }),
8806
- annotationConfig?.enabled && /* @__PURE__ */ jsxs(Fragment, { children: [
8807
- showAnnotation && /* @__PURE__ */ jsx("div", { className: classNames2("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsx(
8808
- AnnotationSidebar_default,
9007
+ collectionConfig?.enabled && showCollection && /* @__PURE__ */ jsx("div", { className: classNames2("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsx(
9008
+ collectionSidebar_default,
8809
9009
  {
8810
9010
  disabled,
8811
- annotations,
8812
- selectedAnnotationId,
8813
- handleSelectAnnotation: (id) => handleSelectAnnotation(id, "sidebar"),
8814
- onEditAnnotation: handleEditAnnotation,
8815
- onDeleteAnnotation: handleDeleteAnnotation,
8816
- annotationConfig,
8817
- onClose: () => setShowAnnotation(false)
9011
+ collections,
9012
+ selectedCollectionId,
9013
+ handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
9014
+ onDeleteCollection: handleDeleteCollection,
9015
+ collectionConfig,
9016
+ onClose: () => setShowCollection(false)
8818
9017
  }
8819
- ) }),
8820
- showAnnotationModal && /* @__PURE__ */ jsx(AnnotationModal_default, { visible: showAnnotationModal, onCancel: closeAnnotationCreateModal, onConfirm: onCreateAnnotationConfirm })
8821
- ] }),
8822
- collectionConfig?.enabled && showCollection && /* @__PURE__ */ jsx("div", { className: classNames2("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsx(
8823
- collectionSidebar_default,
8824
- {
8825
- disabled,
8826
- collections,
8827
- selectedCollectionId,
8828
- handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
8829
- onDeleteCollection: handleDeleteCollection,
8830
- collectionConfig,
8831
- onClose: () => setShowCollection(false)
8832
- }
8833
- ) })
8834
- ] });
8835
- };
9018
+ ) })
9019
+ ] });
9020
+ }
9021
+ );
8836
9022
 
8837
9023
  // src/components/MarkDrawing/styles.module.less
8838
9024
  var styles_module_default7 = {
@@ -8935,6 +9121,6 @@ var UserAvatar_default = ({ size, avatarSrc, userName }) => {
8935
9121
  return avatarSrc ? /* @__PURE__ */ jsx(Avatar, { size, src: avatarSrc }) : /* @__PURE__ */ jsx(Avatar, { size, className: "cursor-pointer", style: { backgroundColor: "var(--ant-color-primary)" }, children: userName?.slice(0, 1)?.toLocaleUpperCase() });
8936
9122
  };
8937
9123
 
8938
- export { AudioPlayer_default as AudioPlayer, BusinessCode, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, DocxPreview_default as DocxPreview, FileIcon_default as FileIcon, FilePreview_default as FilePreview, FilePreviewDrawer_default as FilePreviewDrawer, HttpStatus, Iframe_default as Iframe, LazyComponent_default as LazyComponent, MarkDrawing_default as MarkDrawing, MarkdownEditor_default as MarkdownEditor, MarkdownPreview_default as MarkdownPreview, MultiEmailValidator, PdfImagePreview_default as PdfImagePreview, PdfPreview_default as PdfPreview, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, RenderMarkdown_default as RenderMarkdown, RenderWrapper_default as RenderWrapper, ThanNumLengthValidator, ThanNumValidator, UserAvatar_default as UserAvatar, VideoPlayer_default as VideoPlayer, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval2 as setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, useAsyncQueue_default as useAsyncQueue, useAutoRefresh_default as useAutoRefresh, useCountDown_default as useCountDown, useCreateValtioContext_default as useCreateValtioContext, useDebounce_default as useDebounce, useDeepEffect_default as useDeepEffect, useIframeRelayBridge_default as useIframeRelayBridge, useRefState_default as useRefState, useSyncInput_default as useSyncInput, useThrottle_default as useThrottle, useWebSocket_default as useWebSocket };
9124
+ export { AudioPlayer_default as AudioPlayer, BusinessCode, DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, DEFAULT_YEAR_MONTH_DAY_FORMAT, DEFAULT_YEAR_MONTH_FORMAT, DocxPreview_default as DocxPreview, FileIcon_default as FileIcon, FilePreview_default as FilePreview, FilePreviewDrawer_default as FilePreviewDrawer, HttpStatus, Iframe_default as Iframe, LazyComponent_default as LazyComponent, MarkDrawing_default as MarkDrawing, MarkdownEditor_default as MarkdownEditor, MarkdownPreview_default as MarkdownPreview, MicroApp_default as MicroApp, Drawer_default as MicroAppDrawer, Window_default as MicroAppWindow, MultiEmailValidator, PdfImagePreview_default as PdfImagePreview, PdfPreview_default as PdfPreview, PhoneOrMobileValidator, RegBankCardNo, RegDetailAddress, RegEmail, RegFixedTelePhone, RegIdentityCardNo, RegMobile, RegNumNo, RegPassword, RegSmsCode, RegTaxNo, RegTelePhone, RenderMarkdown_default as RenderMarkdown, RenderWrapper_default as RenderWrapper, ThanNumLengthValidator, ThanNumValidator, UserAvatar_default as UserAvatar, VideoPlayer_default as VideoPlayer, absVal, addUrlLastSlash, aesDecrypt, aesEncrypt, arrToObj, buildUrlParams, cachedMessage, calculate, compareNum, convertCurrency, convertNewlineToBr, copyText, createRequest, createSecureManager, createTokenManager, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, executeScript, findTreeNodesByIds, formatDate, formatNumberWithCommas, formatSize, genNonDuplicateID, generateRandomNumbers, getAllUrlParams, getDeviceId, getEndOfTimestamp, getFileName, getFileSuffixName, getRowSpanCount, getStartOfTimestamp, getTimestamp, getWebSocketUrl, htmlToMarkdown, htmlToText, importThirdPartyFile, is, isArray, isBlob, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isJson, isLocalhost, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isReferenceType, isRegExp, isScriptSafe, isSet, isString, isUnDef, isWindow, markdownToText, minus, objToOptions, plus, precision, processItemList, propsMerge, setInterval2 as setInterval, setUrlMainSource, shouldRender, times, toFixed, transform, transforms, useAsyncQueue_default as useAsyncQueue, useAutoRefresh_default as useAutoRefresh, useCountDown_default as useCountDown, useCreateValtioContext_default as useCreateValtioContext, useDebounce_default as useDebounce, useDeepEffect_default as useDeepEffect, useIframeRelayBridge_default as useIframeRelayBridge, useRefState_default as useRefState, useSyncInput_default as useSyncInput, useThrottle_default as useThrottle, useWebSocket_default as useWebSocket };
8939
9125
  //# sourceMappingURL=index.esm.js.map
8940
9126
  //# sourceMappingURL=index.esm.js.map