rme 0.2.5-alpha.21 → 0.2.5-alpha.23

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.mjs CHANGED
@@ -1829,13 +1829,13 @@ function computeChange(oldVal, newVal) {
1829
1829
 
1830
1830
  // src/editor/components/Editor.tsx
1831
1831
  import { prosemirrorNodeToHtml } from "@rme-sdk/main";
1832
- import { forwardRef as forwardRef2, memo as memo9, useImperativeHandle as useImperativeHandle2, useMemo as useMemo6, useState as useState8 } from "react";
1832
+ import { forwardRef as forwardRef2, memo as memo9, useImperativeHandle as useImperativeHandle2, useMemo as useMemo6, useState as useState9 } from "react";
1833
1833
 
1834
1834
  // src/editor/components/SourceEditor/index.tsx
1835
1835
  import { ProsemirrorDevTools } from "@rme-sdk/dev";
1836
1836
  import { Remirror } from "@rme-sdk/react";
1837
1837
  import { createContextState } from "create-context-state";
1838
- import { memo as memo5, useCallback as useCallback4, useMemo as useMemo2 } from "react";
1838
+ import { memo as memo6, useCallback as useCallback4, useMemo as useMemo2 } from "react";
1839
1839
 
1840
1840
  // src/editor/components/ErrorBoundary.tsx
1841
1841
  import React from "react";
@@ -2648,90 +2648,6 @@ function createElement(tagName, attributes, ...children) {
2648
2648
  }
2649
2649
  return element;
2650
2650
  }
2651
- function deepCloneElement(element, important = false) {
2652
- const clonedElement = element.cloneNode(true);
2653
- const style = deepCopyStyles(element, clonedElement, important);
2654
- return [clonedElement, style];
2655
- }
2656
- function deepCopyStyles(source, target, important) {
2657
- const sources = [source];
2658
- const targets = [target];
2659
- const styles = [];
2660
- while (sources.length > 0 && sources.length === targets.length) {
2661
- const source2 = sources.shift();
2662
- const target2 = targets.shift();
2663
- if (!source2 || !target2) {
2664
- break;
2665
- }
2666
- const style = copyStyles(source2, target2, important);
2667
- if (style) {
2668
- styles.push(style);
2669
- }
2670
- sources.push(...Array.from(source2.children));
2671
- targets.push(...Array.from(target2.children));
2672
- }
2673
- return styles.join("\n");
2674
- }
2675
- function copyStyles(source, target, important) {
2676
- if (!source || !target) {
2677
- return "";
2678
- }
2679
- const view = source.ownerDocument?.defaultView;
2680
- if (!view) {
2681
- return "";
2682
- }
2683
- const sourceStyle = view.getComputedStyle(source);
2684
- const targetStyle = target.style;
2685
- if (!sourceStyle || !targetStyle) {
2686
- return "";
2687
- }
2688
- for (const key2 of sourceStyle) {
2689
- targetStyle.setProperty(
2690
- key2,
2691
- sourceStyle.getPropertyValue(key2),
2692
- // Enforce important to avoid the style being overridden when the element
2693
- // is connected to the page.
2694
- // See https://github.com/prosekit/prosekit/issues/1185 for more details.
2695
- important ? "important" : sourceStyle.getPropertyPriority(key2) || ""
2696
- );
2697
- }
2698
- const styles = [];
2699
- for (const pseudoSelector of [":before", ":after"]) {
2700
- const sourcePseudoStyle = view.getComputedStyle(source, pseudoSelector);
2701
- const targetPseudoStyle = view.getComputedStyle(target, pseudoSelector);
2702
- if (!sourcePseudoStyle) {
2703
- continue;
2704
- }
2705
- const content = sourcePseudoStyle.getPropertyValue("content");
2706
- const hasPseudoElement = content && content !== "none" && content !== "normal";
2707
- if (!hasPseudoElement) {
2708
- continue;
2709
- }
2710
- const cssProps = [];
2711
- for (const property of sourcePseudoStyle) {
2712
- const sourceValue = sourcePseudoStyle.getPropertyValue(property);
2713
- const sourcePriority = sourcePseudoStyle.getPropertyPriority(property);
2714
- const targetValue = targetPseudoStyle.getPropertyValue(property);
2715
- const targetPriority = targetPseudoStyle.getPropertyPriority(property);
2716
- if (sourceValue !== targetValue || sourcePriority !== targetPriority) {
2717
- cssProps.push(`${property}: ${sourceValue}${sourcePriority ? " !important" : ""};`);
2718
- }
2719
- }
2720
- const uniqueClassName = `clone-pseudo-element-${getId()}`;
2721
- target.classList.add(uniqueClassName);
2722
- styles.push(`.${uniqueClassName}${pseudoSelector} { ${cssProps.join(" ")} }`);
2723
- }
2724
- return styles.join("\n");
2725
- }
2726
- function injectStyle(container, styleText) {
2727
- if (!styleText) {
2728
- return;
2729
- }
2730
- const document2 = getDocument(container);
2731
- const style = document2.createElement("style");
2732
- style.textContent = styleText;
2733
- container.appendChild(style);
2734
- }
2735
2651
 
2736
2652
  // src/editor/extensions/Table/table-utils.ts
2737
2653
  import { findParentNodeOfType as findParentNodeOfType2 } from "@rme-sdk/core";
@@ -9574,13 +9490,197 @@ MermaidBlockExtension = __decorateClass([
9574
9490
  ], MermaidBlockExtension);
9575
9491
 
9576
9492
  // src/editor/extensions/NodeIndicator/node-indicator-extension.tsx
9577
- import { isHTMLElement as isHTMLElement3 } from "@ocavue/utils";
9493
+ import { isHTMLElement as isHTMLElement5 } from "@ocavue/utils";
9578
9494
  import { PlainExtension as PlainExtension7 } from "@rme-sdk/core";
