@zero-library/common 2.4.3 → 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.cjs.js CHANGED
@@ -33,6 +33,8 @@ var zh_CN = require('@react-pdf-viewer/locales/lib/zh_CN.json');
33
33
  require('@react-pdf-viewer/page-navigation/lib/styles/index.css');
34
34
  require('@react-pdf-viewer/thumbnail/lib/styles/index.css');
35
35
  require('@react-pdf-viewer/zoom/lib/styles/index.css');
36
+ var microApp = require('@micro-zoe/micro-app');
37
+ var jsxCustomEvent = require('@micro-zoe/micro-app/polyfill/jsx-custom-event');
36
38
  var react = require('@tiptap/react');
37
39
  var extensionHighlight = require('@tiptap/extension-highlight');
38
40
  var extensionImage = require('@tiptap/extension-image');
@@ -94,6 +96,8 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
94
96
  var markdownItKatex__default = /*#__PURE__*/_interopDefault(markdownItKatex);
95
97
  var parse__default = /*#__PURE__*/_interopDefault(parse);
96
98
  var zh_CN__default = /*#__PURE__*/_interopDefault(zh_CN);
99
+ var microApp__default = /*#__PURE__*/_interopDefault(microApp);
100
+ var jsxCustomEvent__default = /*#__PURE__*/_interopDefault(jsxCustomEvent);
97
101
  var TiptapHorizontalRule__default = /*#__PURE__*/_interopDefault(TiptapHorizontalRule);
98
102
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
99
103
  var DropdownMenuPrimitive__namespace = /*#__PURE__*/_interopNamespace(DropdownMenuPrimitive);
