@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.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));
1615
1642
  }
1616
- return { on, off };
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
+ }
1649
+ }
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"
@@ -3284,7 +3450,7 @@ var AnnotationSidebar_default = ({
3284
3450
  }
3285
3451
  return reactDom.createPortal(sidebarContent, container);
3286
3452
  };
3287
- var createHtmlMark = (markName, ATTRS, classNames7) => {
3453
+ var createHtmlMark = (markName, ATTRS, classNames8) => {
3288
3454
  return core.Mark.create({
3289
3455
  name: markName,
3290
3456
  priority: 1e3,
@@ -3313,7 +3479,7 @@ var createHtmlMark = (markName, ATTRS, classNames7) => {
3313
3479
  return [
3314
3480
  "div",
3315
3481
  core.mergeAttributes(attrs, {
3316
- class: classNames7
3482
+ class: classNames8
3317
3483
  }),
3318
3484
  0
3319
3485
  ];
@@ -8610,271 +8776,293 @@ var usePageNo = (pageNoConfig) => {
8610
8776
  onPageChange
8611
8777
  };
8612
8778
  };
8613
- var MarkdownEditor_default = ({
8614
- value = ``,
8615
- onChange,
8616
- searchValue,
8617
- disabled,
8618
- extraNav,
8619
- fixedToolbar = true,
8620
- floatToolbar = true,
8621
- onQuote,
8622
- onDownloadFile,
8623
- annotationConfig,
8624
- collectionConfig,
8625
- pageNoConfig
8626
- }) => {
8627
- const isMobile = useIsBreakpoint();
8628
- const lastContentRef = React.useRef("");
8629
- const { setPageNoEditor, onPageChange } = usePageNo(pageNoConfig);
8630
- const {
8631
- setAnnotationEditor,
8632
- annotations,
8633
- setAnnotations,
8634
- selectedAnnotationId,
8635
- handleSelectAnnotation,
8636
- showAnnotationModal,
8637
- showAnnotation,
8638
- onCreateAnnotation,
8639
- closeAnnotationCreateModal,
8640
- onCreateAnnotationConfirm,
8641
- handleDeleteAnnotation,
8642
- handleEditAnnotation,
8643
- setShowAnnotation
8644
- } = useAnnotations(annotationConfig);
8645
- const {
8646
- setCollectionEditor,
8647
- collections,
8648
- setCollections,
8649
- selectedCollectionId,
8650
- handleSelectCollection,
8651
- showCollection,
8652
- setShowCollection,
8653
- onCreateCollection,
8654
- handleDeleteCollection
8655
- } = useCollections(collectionConfig);
8656
- const editor = react.useEditor({
8657
- immediatelyRender: false,
8658
- editorProps: {
8659
- attributes: {
8660
- autocomplete: "off",
8661
- autocorrect: "off",
8662
- autocapitalize: "off",
8663
- "aria-label": "\u4E3B\u5185\u5BB9\u533A\u57DF\uFF0C\u5F00\u59CB\u8F93\u5165\u6587\u672C..."
8664
- }
8665
- },
8666
- extensions: [
8667
- markdown.Markdown,
8668
- extensionMathematics.Mathematics.configure({
8669
- // 可选:KaTeX 自定义配置
8670
- katexOptions: {
8671
- throwOnError: false
8672
- }
8673
- // 可选:内联公式点击回调
8674
- // inlineOptions: {
8675
- // onClick: (node, pos) => {
8676
- // const newLaTeX = prompt('编辑公式 LaTeX:', node.attrs.latex)
8677
- // if (newLaTeX) {
8678
- // editor?.chain().setNodeSelection(pos).updateInlineMath({ latex: newLaTeX }).run()
8679
- // }
8680
- // }
8681
- // }
8682
- }),
8683
- starterKit.StarterKit.configure({
8684
- horizontalRule: false,
8685
- link: {
8686
- openOnClick: false,
8687
- 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..."
8688
8831
  }
8689
- }),
8690
- HorizontalRule,
8691
- extensionTextAlign.TextAlign.configure({ types: ["heading", "paragraph"] }),
8692
- extensionList.TaskList,
8693
- extensionList.TaskItem.configure({ nested: true }),
8694
- extensionHighlight.Highlight.configure({ multicolor: true }),
8695
- extensionImage.Image,
8696
- extensionTypography.Typography,
8697
- extensionSuperscript.Superscript,
8698
- extensionSubscript.Subscript,
8699
- extensions.Selection,
8700
- extensionTable.Table.configure({
8701
- resizable: true
8702
- // 可选,允许调整表格大小
8703
- }),
8704
- extensionTable.TableHeader,
8705
- extensionTable.TableRow,
8706
- extensionTable.TableCell,
8707
- // ImageUploadNode.configure({
8708
- // accept: 'image/*',
8709
- // maxSize: MAX_FILE_SIZE,
8710
- // limit: 3,
8711
- // upload: handleImageUpload,
8712
- // onError: (error) => console.error('上传失败:', error)
8713
- // }),
8714
- ...pageNoConfig?.enabled ? [
8715
- pageNoMark_default,
8716
- PageNoExtension.configure({
8717
- onPageChange,
8718
- containerSelector: "#contentWrapper"
8719
- })
8720
- ] : [],
8721
- searchAndReplace_default.configure({
8722
- searchResultClass: "cube-hl",
8723
- // class to give to found items. default 'cube-hl'
8724
- disableRegex: false
8725
- // also no need to explain
8726
- }),
8727
- ...annotationConfig?.enabled ? [
8728
- AnnotationMark,
8729
- AnnotationPlugin.configure({
8730
- onAnnotationsChange: setAnnotations,
8731
- onSelectAnnotation: (annotation) => {
8732
- handleSelectAnnotation(annotation?.[ANNOTATION_ATTRS[0]]);
8832
+ },
8833
+ extensions: [
8834
+ markdown.Markdown,
8835
+ extensionMathematics.Mathematics.configure({
8836
+ // 可选:KaTeX 自定义配置
8837
+ katexOptions: {
8838
+ throwOnError: false
8733
8839
  }
8734
- })
8735
- ] : [],
8736
- // 摘录功能扩展
8737
- ...collectionConfig?.enabled ? [
8738
- CollectionMark,
8739
- CollectionPlugin.configure({
8740
- onCollectionsChange: setCollections,
8741
- onSelectCollection: (collection) => {
8742
- 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
8743
8855
  }
8744
- })
8745
- ] : []
8746
- ],
8747
- content: value,
8748
- contentType: "markdown",
8749
- onUpdate: () => {
8750
- const markdownOutput = getMarkdown();
8751
- if (markdownOutput === lastContentRef.current) return;
8752
- lastContentRef.current = markdownOutput;
8753
- onChange?.(markdownOutput);
8754
- }
8755
- });
8756
- const getMarkdown = () => {
8757
- if (!editor) return "";
8758
- if (editor.isEmpty) return "";
8759
- return editor.getMarkdown();
8760
- };
8761
- React.useEffect(() => {
8762
- if (!editor) return;
8763
- setAnnotationEditor(editor);
8764
- setCollectionEditor(editor);
8765
- setPageNoEditor(editor);
8766
- }, [editor]);
8767
- React.useEffect(() => {
8768
- if (!editor) return;
8769
- if (lastContentRef.current === value) return;
8770
- editor?.commands.setContent(value, { contentType: "markdown" });
8771
- editor?.commands.focus("start");
8772
- lastContentRef.current = value;
8773
- }, [value, editor]);
8774
- React.useEffect(() => {
8775
- editor?.commands.setSearchTerm(searchValue || "");
8776
- }, [searchValue, value, editor]);
8777
- React.useEffect(() => {
8778
- editor?.setEditable(!disabled);
8779
- }, [disabled, editor]);
8780
- const downloadFile2 = () => {
8781
- onDownloadFile?.(getMarkdown(), "docx");
8782
- };
8783
- const fixedTools = React.useMemo(() => isArray(fixedToolbar) ? fixedToolbar : void 0, [fixedToolbar]);
8784
- const floatTools = React.useMemo(() => isArray(floatToolbar) ? floatToolbar : void 0, [floatToolbar]);
8785
- return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "height-full width-full", children: [
8786
- /* @__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: [
8787
- /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8788
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "end", align: "center", children: [
8789
- 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(
8790
9016
  EditorToolbar,
8791
9017
  {
8792
- isBubble: false,
9018
+ isBubble: true,
8793
9019
  onQuote,
8794
9020
  onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8795
9021
  onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8796
- tools: fixedTools
9022
+ tools: floatTools
8797
9023
  }
8798
- ),
8799
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, align: "center", className: classNames2__default.default(styles_module_default4.extraToolbar), children: [
8800
- annotationConfig?.enabled && annotationConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8801
- antd.Button,
8802
- {
8803
- size: "small",
8804
- title: "\u6279\u6CE8\u5217\u8868",
8805
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MessageOutlined, {}),
8806
- color: "primary",
8807
- variant: "text",
8808
- onClick: () => setShowAnnotation(!showAnnotation)
8809
- }
8810
- ),
8811
- collectionConfig?.enabled && collectionConfig?.showListButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
8812
- antd.Button,
8813
- {
8814
- style: { gap: "2px" },
8815
- size: "small",
8816
- title: "\u6458\u5F55\u5217\u8868",
8817
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.BookOutlined, {}),
8818
- color: "primary",
8819
- variant: "text",
8820
- onClick: () => setShowCollection(!showCollection),
8821
- children: "\u6458\u5F55"
8822
- }
8823
- ),
8824
- onDownloadFile && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { size: "small", color: "primary", variant: "text", onClick: downloadFile2, children: "\u4E0B\u8F7D" }),
8825
- extraNav
8826
- ] })
9024
+ ) })
8827
9025
  ] }),
8828
- !isMobile && floatToolbar !== false && /* @__PURE__ */ jsxRuntime.jsx(FloatingElement, { editor, zIndex: 188, resetTextSelectionOnClose: false, className: styles_module_default4.editorFloatingToolbar, children: /* @__PURE__ */ jsxRuntime.jsx(
8829
- 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,
8830
9028
  {
8831
- isBubble: true,
8832
- onQuote,
8833
- onCreateAnnotation: annotationConfig?.enabled ? onCreateAnnotation : void 0,
8834
- onCreateCollection: collectionConfig?.enabled ? onCreateCollection : void 0,
8835
- tools: floatTools
9029
+ editor,
9030
+ role: "presentation",
9031
+ className: classNames2__default.default(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8836
9032
  }
8837
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 })
8838
9050
  ] }),
8839
- /* @__PURE__ */ jsxRuntime.jsx("div", { id: "contentWrapper", className: classNames2__default.default(styles_module_default4.contentWrapper, "scroll-fade-in"), children: /* @__PURE__ */ jsxRuntime.jsx(
8840
- react.EditorContent,
8841
- {
8842
- editor,
8843
- role: "presentation",
8844
- className: classNames2__default.default(styles_module_default4.simpleEditorContent, "ns-markdown", { [styles_module_default4.noToolbar]: fixedToolbar === false })
8845
- }
8846
- ) })
8847
- ] }) }),
8848
- annotationConfig?.enabled && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8849
- showAnnotation && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
8850
- 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,
8851
9053
  {
8852
9054
  disabled,
8853
- annotations,
8854
- selectedAnnotationId,
8855
- handleSelectAnnotation: (id) => handleSelectAnnotation(id, "sidebar"),
8856
- onEditAnnotation: handleEditAnnotation,
8857
- onDeleteAnnotation: handleDeleteAnnotation,
8858
- annotationConfig,
8859
- onClose: () => setShowAnnotation(false)
9055
+ collections,
9056
+ selectedCollectionId,
9057
+ handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
9058
+ onDeleteCollection: handleDeleteCollection,
9059
+ collectionConfig,
9060
+ onClose: () => setShowCollection(false)
8860
9061
  }
8861
- ) }),
8862
- showAnnotationModal && /* @__PURE__ */ jsxRuntime.jsx(AnnotationModal_default, { visible: showAnnotationModal, onCancel: closeAnnotationCreateModal, onConfirm: onCreateAnnotationConfirm })
8863
- ] }),
8864
- collectionConfig?.enabled && showCollection && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames2__default.default("height-full", styles_module_default4.extraSidebarParent), children: /* @__PURE__ */ jsxRuntime.jsx(
8865
- collectionSidebar_default,
8866
- {
8867
- disabled,
8868
- collections,
8869
- selectedCollectionId,
8870
- handleSelectCollection: (id) => handleSelectCollection(id, "sidebar"),
8871
- onDeleteCollection: handleDeleteCollection,
8872
- collectionConfig,
8873
- onClose: () => setShowCollection(false)
8874
- }
8875
- ) })
8876
- ] });
8877
- };
9062
+ ) })
9063
+ ] });
9064
+ }
9065
+ );
8878
9066
 
8879
9067
  // src/components/MarkDrawing/styles.module.less
8880
9068
  var styles_module_default7 = {
@@ -8993,6 +9181,9 @@ exports.LazyComponent = LazyComponent_default;
8993
9181
  exports.MarkDrawing = MarkDrawing_default;
8994
9182
  exports.MarkdownEditor = MarkdownEditor_default;
8995
9183
  exports.MarkdownPreview = MarkdownPreview_default;
9184
+ exports.MicroApp = MicroApp_default;
9185
+ exports.MicroAppDrawer = Drawer_default;
9186
+ exports.MicroAppWindow = Window_default;
8996
9187
  exports.MultiEmailValidator = MultiEmailValidator;
8997
9188
  exports.PdfImagePreview = PdfImagePreview_default;
8998
9189
  exports.PdfPreview = PdfPreview_default;