@antdv-next/x 1.2.3-beta.1 → 1.2.4

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.
@@ -265,10 +265,10 @@ var SlotTextAreaProseMirror_default = /* @__PURE__ */ defineComponent({
265
265
  (type === "copy" ? senderCtx.value.onCopy : senderCtx.value.onCut)?.(event, info);
266
266
  if (event.defaultPrevented) return true;
267
267
  if (type === "copy" && !slice && !payloadText) return false;
268
+ if (type === "cut" && isLocked()) return true;
268
269
  try {
269
270
  event.clipboardData?.setData("text/plain", payloadText);
270
271
  } catch {}
271
- if (type === "cut" && isLocked()) return true;
272
272
  if (type === "cut" && slice) {
273
273
  flushDom();
274
274
  syncSelectionFromDom();
@@ -414,7 +414,8 @@ var SlotTextAreaProseMirror_default = /* @__PURE__ */ defineComponent({
414
414
  skill: void 0
415
415
  };
416
416
  senderCtx.value.onPaste?.(event, info);
417
- if (!event.defaultPrevented) routePasteEvent(event);
417
+ if (!event.defaultPrevented) if (isLocked()) event.preventDefault();
418
+ else routePasteEvent(event);
418
419
  },
419
420
  "onCopy": (event) => {
420
421
  routeControlCopyOrCut(event, "copy");
@@ -746,10 +747,37 @@ var SlotTextAreaProseMirror_default = /* @__PURE__ */ defineComponent({
746
747
  if (pos !== null) {
747
748
  const contentNode = editorView.state.doc.nodeAt(pos);
748
749
  if (contentNode && contentNode.type === senderSchema.nodes.contentSlot) try {
749
- const from = editorView.posAtDOM(nativeRange.startContainer, nativeRange.startOffset);
750
- const to = editorView.posAtDOM(nativeRange.endContainer, nativeRange.endOffset);
751
750
  const contentFrom = pos + 1;
752
751
  const contentTo = pos + contentNode.nodeSize - 1;
752
+ const domNodeSize = (node) => {
753
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent?.length ?? 0;
754
+ if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "BR") return 1;
755
+ let size = 0;
756
+ node.childNodes.forEach((child) => {
757
+ size += domNodeSize(child);
758
+ });
759
+ return size;
760
+ };
761
+ const contentOffsetAt = (container, offset) => {
762
+ let current = container;
763
+ let result = container.nodeType === Node.TEXT_NODE ? offset : Array.from(container.childNodes).slice(0, offset).reduce((sum, child) => sum + domNodeSize(child), 0);
764
+ while (current && current !== startContent) {
765
+ const parent = current.parentNode;
766
+ if (!parent) return null;
767
+ let sibling = current.previousSibling;
768
+ while (sibling) {
769
+ result += domNodeSize(sibling);
770
+ sibling = sibling.previousSibling;
771
+ }
772
+ current = parent;
773
+ }
774
+ return current === startContent ? result : null;
775
+ };
776
+ const startOffset = contentOffsetAt(nativeRange.startContainer, nativeRange.startOffset);
777
+ const endOffset = contentOffsetAt(nativeRange.endContainer, nativeRange.endOffset);
778
+ if (startOffset === null || endOffset === null) return false;
779
+ const from = contentFrom + startOffset;
780
+ const to = contentFrom + endOffset;
753
781
  if (contentFrom <= from && from <= to && to <= contentTo) {
754
782
  event.preventDefault();
755
783
  const transaction = editorView.state.tr.delete(from, to);
@@ -1,12 +1,15 @@
1
1
  import ActionButton, { useActionButtonContext } from "../ActionButton.js";
2
2
  import RecordingIcon_default from "./RecordingIcon.js";
3
- import { computed, createVNode, defineComponent, mergeProps } from "vue";
3
+ import { computed, createVNode, defineComponent, isVNode, mergeProps } from "vue";
4
4
  import { AudioMutedOutlined, AudioOutlined } from "@antdv-next/icons";
5
5
  //#region components/sender/components/SpeechButton/index.tsx
6
+ function _isSlot(s) {
7
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
8
+ }
6
9
  var SpeechButton_default = /* @__PURE__ */ defineComponent({
7
10
  name: "SpeechButton",
8
11
  inheritAttrs: false,
9
- setup(_, { attrs }) {
12
+ setup(_, { attrs, slots }) {
10
13
  const context = useActionButtonContext();
11
14
  const mergedDisabled = computed(() => {
12
15
  return attrs.disabled ?? context.value.disabled ?? context.value.onSpeechDisabled;
@@ -21,7 +24,7 @@ var SpeechButton_default = /* @__PURE__ */ defineComponent({
21
24
  "icon": icon.value,
22
25
  "variant": "text",
23
26
  "color": "primary"
24
- }, attrs, { "action": "onSpeech" }), null);
27
+ }, attrs, { "action": "onSpeech" }), _isSlot(slots) ? slots : { default: () => [slots] });
25
28
  }
26
29
  });
27
30
  //#endregion