@@ -1570,9 +1574,9 @@ ${fence}`;
1570
1574
  function emit(type, data, to = "top") {
1571
1575
  const payload = { type, data, to };
1572
1576
  try {
1573
- window.parent.postMessage(payload, "*");
1577
+ window.postMessage(payload, "*");
1574
1578
  } catch (err) {
1575
- console.warn("emit parent failed", err);
1579
+ console.warn("emit failed", err);
1576
1580
  }
1577
1581
  }
1578
1582
  function emitToChild(iframeWindow, type, data, origin = "*") {
@@ -1587,33 +1591,91 @@ function emitToChild(iframeWindow, type, data, origin = "*") {
1587
1591
  console.warn("emit to child failed", err);
1588
1592
  }
1589
1593
  }
1590
- var useIframeRelayBridge_default = (allowedOrigins = ["*"]) => {
1591
- const handlers = React.useRef({});
1592
- React.useEffect(() => {
1593
- const onMessage = (evt) => {
1594
- const { data, source, origin } = evt;
1595
- if (!data || !isObject(data) || !data.type) return;
1596
- if (allowedOrigins[0] !== "*" && !allowedOrigins.includes(origin)) return;
1597
- const { type, data: params, to = "parent" } = data;
1598
- const isTop = window.parent === window;
1599
- if (to === "top" && !isTop) {
1600
- window.parent.postMessage(data, allowedOrigins[0] === "*" ? "*" : origin);
1601
- return;
1594
+ var hookInstances = /* @__PURE__ */ new Set();
1595
+ var handleGlobalMessage = (evt) => {
1596
+ const { data, source, origin } = evt;
1597
+ if (!data || !isObject(data) || !data.type) return;
1598
+ const { type, data: params, to = "top" } = data;
1599
+ const safeOrigin = origin || "*";
1600
+ const fns = [];
1601
+ let isAllowed = hookInstances.size === 0;
1602
+ hookInstances.forEach((ctx) => {
1603
+ const isMatch = ctx.allowedOrigins[0] === "*" || ctx.allowedOrigins.includes(safeOrigin);
1604
+ if (isMatch) {
1605
+ isAllowed = true;
1606
+ if (ctx.handlers[type]) {
1607
+ fns.push(...ctx.handlers[type]);
1602
1608
  }
1603
- const fns = handlers.current[type] || [];
1604
- fns.forEach((fn) => fn(params, source, origin));
1605
- };
1606
- window.addEventListener("message", onMessage);
1607
- return () => window.removeEventListener("message", onMessage);
1608
- }, [allowedOrigins]);
1609
- function on(type, handler) {
1610
- handlers.current[type] = handlers.current[type] || [];
1611
- handlers.current[type].push(handler);
1609
+ }
1610
+ });
1611
+ if (!isAllowed) return;
1612
+ const isTop = window.parent === window;
1613
+ const hasHandler = fns.length > 0;
1614
+ let shouldExecute = false;
1615
+ let shouldForward = false;
1616
+ switch (to) {
1617
+ case "nearest":
1618
+ shouldExecute = hasHandler;
1619
+ shouldForward = !hasHandler && !isTop;
1620
+ break;
1621
+ case "broadcast":
1622
+ shouldExecute = true;
1623
+ shouldForward = !isTop;
1624
+ break;
1625
+ case "top":
1626
+ shouldExecute = isTop;
1627
+ shouldForward = !isTop;
1628
+ break;
1629
+ case "parent":
1630
+ shouldExecute = true;
1631
+ shouldForward = source === window && !isTop;
1632
+ break;
1633
+ case "sibling":
1634
+ case "child":
1635
+ default:
1636
+ shouldExecute = true;
1637
+ shouldForward = false;
1638
+ break;
1612
1639
  }
1613
- function off(type, handler) {
1614
- handlers.current[type] = (handlers.current[type] || []).filter((fn) => fn !== handler);
1640
+ if (shouldExecute && hasHandler) {
1641
+ fns.forEach((fn) => fn(params, source, origin));
1642
+ }
1643
+ if (shouldForward && !isTop && window.parent !== window) {
1644
+ try {
1645
+ window.parent.postMessage(data, "*");
1646
+ } catch (err) {
1647
+ console.warn("IframeRelayBridge forward failed:", err);
1648
+ }
1615
1649
  }
1616
- return { on, off };
1650
+ };
1651
+ if (window) {
1652
+ window.addEventListener("message", handleGlobalMessage);
1653
+ }
1654
+ var useIframeRelayBridge_default = (allowedOrigins = ["*"]) => {
1655
+ const ctxRef = React.useRef({
1656
+ handlers: {},
1657
+ allowedOrigins
1658
+ });
1659
+ ctxRef.current.allowedOrigins = allowedOrigins;
1660
+ React.useEffect(() => {
1661
+ const ctx = ctxRef.current;
1662
+ hookInstances.add(ctx);
1663
+ return () => {
1664
+ hookInstances.delete(ctx);
1665
+ };
1666
+ }, []);
1667
+ const on = React.useCallback((type, handler) => {
1668
+ const handlers = ctxRef.current.handlers;
1669
+ handlers[type] = handlers[type] || [];
1670
+ handlers[type].push(handler);
1671
+ }, []);
1672
+ const off = React.useCallback((type, handler) => {
1673
+ const handlers = ctxRef.current.handlers;
1674
+ if (handlers[type]) {
1675
+ handlers[type] = handlers[type].filter((fn) => fn !== handler);
1676
+ }
1677
+ }, []);
1678
+ return React.useMemo(() => ({ on, off }), [on, off]);
1617
1679
  };
1618
1680
  var useRefState_default = (init) => {
1619
1681
  const [state, setState] = React.useState(init);
@@ -2424,6 +2486,110 @@ var FilePreviewDrawer_default = ({ open, title = "\u6587\u4EF6\u9884\u89C8", onC
2424
2486
  );
2425
2487
  };
2426
2488
 
2489
+ // src/components/MicroApp/styles.less
2490
+ var styles_default = {};
2491
+ var MicroApp_default = ({ name, url, className, onMounted, onError, data, ...rest }) => {
2492
+ const [loading, setLoading] = React.useState(false);
2493
+ React.useEffect(() => {
2494
+ setLoading(true);
2495
+ }, [url]);
2496
+ const handleLoad = () => {
2497
+ setLoading(false);
2498
+ onMounted?.();
2499
+ };
2500
+ const handleError = (e) => {
2501
+ setLoading(false);
2502
+ onError?.(e);
2503
+ };
2504
+ const microAppData = React.useMemo(() => {
2505
+ const parentMainSource = window?.microApp?.getData?.()?.mainSource || [];
2506
+ return { mainSource: [...parentMainSource, name], ...data };
2507
+ }, [data, name]);
2508
+ const TagName = microApp__default.default.tagName || "micro-app";
2509
+ return /* @__PURE__ */ jsxCustomEvent__default.default(antd.Spin, { spinning: loading, wrapperClassName: "full-spin", tip: "\u52A0\u8F7D\u4E2D..." }, /* @__PURE__ */ jsxCustomEvent__default.default(
2510
+ TagName,
2511
+ {
2512
+ name,
2513
+ url,
2514
+ data: microAppData,
2515
+ class: classNames2__default.default(styles_default.microApp, className),
2516
+ onMounted: handleLoad,
2517
+ onError: handleError,
2518
+ ...rest
2519
+ }
2520
+ ));
2521
+ };
2522
+ var Drawer_default = ({ name: podName }) => {
2523
+ const [currentPod, setCurrentPod] = React.useState({ title: "", url: "" });
2524
+ const [fullPodOpen, setFullPodOpen] = React.useState(false);
2525
+ const { on, off } = useIframeRelayBridge_default();
2526
+ const openPod = React.useCallback(({ title, url, name }) => {
2527
+ if (name === podName) {
2528
+ setCurrentPod({ title, url });
2529
+ setFullPodOpen(true);
2530
+ }
2531
+ }, []);
2532
+ const onClosePod = React.useCallback(() => {
2533
+ setFullPodOpen(false);
2534
+ }, []);
2535
+ React.useEffect(() => {
2536
+ on("openPod", openPod);
2537
+ on("onClosePod", onClosePod);
2538
+ return () => {
2539
+ off("openPod", openPod);
2540
+ off("onClosePod", onClosePod);
2541
+ };
2542
+ }, [openPod, onClosePod]);
2543
+ return /* @__PURE__ */ jsxRuntime.jsx(
2544
+ antd.Drawer,
2545
+ {
2546
+ className: "no-padding-drawer",
2547
+ destroyOnHidden: true,
2548
+ title: currentPod.title,
2549
+ classNames: {
2550
+ header: currentPod.title === false ? "hidden" : ""
2551
+ },
2552
+ width: "100%",
2553
+ open: fullPodOpen,
2554
+ onClose: () => setFullPodOpen(false),
2555
+ children: /* @__PURE__ */ jsxRuntime.jsx(MicroApp_default, { iframe: true, name: podName, url: currentPod.url, "router-mode": "pure" }, currentPod.url)
2556
+ }
2557
+ );
2558
+ };
2559
+ var Window_default = ({ defaultUrl, name: appName }) => {
2560
+ const [windowUrl, setWindowUrl] = React.useState("");
2561
+ const [windowUrlKey, setWindowUrlKey, getWindowUrlKey] = useRefState_default(0);
2562
+ const { on, off } = useIframeRelayBridge_default();
2563
+ const onWindowUrlChange = (url) => {
2564
+ setWindowUrl(url);
2565
+ setWindowUrlKey(getWindowUrlKey() + 1);
2566
+ };
2567
+ React.useEffect(() => {
2568
+ const urlParams = getAllUrlParams(location.href);
2569
+ if (urlParams[appName]) {
2570
+ const url = microApp__default.default.router.decode(urlParams[appName]);
2571
+ onWindowUrlChange(url);
2572
+ } else {
2573
+ onWindowUrlChange(defaultUrl);
2574
+ }
2575
+ }, [defaultUrl, appName]);
2576
+ const openWindow = React.useCallback(
2577
+ ({ url, name }) => {
2578
+ if (appName === name) {
2579
+ onWindowUrlChange(url);
2580
+ }
2581
+ },
2582
+ [appName]
2583
+ );
2584
+ React.useEffect(() => {
2585
+ on("openWindow", openWindow);
2586
+ return () => {
2587
+ off("openWindow", openWindow);
2588
+ };
2589
+ }, [openWindow]);
2590
+ return windowUrl ? /* @__PURE__ */ jsxRuntime.jsx(MicroApp_default, { name: appName, url: windowUrl }, windowUrlKey) : null;
2591
+ };
2592
+
2427
2593
  // src/components/Iframe/styles.module.less
2428
2594
  var styles_module_default3 = {
2429
2595
  iframe: "styles_module_iframe"
@@ -2476,6 +2642,7 @@ var HorizontalRule = TiptapHorizontalRule__default.default.extend({
2476
2642
  // src/components/MarkdownEditor/pageNo/constant.ts
2477
2643
  var PAGE_NO_TAG = "page-no";
2478
2644
  var PAGE_NO_KEY = "PageNo";
2645
+ var SCROLL_TOP_OFFSET = 80;
2479
2646
 
2480
2647
  // src/components/MarkdownEditor/pageNo/pageNoMark.ts
2481
2648
  var pageNoMark_default = core.Node.create({
@@ -2605,7 +2772,7 @@ var PageNoExtension = core.Extension.create({
2605
2772
  pageNos.forEach((node) => {
2606
2773
  const rect = node.getBoundingClientRect();
2607
2774
  const top = rect.top - containerTop;
2608
- if (Math.abs(top) <= 80) {
2775
+ if (Math.abs(top) <= SCROLL_TOP_OFFSET) {
2609
2776
  closestNode = node;
2610
2777
  closestTopDiff = 0;
2611
2778
  } else if (top < 0 && top > closestTopDiff) {
@@ -3283,7 +3450,7 @@ var AnnotationSidebar_default = ({
3283
3450
  }
3284
3451
  return reactDom.createPortal(sidebarContent, container);
3285
3452
  };
3286
- var createHtmlMark = (markName, ATTRS, classNames7) => {
3453
+ var createHtmlMark = (markName, ATTRS, classNames8) => {
3287
3454
  return core.Mark.create({
3288
3455
  name: markName,
3289
3456
  priority: 1e3,
@@ -3312,7 +3479,7 @@ var createHtmlMark = (markName, ATTRS, classNames7) => {
3312
3479
  return [
3313
3480
  "div",
3314
3481
  core.mergeAttributes(attrs, {
3315
- class: classNames7
3482
+ class: classNames8
3316
3483
  }),
3317
3484
  0
3318
3485
  ];
@@ -3670,13 +3837,45 @@ function scrollEditorViewToPosInNextFrame(view, pos, options) {
3670
3837
  const { align = "start", behavior = "auto", offset: offset3 = 0 } = options || {};
3671
3838
  requestAnimationFrame(() => {
3672
3839
  try {
3673
- const result = view.domAtPos(pos);
3674
- if (!result) return;
3675
- const el = result.node.nodeType === Node.TEXT_NODE ? result.node.parentElement : result.node;
3676
- if (!el) return;
3677
3840
  const scrollParent = getScrollParent(view.dom);
3841
+ if (!scrollParent) return;
3678
3842
  const parentRect = scrollParent.getBoundingClientRect();
3679
- const targetRect = el.getBoundingClientRect();
3843
+ if (!parentRect.height) return;
3844
+ let el = null;
3845
+ const nodeDom = view.nodeDOM?.(pos);
3846
+ if (nodeDom) {
3847
+ el = nodeDom.nodeType === Node.TEXT_NODE ? nodeDom.parentElement : nodeDom;
3848
+ }
3849
+ if (!el) {
3850
+ const result = view.domAtPos(pos);
3851
+ if (result) {
3852
+ if (result.node.nodeType === Node.TEXT_NODE) {
3853
+ el = result.node.parentElement;
3854
+ } else {
3855
+ const container = result.node;
3856
+ const nodeAtOffset = container.childNodes?.[result.offset];
3857
+ const nodeBeforeOffset = container.childNodes?.[result.offset - 1];
3858
+ if (nodeAtOffset?.nodeType === Node.ELEMENT_NODE) {
3859
+ el = nodeAtOffset;
3860
+ } else if (nodeBeforeOffset?.nodeType === Node.ELEMENT_NODE) {
3861
+ el = nodeBeforeOffset;
3862
+ } else {
3863
+ el = container;
3864
+ }
3865
+ }
3866
+ }
3867
+ }
3868
+ let targetRect = null;
3869
+ if (el) {
3870
+ targetRect = el.getBoundingClientRect();
3871
+ } else {
3872
+ try {
3873
+ const coords = view.coordsAtPos(pos);
3874
+ targetRect = new DOMRect(coords.left, coords.top, coords.right - coords.left, coords.bottom - coords.top);
3875
+ } catch {
3876
+ return;
3877
+ }
3878
+ }
3680
3879
  let delta = 0;
3681
3880
  if (align === "start") {
3682
3881
  delta = targetRect.top - parentRect.top;
@@ -3685,8 +3884,10 @@ function scrollEditorViewToPosInNextFrame(view, pos, options) {
3685
3884
  } else if (align === "end") {
3686
3885
  delta = targetRect.bottom - parentRect.bottom;
3687
3886
  }
3887
+ const maxTop = Math.max(0, scrollParent.scrollHeight - scrollParent.clientHeight);
3888
+ const nextTop = Math.max(0, Math.min(scrollParent.scrollTop + delta - offset3, maxTop));
3688
3889
  scrollParent.scrollTo({
3689
- top: scrollParent.scrollTop + delta - offset3,
3890
+ top: nextTop,
3690
3891
  behavior
3691
3892
  });
3692
3893
  } catch (e) {
@@ -8532,7 +8733,7 @@ var usePageNo = (pageNoConfig) => {
8532
8733
  const setPageNoEditor = (newEditor) => {
8533
8734
  setEditor(newEditor);
8534
8735
  };
8535
- const onPageChange = useDebounce_default((pageNo = 0) => {
8736
+ const onPageChange = useDebounce_default((pageNo = 1) => {
8536
8737
  lastScrollToPageNoRef.current = pageNo;
8537
8738
  pageNoConfig?.onScrollPage?.(pageNo);
8538
8739
  }, 300);
@@ -8561,7 +8762,7 @@ var usePageNo = (pageNoConfig) => {
8561
8762
  const tryScroll = () => {
8562
8763
  const foundPos = findTargetPos();
8563
8764
  if (!isNullOrUnDef(foundPos)) {
8564
- scrollEditorViewToPosInNextFrame(editor.view, foundPos, { align: "start", behavior: "smooth" });
8765
+ scrollEditorViewToPosInNextFrame(editor.view, foundPos, { align: "start", offset: SCROLL_TOP_OFFSET });
8565
8766
  return;
8566
8767
  }
8567
8768
  tries += 1;
@@ -8575,271 +8776,293 @@ var usePageNo = (pageNoConfig) => {
8575
8776
  onPageChange
8576
8777
  };
8577
8778
  };
8578
- var MarkdownEditor_default = ({
8579
- value = ``,
8580
- onChange,
8581
- searchValue,
8582
- disabled,
8583
- extraNav,
8584
- fixedToolbar = true,
8585
- floatToolbar = true,
8586
- onQuote,
8587
- onDownloadFile,
8588
- annotationConfig,
8589
- collectionConfig,
8590
- pageNoConfig
8591
- }) => {
8592
- const isMobile = useIsBreakpoint();
8593
- const lastContentRef = React.useRef("");
8594
- const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
8595
- const {
8596
- setAnnotationEditor,
8597
- annotations,
8598
- setAnnotations,
8599
- selectedAnnotationId,
8600
- handleSelectAnnotation,
8601
- showAnnotationModal,
8602
- showAnnotation,
8603
- onCreateAnnotation,
8604
- closeAnnotationCreateModal,
8605
- onCreateAnnotationConfirm,
8606
- handleDeleteAnnotation,
8607
- handleEditAnnotation,
8608
- setShowAnnotation
8609
- } = useAnnotations(annotationConfig);
8610
- const {
8611
- setCollectionEditor,
8612
- collections,
8613
- setCollections,
8614
- selectedCollectionId,
8615
- handleSelectCollection,
8616
- showCollection,
8617
- setShowCollection,
8618
- onCreateCollection,
8619
- handleDeleteCollection
8620
- } = useCollections(collectionConfig);
8621
- const editor = react.useEditor({
8622
- immediatelyRender: false,
8623
- editorProps: {
8624
- attributes: {
8625
- autocomplete: "off",
8626
- autocorrect: "off",
8627
- autocapitalize: "off",
8628
- "aria-label": "\u4E3B\u5185\u5BB9\u533A\u57DF\uFF0C\u5F00\u59CB\u8F93\u5165\u6587\u672C..."
8629
- }
8630
- },
8631
- extensions: [
8632
- markdown.Markdown,
8633
- extensionMathematics.Mathematics.configure({
8634
- // 可选:KaTeX 自定义配置
8635
- katexOptions: {
8636
- throwOnError: false
8637
- }
8638
- // 可选:内联公式点击回调
8639
- // inlineOptions: {
8640
- // onClick: (node, pos) => {
8641
- // const newLaTeX = prompt('编辑公式 LaTeX:', node.attrs.latex)
8642
- // if (newLaTeX) {
8643
- // editor?.chain().setNodeSelection(pos).updateInlineMath({ latex: newLaTeX }).run()
8644
- // }
8645
- // }
8646
- // }
8647
- }),
8648
- starterKit.StarterKit.configure({
8649
- horizontalRule: false,
8650
- link: {
8651
- openOnClick: false,
8652
- enableClickSelection: true
8779
+ var MarkdownEditor_default = React.forwardRef(
8780
+ ({
8781
+ value = ``,
8782
+ onChange,
8783
+ searchValue,
8784
+ disabled,
8785
+ extraNav,
8786
+ fixedToolbar = true,
8787
+ floatToolbar = true,
8788
+ onQuote,
8789
+ onDownloadFile,
8790
+ annotationConfig,
8791
+ collectionConfig,
8792
+ pageNoConfig
8793
+ }, ref) => {
8794
+ const isMobile = useIsBreakpoint();
8795
+ const lastContentRef = React.useRef("");
8796
+ const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
8797
+ const {
8798
+ setAnnotationEditor,
8799
+ annotations,
8800
+ setAnnotations,
8801
+ selectedAnnotationId,
8802
+ handleSelectAnnotation,
8803
+ showAnnotationModal,
8804
+ showAnnotation,
8805
+ onCreateAnnotation,
8806
+ closeAnnotationCreateModal,
8807
+ onCreateAnnotationConfirm,
8808
+ handleDeleteAnnotation,
8809
+ handleEditAnnotation,
8810
+ setShowAnnotation
8811
+ } = useAnnotations(annotationConfig);
8812
+ const {
8813
+ setCollectionEditor,
8814
+ collections,
8815
+ setCollections,
8816
+ selectedCollectionId,
8817
+ handleSelectCollection,
8818
+ showCollection,
8819
+ setShowCollection,
8820
+ onCreateCollection,
8821
+ handleDeleteCollection
8822
+ } = useCollections(collectionConfig);
8823
+ const editor = react.useEditor({
8824
+ immediatelyRender: false,
8825
+ editorProps: {
8826
+ attributes: {
8827
+ autocomplete: "off",
8828
+ autocorrect: "off",
8829
+ autocapitalize: "off",
8830
+ "aria-label": "\u4E3B\u5185\u5BB9\u533A\u57DF\uFF0C\u5F00\u59CB\u8F93\u5165\u6587\u672C..."
8653
8831
  }
8654
- }),
8655
- HorizontalRule,
8656
- extensionTextAlign.TextAlign.configure({ types: ["heading", "paragraph"] }),
8657
- extensionList.TaskList,
8658
- extensionList.TaskItem.configure({ nested: true }),
8659
- extensionHighlight.Highlight.configure({ multicolor: true }),
8660
- extensionImage.Image,
8661
- extensionTypography.Typography,
8662
- extensionSuperscript.Superscript,
8663
- extensionSubscript.Subscript,
8664
- extensions.Selection,
8665
- extensionTable.Table.configure({
8666
- resizable: true
8667
- // 可选,允许调整表格大小
8668
- }),
8669
- extensionTable.TableHeader,
8670
- extensionTable.TableRow,
8671
- extensionTable.TableCell,
8672
- // ImageUploadNode.configure({
8673
- // accept: 'image/*',
8674
- // maxSize: MAX_FILE_SIZE,
8675
- // limit: 3,
8676
- // upload: handleImageUpload,
8677
- // onError: (error) => console.error('上传失败:', error)
8678
- // }),
8679
- ...pageNoConfig?.enabled ? [
8680
- pageNoMark_default,
8681
- PageNoExtension.configure({
8682
- onPageChange,
8683
- containerSelector: "#contentWrapper"
8684
- })
8685
- ] : [],
8686
- searchAndReplace_default.configure({
8687
- searchResultClass: "cube-hl",
8688
- // class to give to found items. default 'cube-hl'
8689
- disableRegex: false
8690
- // also no need to explain
8691
- }),
8692
- ...annotationConfig?.enabled ? [
8693
- AnnotationMark,
8694
- AnnotationPlugin.configure({
8695
- onAnnotationsChange: setAnnotations,
8696
- onSelectAnnotation: (annotation) => {
8697
- handleSelectAnnotation(annotation?.[ANNOTATION_ATTRS[0]]);
8832
+ },
8833
+ extensions: [
8834
+ markdown.Markdown,
8835
+ extensionMathematics.Mathematics.configure({
8836
+ // 可选:KaTeX 自定义配置
8837
+ katexOptions: {
8838
+ throwOnError: false
8698
8839
  }
8699
- })
8700
- ] : [],
8701
- // 摘录功能扩展
8702
- ...collectionConfig?.enabled ? [
8703
- CollectionMark,
8704
- CollectionPlugin.configure({
8705
- onCollectionsChange: setCollections,
8706
- onSelectCollection: (collection) => {
8707
- handleSelectCollection(collection?.[COLLECTION_ATTRS[0]]);
8840
+ // 可选:内联公式点击回调
8841
+ // inlineOptions: {
8842
+ // onClick: (node, pos) => {
8843
+ // const newLaTeX = prompt('编辑公式 LaTeX:', node.attrs.latex)
8844
+ // if (newLaTeX) {
8845
+ // editor?.chain().setNodeSelection(pos).updateInlineMath({ latex: newLaTeX }).run()
8846
+ // }
8847
+ // }
8848
+ // }
8849
+ }),
8850
+ starterKit.StarterKit.configure({
8851
+ horizontalRule: false,
8852
+ link: {
8853
+ openOnClick: false,
8854
+ enableClickSelection: true
8708
8855
  }
8709
- })
8710
- ] : []
8711
- ],
8712
- content: value,
8713
- contentType: "markdown",
8714
- onUpdate: () => {
8715
- const markdownOutput = getMarkdown();
8716
- if (markdownOutput === lastContentRef.current) return;
8717
- lastContentRef.current = markdownOutput;
8718
- onChange?.(markdownOutput);
8719
- }
8720
- });
8721
- const getMarkdown = () => {
8722
- if (!editor) return "";
8723
- if (editor.isEmpty) return "";
8724
- return editor.getMarkdown();
8725
- };
8726
- React.useEffect(() => {
8727
- if (!editor) return;
8728
- setAnnotationEditor(editor);
8729
- setCollectionEditor(editor);
8730
- setPageNoEditor(editor);
8731
- }, [editor]);
8732
- React.useEffect(() => {
8733
- if (!editor) return;
8734
- if (lastContentRef.current === value) return;
8735
- editor?.commands.setContent(value, { contentType: "markdown" });
8736
- editor?.commands.focus("start");
8737
- lastContentRef.current = value;
8738
- }, [value, editor]);
8739
- React.useEffect(() => {
8740
- editor?.commands.setSearchTerm(searchValue || "");
8741
- }, [searchValue, value, editor]);
8742
- React.useEffect(() => {
8743
- editor?.setEditable(!disabled);
8744
- }, [disabled, editor]);
8745
- const downloadFile2 = () => {
8746
- onDownloadFile?.(getMarkdown(), "docx");
8747
- };
8748
- const fixedTools = React.useMemo(() => isArray(fixedToolbar) ? fixedToolbar : void 0, [fixedToolbar]);
8749
- const floatTools = React.useMemo(() => isArray(floatToolbar) ? floatToolbar : void 0, [floatToolbar]);
8750
- return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "height-full width-full", children: [
8751
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", "flex-1", styles_module_default4.editorParent), children: /* @__PURE__ */ jsxRuntime.jsxs(react.EditorContext.Provider, { value: { editor }, children: [
8752
- /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8753
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "end", align: "center", children: [
8754
- fixedToolbar !== false && /* @__PURE__ */ jsxRuntime.jsx(
8856
+ }),
8857
+ HorizontalRule,
8858
+ extensionTextAlign.TextAlign.configure({ types: ["heading", "paragraph"] }),
8859
+ extensionList.TaskList,
8860
+ extensionList.TaskItem.configure({ nested: true }),
8861
+ extensionHighlight.Highlight.configure({ multicolor: true }),
8862
+ extensionImage.Image,
8863
+ extensionTypography.Typography,
8864
+ extensionSuperscript.Superscript,
8865
+ extensionSubscript.Subscript,
8866
+ extensions.Selection,
8867
+ extensionTable.Table.configure({
8868
+ resizable: true
8869
+ // 可选,允许调整表格大小
8870
+ }),
8871
+ extensionTable.TableHeader,
8872
+ extensionTable.TableRow,
8873
+ extensionTable.TableCell,
8874
+ // ImageUploadNode.configure({
8875
+ // accept: 'image/*',
8876
+ // maxSize: MAX_FILE_SIZE,
8877
+ // limit: 3,
8878
+ // upload: handleImageUpload,
8879
+ // onError: (error) => console.error('上传失败:', error)
8880
+ // }),
8881
+ ...pageNoConfig?.enabled ? [
8882
+ pageNoMark_default,
8883
+ PageNoExtension.configure({
8884
+ onPageChange,
8885
+ containerSelector: "#contentWrapper"
8886
+ })
8887
+ ] : [],
8888
+ searchAndReplace_default.configure({
8889
+ searchResultClass: "cube-hl",
8890
+ // class to give to found items. default 'cube-hl'
8891
+ disableRegex: false
8892
+ // also no need to explain
8893
+ }),
8894
+ ...annotationConfig?.enabled ? [
8895
+ AnnotationMark,
8896
+ AnnotationPlugin.configure({
8897
+ onAnnotationsChange: setAnnotations,
8898
+ onSelectAnnotation: (annotation) => {
8899
+ handleSelectAnnotation(annotation?.[ANNOTATION_ATTRS[0]]);
8900
+ }
8901
+ })
8902
+ ] : [],
8903
+ // 摘录功能扩展
8904
+ ...collectionConfig?.enabled ? [
8905
+ CollectionMark,
8906
+ CollectionPlugin.configure({
8907
+ onCollectionsChange: setCollections,
8908
+ onSelectCollection: (collection) => {
8909
+ handleSelectCollection(collection?.[COLLECTION_ATTRS[0]]);
8910
+ }
8911
+ })
8912
+ ] : []
8913
+ ],
8914
+ content: value,
8915
+ contentType: "markdown",
8916
+ onUpdate: () => {
8917
+ const markdownOutput = getMarkdown();
8918
+ if (markdownOutput === lastContentRef.current) return;
8919
+ lastContentRef.current = markdownOutput;
8920
+ onChange?.(markdownOutput);
8921
+ }
8922
+ });
8923
+ const getMarkdown = () => {
8924
+ if (!editor) return "";
8925
+ if (editor.isEmpty) return "";
8926
+ return editor.getMarkdown();
8927
+ };
8928
+ React.useImperativeHandle(
8929
+ ref,
8930
+ () => ({
8931
+ getEditor: () => editor,
8932
+ getMarkdown,
8933
+ focus: (pos) => {
8934
+ if (!editor) return;
8935
+ editor.commands.focus(pos);
8936
+ },
8937
+ insertContent: (value2, options) => {
8938
+ if (!editor) return;
8939
+ editor.chain().focus().insertContent(value2, options).run();
8940
+ },
8941
+ insertContentAt: (position, value2, options) => {
8942
+ if (!editor) return;
8943
+ editor.chain().focus().insertContentAt(position, value2, options).run();
8944
+ }
8945
+ }),
8946
+ [editor]
8947
+ );
8948
+ React.useEffect(() => {
8949
+ if (!editor) return;
8950
+ setAnnotationEditor(editor);
8951
+ setCollectionEditor(editor);
8952
+ setPageNoEditor(editor);
8953
+ }, [editor]);
8954
+ React.useEffect(() => {
8955
+ if (!editor) return;
8956
+ if (lastContentRef.current === value) return;
8957
+ editor?.commands.setContent(value, { contentType: "markdown" });
8958
+ editor?.commands.focus("start");
8959
+ lastContentRef.current = value;
8960
+ }, [value, editor]);
8961
+ React.useEffect(() => {
8962
+ editor?.commands.setSearchTerm(searchValue || "");
8963
+ }, [searchValue, value, editor]);
8964
+ React.useEffect(() => {
8965
+ editor?.setEditable(!disabled);
8966
+ }, [disabled, editor]);
8967
+ const downloadFile2 = () => {
8968
+ onDownloadFile?.(getMarkdown(), "docx");
8969
+ };
8970
+ const fixedTools = React.useMemo(() => isArray(fixedToolbar) ? fixedToolbar : void 0, [fixedToolbar]);
8971
+ const floatTools = React.useMemo(() => isArray(floatToolbar) ? floatToolbar : void 0, [floatToolbar]);
8972
+ return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "height-full width-full", children: [
8973
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", "flex-1", styles_module_default4.editorParent), children: /* @__PURE__ */ jsxRuntime.jsxs(react.EditorContext.Provider, { value: { editor }, children: [
8974
+ /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8975
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "end", align: "center", children: [
8976
+ fixedToolbar !== false && /* @__PURE__ */ jsxRuntime.jsx(
8977
+ EditorToolbar,
8978
+ {
8979
+ isBubble: false,
8980
+ onQuote,
8981
+ onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8982
+ onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8983
+ tools: fixedTools
8984
+ }
8985
+ ),
8986
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, align: "center", className: classNames2__default.default(styles_module_default4.extraToolbar), children: [
8987
+ annotationConfig?.enabled && annotationConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8988
+ antd.Button,
8989
+ {
8990
+ size: "small",
8991
+ title: "\u6279\u6CE8\u5217\u8868",
8992
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MessageOutlined, {}),
8993
+ color: "primary",
8994
+ variant: "text",
8995
+ onClick: () => setShowAnnotation(!showAnnotation)
8996
+ }
8997
+ ),
8998
+ collectionConfig?.enabled && collectionConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8999
+ antd.Button,
9000
+ {
9001
+ style: { gap: "2px" },
9002
+ size: "small",
9003
+ title: "\u6458\u5F55\u5217\u8868",
9004
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.BookOutlined, {}),
9005
+ color: "primary",
9006
+ variant: "text",
9007
+ onClick: () => setShowCollection(!showCollection),
9008
+ children: "\u6458\u5F55"
9009
+ }
9010
+ ),
9011
+ onDownloadFile && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { size: "small", color: "primary", variant: "text", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
9012
+ extraNav
9013
+ ] })
9014
+ ] }),
9015
+ !isMobile && floatToolbar !== false && /* @__PURE__ */ jsxRuntime.jsx(FloatingElement, { editor, zIndex: 188, resetTextSelectionOnClose: false, className: styles_module_default4.editorFloatingToolbar, children: /* @__PURE__ */ jsxRuntime.jsx(
8755
9016
  EditorToolbar,
8756
9017
  {
8757
- isBubble: false,
9018
+ isBubble: true,
8758
9019
  onQuote,
8759
9020
  onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8760
9021
  onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8761
- tools: fixedTools
9022
+ tools: floatTools
8762
9023
  }
8763
- ),
8764
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, align: "center", className: classNames2__default.default(styles_module_default4.extraToolbar), children: [
8765
- annotationConfig?.enabled && annotationConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8766
- antd.Button,
8767
- {
8768
- size: "small",
8769
- title: "\u6279\u6CE8\u5217\u8868",
8770
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MessageOutlined, {}),
8771
- color: "primary",
8772
- variant: "text",
8773
- onClick: () => setShowAnnotation(!showAnnotation)
8774
- }
8775
- ),
8776
- collectionConfig?.enabled && collectionConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8777
- antd.Button,
8778
- {
8779
- style: { gap: "2px" },
8780
- size: "small",
8781
- title: "\u6458\u5F55\u5217\u8868",
8782
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.BookOutlined, {}),
8783
- color: "primary",
8784
- variant: "text",
8785
- onClick: () => setShowCollection(!showCollection),
8786
- children: "\u6458\u5F55"
8787
- }
8788
- ),
8789
- onDownloadFile && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { size: "small", color: "primary", variant: "text", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
8790
- extraNav
8791
- ] })
9024
+ ) })
8792
9025
  ] }),
8793
- !isMobile && floatToolbar !== false && /* @__PURE__ */ jsxRuntime.jsx(FloatingElement, { editor, zIndex: 188, resetTextSelectionOnClose: false, className: styles_module_default4.editorFloatingToolbar, children: /* @__PURE__ */ jsxRuntime.jsx(
8794
- EditorToolbar,
9026
+ /* @__PURE__ */ jsxRuntime.jsx("div", { id: "contentWrapper", className: classNames2__default.default(styles_module_default4.contentWrapper, "scroll-fade-in"), children: /* @__PURE__ */ jsxRuntime.jsx(
9027
+ react.EditorContent,
8795
9028
  {
8796
- isBubble: true,
8797
- onQuote,
8798
- onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8799
- onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8800
- tools: floatTools
9029
+ editor,
9030
+ role: "presentation",
9031
+ className: classNames2__default.default(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8801
9032
  }
8802
9033
  ) })
9034
+ ] }) }),
9035
+ annotationConfig?.enabled && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
9036
+ showAnnotation && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
9037
+ AnnotationSidebar_default,
9038
+ {
9039
+ disabled,
9040
+ annotations,
9041
+ selectedAnnotationId,
9042
+ handleSelectAnnotation: (id) => handleSelectAnnotation(id, "sidebar"),
9043
+ onEditAnnotation: handleEditAnnotation,
9044
+ onDeleteAnnotation: handleDeleteAnnotation,
9045
+ annotationConfig,
9046
+ onClose: () => setShowAnnotation(false)
9047
+ }
9048
+ ) }),
9049
+ showAnnotationModal && /* @__PURE__ */ jsxRuntime.jsx(AnnotationModal_default, { visible: showAnnotationModal, onCancel: closeAnnotationCreateModal, onConfirm: onCreateAnnotationConfirm })
8803
9050
  ] }),
8804
- /* @__PURE__ */ jsxRuntime.jsx("div", { id: "contentWrapper", className: classNames2__default.default(styles_module_default4.contentWrapper, "scroll-fade-in"), children: /* @__PURE__ */ jsxRuntime.jsx(
8805
- react.EditorContent,
8806
- {
8807
- editor,
8808
- role: "presentation",
8809
- className: classNames2__default.default(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8810
- }
8811
- ) })
8812
- ] }) }),
8813
- annotationConfig?.enabled && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8814
- showAnnotation && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
8815
- AnnotationSidebar_default,
9051
+ collectionConfig?.enabled && showCollection && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
9052
+ collectionSidebar_default,
8816
9053
  {
8817
9054
  disabled,
8818
- annotations,
8819
- selectedAnnotationId,
8820
- handleSelectAnnotation: (id) => handleSelectAnnotation(id, "sidebar"),
8821
- onEditAnnotation: handleEditAnnotation,
8822
- onDeleteAnnotation: handleDeleteAnnotation,
8823
- annotationConfig,
8824
- onClose: () => setShowAnnotation(false)
9055
+ collections,
9056
+ selectedCollectionId,
9057
+ handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
9058
+ onDeleteCollection: handleDeleteCollection,
9059
+ collectionConfig,
9060
+ onClose: () => setShowCollection(false)
8825
9061
  }
8826
- ) }),
8827
- showAnnotationModal && /* @__PURE__ */ jsxRuntime.jsx(AnnotationModal_default, { visible: showAnnotationModal, onCancel: closeAnnotationCreateModal, onConfirm: onCreateAnnotationConfirm })
8828
- ] }),
8829
- collectionConfig?.enabled && showCollection && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
8830
- collectionSidebar_default,
8831
- {
8832
- disabled,
8833
- collections,
8834
- selectedCollectionId,
8835
- handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
8836
- onDeleteCollection: handleDeleteCollection,
8837
- collectionConfig,
8838
- onClose: () => setShowCollection(false)
8839
- }
8840
- ) })
8841
- ] });
8842
- };
9062
+ ) })
9063
+ ] });
9064
+ }
9065
+ );
8843
9066
 
8844
9067
  // src/components/MarkDrawing/styles.module.less
8845
9068
  var styles_module_default7 = {
@@ -8958,6 +9181,9 @@ exports.LazyComponent = LazyComponent_default;
8958
9181
  exports.MarkDrawing = MarkDrawing_default;
8959
9182
  exports.MarkdownEditor = MarkdownEditor_default;
8960
9183
  exports.MarkdownPreview = MarkdownPreview_default;
9184
+ exports.MicroApp = MicroApp_default;
9185
+ exports.MicroAppDrawer = Drawer_default;
9186
+ exports.MicroAppWindow = Window_default;
8961
9187
  exports.MultiEmailValidator = MultiEmailValidator;
8962
9188
  exports.PdfImagePreview = PdfImagePreview_default;
8963
9189
  exports.PdfPreview = PdfPreview_default;