9579
- import { NodeSelection as NodeSelection2, TextSelection as TextSelection11 } from "@rme-sdk/pm/state";
9495
+ import { NodeSelection as NodeSelection4, TextSelection as TextSelection11 } from "@rme-sdk/pm/state";
9580
9496
 
9581
- // src/editor/extensions/NodeIndicator/drop-target.ts
9497
+ // src/editor/toolbar/BlockHandler/index.tsx
9498
+ import { isHTMLElement as isHTMLElement2 } from "@ocavue/utils";
9499
+ import { NodeSelection as NodeSelection2 } from "@rme-sdk/pm/state";
9500
+ import { useExtension, useRemirrorContext as useRemirrorContext2 } from "@rme-sdk/react-core";
9501
+ import { memo as memo5, useEffect as useEffect5, useState as useState6 } from "react";
9502
+ import styled10 from "styled-components";
9503
+
9504
+ // src/editor/extensions/NodeIndicator/drag-preview.ts
9582
9505
  import { isHTMLElement } from "@ocavue/utils";
9506
+ import { Fragment as Fragment6, Slice as Slice3 } from "@rme-sdk/pm";
9583
9507
  import { NodeSelection } from "@rme-sdk/pm/state";
9508
+
9509
+ // src/editor/utils/get-client-rect.ts
9510
+ function getClientRect(element) {
9511
+ const rect = element.getBoundingClientRect();
9512
+ if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
9513
+ if (element.getClientRects().length === 0) {
9514
+ const children = Array.from(element.children);
9515
+ const rects = children.map((child) => getClientRect(child));
9516
+ if (rects.length === 0) {
9517
+ return rect;
9518
+ }
9519
+ if (rects.length === 1) {
9520
+ return rects[0];
9521
+ }
9522
+ let { top, bottom, left, right } = rects[0];
9523
+ for (let i = 1; i < rects.length; i++) {
9524
+ const r = rects[i];
9525
+ if (r.top < top) top = r.top;
9526
+ if (r.bottom > bottom) bottom = r.bottom;
9527
+ if (r.left < left) left = r.left;
9528
+ if (r.right > right) right = r.right;
9529
+ }
9530
+ return { top, bottom, left, right };
9531
+ }
9532
+ }
9533
+ return rect;
9534
+ }
9535
+
9536
+ // src/editor/extensions/NodeIndicator/drag-preview.ts
9537
+ function setViewDragging(view, hoverState) {
9538
+ const { node, pos } = hoverState;
9539
+ const dragging = {
9540
+ slice: new Slice3(Fragment6.from(node), 0, 0),
9541
+ move: true,
9542
+ node: NodeSelection.create(view.state.doc, pos)
9543
+ };
9544
+ view.dragging = dragging;
9545
+ }
9546
+
9547
+ // src/editor/toolbar/BlockHandler/index.tsx
9548
+ import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
9549
+ var nodeTypeIconMap = {
9550
+ "heading-1": "ri-h-1",
9551
+ "heading-2": "ri-h-2",
9552
+ "heading-3": "ri-h-3",
9553
+ "heading-4": "ri-h-4",
9554
+ "heading-5": "ri-h-5",
9555
+ "heading-6": "ri-h-6",
9556
+ paragraph: "ri-paragraph",
9557
+ "list-bullet": "ri-list-unordered",
9558
+ "list-ordered": "ri-list-ordered",
9559
+ "list-task": "ri-list-check-3",
9560
+ codeMirror: "ri-code-box-line",
9561
+ table: "ri-table-line",
9562
+ html_block: "ri-html5-line",
9563
+ math_block: "ri-formula"
9564
+ };
9565
+ var watchers = {};
9566
+ var draggingRef = { current: false };
9567
+ var addDraggingRefWatcher = (key2, watcher) => {
9568
+ watchers[key2] = watcher;
9569
+ };
9570
+ var setDraggingRef = (value) => {
9571
+ draggingRef.current = value;
9572
+ Object.values(watchers).forEach((watcher) => watcher(value));
9573
+ };
9574
+ var BlockHandler = memo5(() => {
9575
+ const { view: editorView } = useRemirrorContext2({ autoUpdate: true });
9576
+ const [isDragging, setIsDragging] = useState6(false);
9577
+ const nodeIndicatorExtension = useExtension(NodeIndicatorExtension);
9578
+ const state = nodeIndicatorExtension.getPluginState();
9579
+ useEffect5(() => {
9580
+ addDraggingRefWatcher("blockHandler", setIsDragging);
9581
+ return () => {
9582
+ delete watchers["blockHandler"];
9583
+ };
9584
+ }, []);
9585
+ const handleClick = () => {
9586
+ if (editorView && nodeIndicatorExtension) {
9587
+ const state2 = nodeIndicatorExtension.getPluginState();
9588
+ if (state2 && state2.pos !== null && state2.node) {
9589
+ const tr = editorView.state.tr;
9590
+ tr.setSelection(NodeSelection2.create(tr.doc, state2.pos));
9591
+ editorView.dispatch(tr);
9592
+ }
9593
+ }
9594
+ };
9595
+ const handleDragStart = (event2) => {
9596
+ console.log("handleDragStart - Tauri\u62D6\u62FD\u5F00\u59CB");
9597
+ setDraggingRef(true);
9598
+ if (editorView && nodeIndicatorExtension) {
9599
+ const state2 = nodeIndicatorExtension.getPluginState();
9600
+ if (state2 && state2.pos !== null && state2.node && state2.node.isBlock) {
9601
+ let tr = editorView.state.tr;
9602
+ tr = tr.setSelection(NodeSelection2.create(tr.doc, state2.pos));
9603
+ editorView.dispatch(tr);
9604
+ const dom = editorView.nodeDOM(state2.pos);
9605
+ if (dom && isHTMLElement2(dom)) {
9606
+ if (event2.dataTransfer) {
9607
+ event2.dataTransfer.effectAllowed = "move";
9608
+ }
9609
+ setViewDragging(editorView, state2);
9610
+ }
9611
+ }
9612
+ }
9613
+ };
9614
+ const handleDragEnd = (e) => {
9615
+ console.log("handleDragEnd", e);
9616
+ };
9617
+ if (!editorView || !state?.node) {
9618
+ return null;
9619
+ }
9620
+ const renderIcon = () => {
9621
+ let key2 = state?.node?.type?.name || "";
9622
+ if (state?.node?.type?.name === "heading") {
9623
+ key2 = `heading-${state?.node?.attrs?.level}`;
9624
+ }
9625
+ if (state?.node?.type?.name === "list") {
9626
+ key2 = `list-${state?.node?.attrs?.kind}`;
9627
+ }
9628
+ const iconName = nodeTypeIconMap[key2 || ""];
9629
+ if (iconName) {
9630
+ return /* @__PURE__ */ jsx16("i", { className: iconName });
9631
+ }
9632
+ return null;
9633
+ };
9634
+ return /* @__PURE__ */ jsxs7(
9635
+ Container3,
9636
+ {
9637
+ className: "rme-block-handler",
9638
+ draggable: "true",
9639
+ onClick: handleClick,
9640
+ onDragStart: handleDragStart,
9641
+ onDragEnd: handleDragEnd,
9642
+ "data-dragging": isDragging,
9643
+ style: {
9644
+ position: "fixed",
9645
+ left: `${state?.rect?.left ? state.rect.left - 38 : 0}px`,
9646
+ top: `${state?.rect?.top || 0}px`
9647
+ },
9648
+ children: [
9649
+ renderIcon(),
9650
+ /* @__PURE__ */ jsx16("div", { className: "rme-draggable-handler", children: /* @__PURE__ */ jsx16("i", { className: "ri-draggable" }) })
9651
+ ]
9652
+ },
9653
+ "rme-block-handler"
9654
+ );
9655
+ });
9656
+ var Container3 = styled10.div`
9657
+ display: flex;
9658
+ align-items: center;
9659
+ justify-content: center;
9660
+ padding: 0 2px;
9661
+ border: 1px solid ${(props) => props.theme.borderColor};
9662
+ border-radius: 4px;
9663
+ font-size: 14px;
9664
+ z-index: 1000;
9665
+
9666
+ .rme-draggable-handler {
9667
+ display: flex;
9668
+ align-items: center;
9669
+ justify-content: center;
9670
+ height: 18px;
9671
+ width: 18px;
9672
+ border-radius: 4px;
9673
+ cursor: grab;
9674
+
9675
+ &:hover {
9676
+ background-color: ${(props) => props.theme.hoverColor};
9677
+ }
9678
+ }
9679
+ `;
9680
+
9681
+ // src/editor/extensions/NodeIndicator/drop-target.ts
9682
+ import { isHTMLElement as isHTMLElement3 } from "@ocavue/utils";
9683
+ import { NodeSelection as NodeSelection3 } from "@rme-sdk/pm/state";
9584
9684
  function getTargetsByView(view) {
9585
9685
  let stack = [[-1, view.state.doc]];
9586
9686
  let targets = [];
@@ -9588,7 +9688,7 @@ function getTargetsByView(view) {
9588
9688
  const [pos, node] = stack.pop();
9589
9689
  if (pos >= 0) {
9590
9690
  let dom = view.nodeDOM(pos);
9591
- if (dom && isHTMLElement(dom)) {
9691
+ if (dom && isHTMLElement3(dom)) {
9592
9692
  let rect = dom.getBoundingClientRect();
9593
9693
  let { top, bottom, left: x1, right: x2 } = rect;
9594
9694
  targets.push(
@@ -9672,7 +9772,7 @@ function isDraggingToItself(view, pos) {
9672
9772
  const { move } = dragging;
9673
9773
  if (!move) return;
9674
9774
  const selection = view.state.selection;
9675
- if (!(selection instanceof NodeSelection)) return;
9775
+ if (!(selection instanceof NodeSelection3)) return;
9676
9776
  const { from, to } = selection;
9677
9777
  return from <= pos && pos <= to;
9678
9778
  }
@@ -9686,35 +9786,6 @@ import {
9686
9786
  isElement,
9687
9787
  isTextNode
9688
9788
  } from "@ocavue/utils";
9689
-
9690
- // src/editor/utils/get-client-rect.ts
9691
- function getClientRect(element) {
9692
- const rect = element.getBoundingClientRect();
9693
- if (rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0) {
9694
- if (element.getClientRects().length === 0) {
9695
- const children = Array.from(element.children);
9696
- const rects = children.map((child) => getClientRect(child));
9697
- if (rects.length === 0) {
9698
- return rect;
9699
- }
9700
- if (rects.length === 1) {
9701
- return rects[0];
9702
- }
9703
- let { top, bottom, left, right } = rects[0];
9704
- for (let i = 1; i < rects.length; i++) {
9705
- const r = rects[i];
9706
- if (r.top < top) top = r.top;
9707
- if (r.bottom > bottom) bottom = r.bottom;
9708
- if (r.left < left) left = r.left;
9709
- if (r.right > right) right = r.right;
9710
- }
9711
- return { top, bottom, left, right };
9712
- }
9713
- }
9714
- return rect;
9715
- }
9716
-
9717
- // src/editor/extensions/NodeIndicator/node-target.ts
9718
9789
  function findBlockByCoords(view, x, y) {
9719
9790
  const rect = getClientRect(view.dom);
9720
9791
  if (!isWithinRect(rect, x, y)) {
@@ -9847,7 +9918,6 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9847
9918
  const initialState = {
9848
9919
  node: null,
9849
9920
  pos: null,
9850
- isDragging: false,
9851
9921
  rect: null
9852
9922
  };
9853
9923
  return {
@@ -9861,10 +9931,7 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9861
9931
  return { ...value, ...meta };
9862
9932
  }
9863
9933
  if (tr.docChanged) {
9864
- if (!value.isDragging) {
9865
- return { node: null, pos: null, isDragging: false };
9866
- }
9867
- return { ...value, isDragging: false };
9934
+ return { ...value };
9868
9935
  }
9869
9936
  return value;
9870
9937
  }
@@ -9875,15 +9942,17 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9875
9942
  },
9876
9943
  props: {
9877
9944
  handleDrop: (view, event2, slice, move) => {
9878
- console.log("handleDrop - \u5F00\u59CB\u5904\u7406\u653E\u7F6E\u64CD\u4F5C", { move, hasSlice: !!slice, eventType: event2.type });
9945
+ console.log("handleDrop - \u5F00\u59CB\u5904\u7406\u653E\u7F6E\u64CD\u4F5C", {
9946
+ move,
9947
+ hasSlice: !!slice,
9948
+ eventType: event2.type
9949
+ });
9879
9950
  if (!getTarget) {
9880
9951
  console.log("handleDrop - getTarget\u672A\u5B9A\u4E49");
9881
9952
  return false;
9882
9953
  }
9883
9954
  const target = getTarget([event2.clientX, event2.clientY], event2);
9884
- console.log("handleDrop - \u8BA1\u7B97\u7684\u653E\u7F6E\u76EE\u6807:", target);
9885
9955
  if (!target) {
9886
- console.log("handleDrop - \u672A\u627E\u5230\u6709\u6548\u653E\u7F6E\u76EE\u6807");
9887
9956
  return false;
9888
9957
  }
9889
9958
  event2.preventDefault();
@@ -9906,8 +9975,8 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9906
9975
  return true;
9907
9976
  }
9908
9977
  let $pos = tr.doc.resolve(pos);
9909
- if (isNode && NodeSelection2.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) {
9910
- tr.setSelection(new NodeSelection2($pos));
9978
+ if (isNode && NodeSelection4.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) {
9979
+ tr.setSelection(new NodeSelection4($pos));
9911
9980
  } else {
9912
9981
  let end = tr.mapping.map(insertPos);
9913
9982
  tr.mapping.maps[tr.mapping.maps.length - 1].forEach(
@@ -9917,6 +9986,7 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9917
9986
  }
9918
9987
  view.focus();
9919
9988
  view.dispatch(tr.setMeta("uiEvent", "drop"));
9989
+ setDraggingRef(false);
9920
9990
  return true;
9921
9991
  },
9922
9992
  handleDOMEvents: {
@@ -9924,17 +9994,13 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
9924
9994
  const { x, y } = event2;
9925
9995
  const block = findBlockByCoords(view, x, y);
9926
9996
  if (!block) {
9927
- view.dispatch(
9928
- view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
9929
- );
9997
+ view.dispatch(view.state.tr.setMeta(pluginKey, { node: null, pos: null }));
9930
9998
  return;
9931
9999
  }
9932
10000
  const { node, pos } = block;
9933
10001
  const element = view.nodeDOM(pos);
9934
- if (!element || !isHTMLElement3(element)) {
9935
- view.dispatch(
9936
- view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
9937
- );
10002
+ if (!element || !isHTMLElement5(element)) {
10003
+ view.dispatch(view.state.tr.setMeta(pluginKey, { node: null, pos: null }));
9938
10004
  return;
9939
10005
  }
9940
10006
  const $pos = view.state.doc.resolve(pos);
@@ -10921,7 +10987,7 @@ var createSourceCodeDelegate = (options) => {
10921
10987
  };
10922
10988
 
10923
10989
  // src/editor/components/SourceEditor/index.tsx
10924
- import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
10990
+ import { jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
10925
10991
  var [SourceEditorProvider, useSourceCodeEditor] = createContextState(
10926
10992
  ({ props }) => {
10927
10993
  return {
@@ -10929,7 +10995,7 @@ var [SourceEditorProvider, useSourceCodeEditor] = createContextState(
10929
10995
  };
10930
10996
  }
10931
10997
  );
10932
- var SourceCodeEditorCore = memo5(
10998
+ var SourceCodeEditorCore = memo6(
10933
10999
  (props) => {
10934
11000
  const { markdownToolBar, styleToken, textContainerProps = {} } = props;
10935
11001
  const { content, markText, hooks, isTesting, editable } = useSourceCodeEditor();
@@ -10937,9 +11003,9 @@ var SourceCodeEditorCore = memo5(
10937
11003
  try {
10938
11004
  initialCntent = markText.stringToDoc(content);
10939
11005
  } catch (error) {
10940
- return /* @__PURE__ */ jsx16(ErrorBoundary_default, { hasError: true, error, ...props.errorHandler || {} });
11006
+ return /* @__PURE__ */ jsx17(ErrorBoundary_default, { hasError: true, error, ...props.errorHandler || {} });
10941
11007
  }
10942
- return /* @__PURE__ */ jsx16(ErrorBoundary_default, { ...props.errorHandler || {}, children: /* @__PURE__ */ jsx16(SourceCodeThemeWrapper, { ...styleToken, children: /* @__PURE__ */ jsxs7(
11008
+ return /* @__PURE__ */ jsx17(ErrorBoundary_default, { ...props.errorHandler || {}, children: /* @__PURE__ */ jsx17(SourceCodeThemeWrapper, { ...styleToken, children: /* @__PURE__ */ jsxs8(
10943
11009
  Remirror,
10944
11010
  {
10945
11011
  manager: markText.manager,
@@ -10948,9 +11014,9 @@ var SourceCodeEditorCore = memo5(
10948
11014
  editable,
10949
11015
  onChange: props.onChange,
10950
11016
  children: [
10951
- /* @__PURE__ */ jsx16(Text_default, { ...textContainerProps }),
11017
+ /* @__PURE__ */ jsx17(Text_default, { ...textContainerProps }),
10952
11018
  markdownToolBar || null,
10953
- isTesting ? /* @__PURE__ */ jsx16(ProsemirrorDevTools, {}) : null
11019
+ isTesting ? /* @__PURE__ */ jsx17(ProsemirrorDevTools, {}) : null
10954
11020
  ]
10955
11021
  }
10956
11022
  ) }) });
@@ -10977,14 +11043,14 @@ var SourceEditor = (props) => {
10977
11043
  },
10978
11044
  [editorDelegate, props]
10979
11045
  );
10980
- return /* @__PURE__ */ jsx16(
11046
+ return /* @__PURE__ */ jsx17(
10981
11047
  SourceEditorProvider,
10982
11048
  {
10983
11049
  content,
10984
11050
  isTesting,
10985
11051
  markText: editorDelegate,
10986
11052
  hooks,
10987
- children: /* @__PURE__ */ jsx16(
11053
+ children: /* @__PURE__ */ jsx17(
10988
11054
  SourceCodeEditorCore,
10989
11055
  {
10990
11056
  styleToken,
@@ -10997,14 +11063,14 @@ var SourceEditor = (props) => {
10997
11063
  }
10998
11064
  );
10999
11065
  };
11000
- var SourceEditor_default = memo5(SourceEditor);
11066
+ var SourceEditor_default = memo6(SourceEditor);
11001
11067
 
11002
11068
  // src/editor/components/useContextMounted.tsx
11003
- import { useRemirrorContext as useRemirrorContext2 } from "@rme-sdk/react-core";
11004
- import { useEffect as useEffect5 } from "react";
11069
+ import { useRemirrorContext as useRemirrorContext3 } from "@rme-sdk/react-core";
11070
+ import { useEffect as useEffect6 } from "react";
11005
11071
  var useContextMounted = (onContextMounted) => {
11006
- const remirrorContext = useRemirrorContext2();
11007
- useEffect5(() => {
11072
+ const remirrorContext = useRemirrorContext3();
11073
+ useEffect6(() => {
11008
11074
  if (onContextMounted) {
11009
11075
  onContextMounted(remirrorContext);
11010
11076
  }
@@ -11014,269 +11080,11 @@ var useContextMounted = (onContextMounted) => {
11014
11080
  // src/editor/components/WysiwygEditor/index.tsx
11015
11081
  import { ProsemirrorDevTools as ProsemirrorDevTools2 } from "@rme-sdk/dev";
11016
11082
  import { Remirror as Remirror2 } from "@rme-sdk/react";
11017
- import { memo as memo8, useCallback as useCallback19, useEffect as useEffect8, useMemo as useMemo5 } from "react";
11018
-
11019
- // src/editor/toolbar/BlockHandler/index.tsx
11020
- import { isHTMLElement as isHTMLElement5 } from "@ocavue/utils";
11021
- import { NodeSelection as NodeSelection4 } from "@rme-sdk/pm/state";
11022
- import { useExtension, useRemirrorContext as useRemirrorContext3 } from "@rme-sdk/react-core";
11023
- import { memo as memo6 } from "react";
11024
- import styled10 from "styled-components";
11025
-
11026
- // src/editor/extensions/NodeIndicator/drag-preview.ts
11027
- import { isHTMLElement as isHTMLElement4 } from "@ocavue/utils";
11028
- import { Fragment as Fragment6, Slice as Slice3 } from "@rme-sdk/pm";
11029
- import { NodeSelection as NodeSelection3 } from "@rme-sdk/pm/state";
11030
-
11031
- // src/editor/utils/get-box-element.ts
11032
- function getBoxElement(element) {
11033
- const window2 = element.ownerDocument.defaultView;
11034
- if (!window2) {
11035
- return;
11036
- }
11037
- const style = window2.getComputedStyle(element);
11038
- const display = style.display;
11039
- if (display === "contents" && element.childElementCount === 1) {
11040
- return element.firstElementChild;
11041
- } else if (display === "none") {
11042
- return;
11043
- }
11044
- return element;
11045
- }
11046
-
11047
- // src/editor/extensions/NodeIndicator/set-drag-preview.ts
11048
- function setDragPreview(event2, element) {
11049
- const { top, bottom, left, right } = getClientRect(element);
11050
- const width = right - left;
11051
- const height = bottom - top;
11052
- const elementX = left;
11053
- const elementY = top;
11054
- const { clientX, clientY } = event2;
11055
- const document2 = element.ownerDocument;
11056
- const container = document2.createElement("div");
11057
- const outsideX = Math.round(elementX - clientX);
11058
- const outsideY = Math.round(elementY - clientY);
11059
- const borderX = Math.max(outsideX, 0);
11060
- const borderY = Math.max(outsideY, 0);
11061
- Object.assign(container.style, {
11062
- // Ensuring we don't cause reflow when adding the element to the page using
11063
- // `position:fixed` rather than `position:absolute` so we are positioned on
11064
- // the current viewport. `position:fixed` also creates a new stacking
11065
- // context, so we don't need to do that here.
11066
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/56276552/packages/core/src/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.ts#L60
11067
- position: "fixed",
11068
- // The element is positioned off-screen to avoid capturing the content of
11069
- // the page on Safari when the dragging element has a transparent background
11070
- // on Safari. See https://github.com/prosekit/prosekit/issues/1153 for more
11071
- // details.
11072
- top: "-1000vh",
11073
- left: "-1000vw",
11074
- // The element should not be interactive.
11075
- pointerEvents: "none",
11076
- // The element should be on top of everything else.
11077
- zIndex: "2147483647",
11078
- // Only reliable cross browser technique found to push a drag preview away
11079
- // from the cursor is to use transparent borders on the container.
11080
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/56276552/packages/core/src/public-utils/element/custom-native-drag-preview/pointer-outside-of-preview.ts#L13-L18
11081
- borderLeft: `${borderX}px solid transparent`,
11082
- borderTop: `${borderY}px solid transparent`,
11083
- boxSizing: "border-box",
11084
- width: `${width + borderX}px`,
11085
- height: `${height + borderY}px`
11086
- });
11087
- const [clonedElement, styleText] = deepCloneElement(element, true);
11088
- clonedElement.style.setProperty("opacity", "0.7", "important");
11089
- clonedElement.style.setProperty("margin", "0", "important");
11090
- clonedElement.style.setProperty("outline-color", "transparent", "important");
11091
- document2.body.appendChild(container);
11092
- container.appendChild(clonedElement);
11093
- injectStyle(container, styleText);
11094
- event2.dataTransfer?.setDragImage(container, Math.max(-outsideX, 0), Math.max(-outsideY, 0));
11095
- setTimeout(() => {
11096
- if (document2.body.contains(container)) {
11097
- document2.body.removeChild(container);
11098
- }
11099
- }, 100);
11100
- const cleanupHandler = () => {
11101
- if (document2.body.contains(container)) {
11102
- document2.body.removeChild(container);
11103
- }
11104
- document2.removeEventListener("dragend", cleanupHandler);
11105
- };
11106
- document2.addEventListener("dragend", cleanupHandler, { once: true });
11107
- }
11108
-
11109
- // src/editor/extensions/NodeIndicator/drag-preview.ts
11110
- function createDraggingPreview(view, hoverState, event2) {
11111
- if (!event2.dataTransfer) {
11112
- return;
11113
- }
11114
- const { pos } = hoverState;
11115
- if (pos == null) {
11116
- return;
11117
- }
11118
- const element = view.nodeDOM(pos);
11119
- if (!element || !isHTMLElement4(element)) {
11120
- return;
11121
- }
11122
- const boxElement = getBoxElement(element);
11123
- if (!boxElement || !isHTMLElement4(boxElement)) {
11124
- return;
11125
- }
11126
- event2.dataTransfer.clearData();
11127
- event2.dataTransfer.setData("text/html", boxElement.outerHTML);
11128
- event2.dataTransfer.effectAllowed = "copyMove";
11129
- setDragPreview(event2, boxElement);
11130
- return;
11131
- }
11132
- function setViewDragging(view, hoverState) {
11133
- const { node, pos } = hoverState;
11134
- const dragging = {
11135
- slice: new Slice3(Fragment6.from(node), 0, 0),
11136
- move: true,
11137
- node: NodeSelection3.create(view.state.doc, pos)
11138
- };
11139
- view.dragging = dragging;
11140
- }
11141
-
11142
- // src/editor/toolbar/BlockHandler/index.tsx
11143
- import { jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
11144
- var nodeTypeIconMap = {
11145
- "heading-1": "ri-h-1",
11146
- "heading-2": "ri-h-2",
11147
- "heading-3": "ri-h-3",
11148
- "heading-4": "ri-h-4",
11149
- "heading-5": "ri-h-5",
11150
- "heading-6": "ri-h-6",
11151
- paragraph: "ri-paragraph",
11152
- "list-bullet": "ri-list-unordered",
11153
- "list-ordered": "ri-list-ordered",
11154
- "list-task": "ri-list-check-3",
11155
- codeMirror: "ri-code-box-line",
11156
- table: "ri-table-line",
11157
- html_block: "ri-html5-line",
11158
- math_block: "ri-formula"
11159
- };
11160
- var BlockHandler = memo6(() => {
11161
- const { view: editorView } = useRemirrorContext3({ autoUpdate: true });
11162
- const nodeIndicatorExtension = useExtension(NodeIndicatorExtension);
11163
- const state = nodeIndicatorExtension.getPluginState();
11164
- const handleClick = () => {
11165
- if (editorView && nodeIndicatorExtension) {
11166
- const state2 = nodeIndicatorExtension.getPluginState();
11167
- if (state2 && state2.pos !== null && state2.node) {
11168
- const tr = editorView.state.tr;
11169
- tr.setSelection(NodeSelection4.create(tr.doc, state2.pos));
11170
- editorView.dispatch(tr);
11171
- }
11172
- }
11173
- };
11174
- const handleDragStart = (event2) => {
11175
- console.log("handleDragStart - Tauri\u62D6\u62FD\u5F00\u59CB");
11176
- if (editorView && nodeIndicatorExtension) {
11177
- const state2 = nodeIndicatorExtension.getPluginState();
11178
- if (state2 && state2.pos !== null && state2.node && state2.node.isBlock) {
11179
- const tr = editorView.state.tr;
11180
- tr.setSelection(NodeSelection4.create(tr.doc, state2.pos));
11181
- tr.setMeta(nodeIndicatorExtension.pluginKey, { isDragging: true });
11182
- editorView.dispatch(tr);
11183
- const dom = editorView.nodeDOM(state2.pos);
11184
- if (dom && isHTMLElement5(dom)) {
11185
- if (event2.dataTransfer) {
11186
- event2.dataTransfer.effectAllowed = "move";
11187
- event2.dataTransfer.setData("text/plain", state2.node.textContent);
11188
- event2.dataTransfer.setData("application/x-node-position", String(state2.pos));
11189
- }
11190
- createDraggingPreview(editorView, state2, event2);
11191
- setViewDragging(editorView, state2);
11192
- }
11193
- }
11194
- }
11195
- };
11196
- const handleDragOver = (event2) => {
11197
- console.log("handleDragOver - Tauri\u62D6\u62FD\u60AC\u505C");
11198
- event2.preventDefault();
11199
- event2.dataTransfer.dropEffect = "move";
11200
- };
11201
- const handleDragEnd = (event2) => {
11202
- console.log("handleDragEnd - Tauri\u62D6\u62FD\u7ED3\u675F");
11203
- if (editorView && nodeIndicatorExtension) {
11204
- const tr = editorView.state.tr;
11205
- tr.setMeta(nodeIndicatorExtension.pluginKey, { isDragging: false });
11206
- editorView.dispatch(tr);
11207
- }
11208
- };
11209
- const handleDragLeave = (event2) => {
11210
- console.log("handleDragLeave - Tauri\u62D6\u62FD\u79BB\u5F00");
11211
- };
11212
- if (!editorView || !state?.node) {
11213
- return null;
11214
- }
11215
- const renderIcon = () => {
11216
- let key2 = state?.node?.type?.name || "";
11217
- if (state?.node?.type?.name === "heading") {
11218
- key2 = `heading-${state?.node?.attrs?.level}`;
11219
- }
11220
- if (state?.node?.type?.name === "list") {
11221
- key2 = `list-${state?.node?.attrs?.kind}`;
11222
- }
11223
- const iconName = nodeTypeIconMap[key2 || ""];
11224
- if (iconName) {
11225
- return /* @__PURE__ */ jsx17("i", { className: iconName });
11226
- }
11227
- return null;
11228
- };
11229
- return /* @__PURE__ */ jsxs8(
11230
- Container3,
11231
- {
11232
- className: "rme-block-handler",
11233
- draggable: "true",
11234
- onClick: handleClick,
11235
- onDragStart: handleDragStart,
11236
- onDragOver: handleDragOver,
11237
- onDragEnd: handleDragEnd,
11238
- onDragLeave: handleDragLeave,
11239
- style: {
11240
- position: "fixed",
11241
- left: `${state?.rect?.left ? state.rect.left - 38 : 0}px`,
11242
- top: `${state?.rect?.top || 0}px`
11243
- },
11244
- children: [
11245
- renderIcon(),
11246
- /* @__PURE__ */ jsx17("div", { className: "rme-draggable-handler", children: /* @__PURE__ */ jsx17("i", { className: "ri-draggable" }) })
11247
- ]
11248
- },
11249
- "rme-block-handler"
11250
- );
11251
- });
11252
- var Container3 = styled10.div`
11253
- display: flex;
11254
- align-items: center;
11255
- justify-content: center;
11256
- padding: 0 2px;
11257
- border: 1px solid ${(props) => props.theme.borderColor};
11258
- border-radius: 4px;
11259
- font-size: 14px;
11260
- z-index: 1000;
11261
-
11262
- .rme-draggable-handler {
11263
- display: flex;
11264
- align-items: center;
11265
- justify-content: center;
11266
- height: 18px;
11267
- width: 18px;
11268
- border-radius: 4px;
11269
- cursor: grab;
11270
-
11271
- &:hover {
11272
- background-color: ${(props) => props.theme.hoverColor};
11273
- }
11274
- }
11275
- `;
11083
+ import { memo as memo8, useCallback as useCallback19, useEffect as useEffect9, useMemo as useMemo5 } from "react";
11276
11084
 
11277
11085
  // src/editor/toolbar/SlashMenu/index.tsx
11278
11086
  import { useExtension as useExtension2, useRemirrorContext as useRemirrorContext4 } from "@rme-sdk/react-core";
11279
- import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef6, useState as useState6 } from "react";
11087
+ import { useCallback as useCallback5, useEffect as useEffect7, useMemo as useMemo3, useRef as useRef6, useState as useState7 } from "react";
11280
11088
  import { usePopper } from "react-popper";
11281
11089
  import styled11 from "styled-components";
11282
11090
  import { Fragment as Fragment7, jsx as jsx18 } from "react/jsx-runtime";
@@ -11289,7 +11097,7 @@ var SlashMenu = () => {
11289
11097
  const slashMenuExtension = useExtension2(SlashMenuExtension);
11290
11098
  const menuState = slashMenuExtension.getPluginState();
11291
11099
  const rootRef = useRef6(null);
11292
- useEffect6(() => {
11100
+ useEffect7(() => {
11293
11101
  if (!rootRef) return;
11294
11102
  const outsideClickHandler = (event2) => {
11295
11103
  if (rootRef.current && (!event2.target || !(event2.target instanceof Node) || !rootRef.current.contains(event2?.target))) {
@@ -11303,7 +11111,7 @@ var SlashMenu = () => {
11303
11111
  document.removeEventListener("mousedown", outsideClickHandler);
11304
11112
  };
11305
11113
  }, [editorView, rootRef, slashMenuExtension.pluginKey]);
11306
- const [popperElement, setPopperElement] = useState6(null);
11114
+ const [popperElement, setPopperElement] = useState7(null);
11307
11115
  const virtualReference = useMemo3(() => {
11308
11116
  const domNode = editorView.domAtPos(editorState.selection.to)?.node;
11309
11117
  const cursorPosition = editorView.state.selection.to;
@@ -11379,7 +11187,7 @@ var Container4 = styled11.div`
11379
11187
 
11380
11188
  // src/editor/toolbar/TableToolbar/index.tsx
11381
11189
  import { PositionerPortal, useCommands as useCommands3, useMultiPositioner } from "@rme-sdk/react";
11382
- import { useEffect as useEffect7 } from "react";
11190
+ import { useEffect as useEffect8 } from "react";
11383
11191
 
11384
11192
  // src/editor/toolbar/TableToolbar/ActiveCellMenu.tsx
11385
11193
  import {
@@ -11392,7 +11200,7 @@ import {
11392
11200
  Popper
11393
11201
  } from "@mui/material";
11394
11202
  import { useCommands } from "@rme-sdk/react";
11395
- import { useRef as useRef7, useState as useState7 } from "react";
11203
+ import { useRef as useRef7, useState as useState8 } from "react";
11396
11204
  import { useTranslation as useTranslation2 } from "react-i18next";
11397
11205
  import styled12 from "styled-components";
11398
11206
  import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
@@ -11406,7 +11214,7 @@ var Container5 = styled12.div`
11406
11214
  var ActiveCellMenu = (props) => {
11407
11215
  const { positioner } = props;
11408
11216
  const commands = useCommands();
11409
- const [open, setOpen] = useState7(false);
11217
+ const [open, setOpen] = useState8(false);
11410
11218
  const anchorRef = useRef7(null);
11411
11219
  const { t: t19 } = useTranslation2();
11412
11220
  const options = [
@@ -11627,7 +11435,7 @@ import { Fragment as Fragment8, jsx as jsx21 } from "react/jsx-runtime";
11627
11435
  var MultiPositionerIllustration = ({ positioner }) => {
11628
11436
  const positioners = useMultiPositioner(positioner, []);
11629
11437
  const { forceUpdatePositioners } = useCommands3();
11630
- useEffect7(() => {
11438
+ useEffect8(() => {
11631
11439
  forceUpdatePositioners();
11632
11440
  }, [forceUpdatePositioners]);
11633
11441
  if (positioners.length === 0) return null;
@@ -12264,7 +12072,7 @@ var WysiwygEditor = (props) => {
12264
12072
  },
12265
12073
  [editorDelegate, props]
12266
12074
  );
12267
- useEffect8(() => {
12075
+ useEffect9(() => {
12268
12076
  const ext = editorDelegate.manager.getExtension(TransformerExtension);
12269
12077
  if (ext) {
12270
12078
  editorDelegate?.manager?.view?.dispatch(
@@ -12315,7 +12123,7 @@ var Editor = memo9(
12315
12123
  onContextMounted,
12316
12124
  ...otherProps
12317
12125
  } = props;
12318
- const [type, setType] = useState8(initialType);
12126
+ const [type, setType] = useState9(initialType);
12319
12127
  useImperativeHandle2(ref, () => ({
12320
12128
  getType: () => type,
12321
12129
  toggleType: (targetType) => {
@@ -12378,7 +12186,7 @@ var defaultStyleToken = {
12378
12186
 
12379
12187
  // src/editor/components/ThemeProvider.tsx
12380
12188
  import { ThemeProvider as ScThemeProvider } from "styled-components";
12381
- import { memo as memo10, useEffect as useEffect9 } from "react";
12189
+ import { memo as memo10, useEffect as useEffect10 } from "react";
12382
12190
 
12383
12191
  // src/editor/i18n/index.ts
12384
12192
  import i18next from "i18next";
@@ -12461,7 +12269,7 @@ var ThemeProvider = memo10(({ theme, i18n, children }) => {
12461
12269
  const mode = theme?.mode || "light";
12462
12270
  const defaultThemeToken = mode === "dark" ? darkTheme.styledConstants : lightTheme.styledConstants;
12463
12271
  const themeToken = theme?.token ? { ...defaultThemeToken, ...theme.token } : defaultThemeToken;
12464
- useEffect9(() => {
12272
+ useEffect10(() => {
12465
12273
  if (i18n?.locales) {
12466
12274
  i18nInit(i18n.locales).then(() => {
12467
12275
  if (i18n?.language) {
@@ -12470,7 +12278,7 @@ var ThemeProvider = memo10(({ theme, i18n, children }) => {
12470
12278
  });
12471
12279
  }
12472
12280
  }, [i18n]);
12473
- useEffect9(() => {
12281
+ useEffect10(() => {
12474
12282
  const codemirrorTheme = theme?.codemirrorTheme || mode === "dark" ? darkTheme.codemirrorTheme : lightTheme.codemirrorTheme;
12475
12283
  changeTheme(codemirrorTheme);
12476
12284
  mermaid2.initialize({
@@ -12482,7 +12290,7 @@ var ThemeProvider = memo10(({ theme, i18n, children }) => {
12482
12290
  });
12483
12291
 
12484
12292
  // src/editor/components/Preview/preview.tsx
12485
- import { useEffect as useEffect10, useState as useState9 } from "react";
12293
+ import { useEffect as useEffect11, useState as useState10 } from "react";
12486
12294
  import { Icon } from "zens";
12487
12295
 
12488
12296
  // src/editor/utils/prosemirrorNodeToHtml.ts
@@ -12565,12 +12373,12 @@ var rmeProsemirrorNodeToHtml = async (doc, delegateOptions) => {
12565
12373
  import { jsx as jsx41 } from "react/jsx-runtime";
12566
12374
  var Preview = (props) => {
12567
12375
  const { doc, delegateOptions } = props;
12568
- const [processedHtml, setProcessedHtml] = useState9("");
12376
+ const [processedHtml, setProcessedHtml] = useState10("");
12569
12377
  let targetDoc = doc;
12570
12378
  if (typeof targetDoc === "string") {
12571
12379
  targetDoc = createWysiwygDelegate(delegateOptions).stringToDoc(targetDoc);
12572
12380
  }
12573
- useEffect10(() => {
12381
+ useEffect11(() => {
12574
12382
  rmeProsemirrorNodeToHtml(targetDoc, delegateOptions).then((html2) => {
12575
12383
  setProcessedHtml(html2);
12576
12384
  }).catch((e) => {