slate-vue3 0.0.22 → 0.0.24

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/README.md CHANGED
@@ -8,19 +8,21 @@
8
8
  # How to use?
9
9
 
10
10
  ## 1. install slate-vue3
11
- ```
11
+ ```sh
12
12
  npm install slate-vue3
13
13
  ```
14
14
  ## 2. now, you can use it in vue-sfc
15
- ```
15
+ ```vue
16
16
  <script setup lang="ts">
17
17
  import { withDOM, Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder, createEditor, withHistory } from "slate-vue3"
18
18
  import { h } from "vue";
19
19
 
20
- const initialValue = [{
21
- type: 'paragraph',
22
- children: [{ text: 'Let's start' }]
23
- }]
20
+ const initialValue = [
21
+ {
22
+ type: 'paragraph',
23
+ children: [{ text: 'Let us start'}]
24
+ }
25
+ ]
24
26
  const renderElement = ({ attributes, children }) => h('p', attributes, children)
25
27
  const editor = withHistory(withDOM(createEditor(initialValue)))
26
28
  </script>
@@ -45,7 +47,7 @@ const editor = withHistory(withDOM(createEditor(initialValue)))
45
47
  > Get the current composing state of the editor. It deals with compositionstart, compositionupdate, compositionend events.
46
48
 
47
49
  const useComposing : ( ) => Ref<boolean>
48
- ```
50
+ ```javascript
49
51
  import { useComposing } from 'slate-vue3'
50
52
 
51
53
  const composing = useComposing()
@@ -55,7 +57,7 @@ const composing = useComposing()
55
57
  > Get the current focused state of the editor.
56
58
 
57
59
  const useFocused : ( ) => Ref<boolean>
58
- ```
60
+ ```javascript
59
61
  import { useFocused } from 'slate-vue3'
60
62
 
61
63
  const focused = useFocused()
@@ -65,7 +67,7 @@ const focused = useFocused()
65
67
  > Get the current readOnly state of the editor.
66
68
 
67
69
  const useReadOnly : ( ) => Ref<boolean>
68
- ```
70
+ ```javascript
69
71
  import { useReadOnly } from 'slate-vue3'
70
72
 
71
73
  const readonly = useReadOnly()
@@ -75,7 +77,7 @@ const readonly = useReadOnly()
75
77
  > Get the current selected state of an element.
76
78
 
77
79
  const useSelected : ( ) => ComputedRef<boolean>
78
- ```
80
+ ```javascript
79
81
  import { useSelected } from 'slate-vue3'
80
82
 
81
83
  const selected = useSelected()
@@ -85,7 +87,7 @@ const selected = useSelected()
85
87
  > Get the current editor object from the context. Context whenever changes occur in the editor.
86
88
 
87
89
  const useEditor : ( ) => Editor
88
- ```
90
+ ```javascript
89
91
  import { useEditor } from 'slate-vue3'
90
92
 
91
93
  const editor = useEditor()
@@ -95,7 +97,7 @@ const editor = useEditor()
95
97
  > Get the current editor selection from the context.
96
98
 
97
99
  const useSelection : ( ) => ComputedRef<Selection>
98
- ```
100
+ ```javascript
99
101
  import { useSelection } from 'slate-vue3'
100
102
 
101
103
  const selection = useSelection()
@@ -106,7 +108,7 @@ const selection = useSelection()
106
108
  > Automatically bind ref to the real node when the component is mounted,This is important when rendering element nodes directly
107
109
 
108
110
  const useInheritRef : ( attribute: HTMLAttributes ) => HTMLAttributes
109
- ```
111
+ ```javascript
110
112
  const renderElement = (props: RenderElementProps) => {
111
113
  const { attributes, children, element } = props
112
114
  switch (element.type) {
package/dist/index.d.ts CHANGED
@@ -321,9 +321,6 @@ export declare type Descendant = Element_2 | Text_2;
321
321
 
322
322
  export declare const deselect: SelectionTransforms['deselect'];
323
323
 
324
- /**
325
- * A DOM-specific version of the `Editor` interface.
326
- */
327
324
  export declare interface DOMEditor extends BaseEditor {
328
325
  hasEditableTarget: (editor: DOMEditor, target: EventTarget | null) => target is DOMNode_2;
329
326
  hasRange: (editor: DOMEditor, range: Range_2) => boolean;
@@ -333,7 +330,7 @@ export declare interface DOMEditor extends BaseEditor {
333
330
  insertFragmentData: (data: DataTransfer) => boolean;
334
331
  insertTextData: (data: DataTransfer) => boolean;
335
332
  isTargetInsideNonReadonlyVoid: (editor: DOMEditor, target: EventTarget | null) => boolean;
336
- setFragmentData: (data: DataTransfer, originEvent?: 'drag' | 'copy' | 'cut') => void;
333
+ setFragmentData: (data: DataTransfer, originEvent?: "drag" | "copy" | "cut") => void;
337
334
  }
338
335
 
339
336
  export declare const DOMEditor: DOMEditorInterface;
@@ -432,7 +429,7 @@ export declare interface DOMEditorInterface {
432
429
  /**
433
430
  * Sets data from the currently selected fragment on a `DataTransfer`.
434
431
  */
435
- setFragmentData: (editor: DOMEditor, data: DataTransfer, originEvent?: 'drag' | 'copy' | 'cut') => void;
432
+ setFragmentData: (editor: DOMEditor, data: DataTransfer, originEvent?: "drag" | "copy" | "cut") => void;
436
433
  /**
437
434
  * Find the native DOM element from a Slate node.
438
435
  */
@@ -464,7 +461,7 @@ export declare interface DOMEditorInterface {
464
461
  * The direction to search for Slate leaf nodes if `domPoint` is
465
462
  * non-editable and non-void.
466
463
  */
467
- searchDirection?: 'forward' | 'backward';
464
+ searchDirection?: "forward" | "backward";
468
465
  }) => T extends true ? Point | null : Point;
469
466
  /**
470
467
  * Find a Slate range from a DOM range or selection.
package/dist/index.js CHANGED
@@ -857,44 +857,10 @@ function baseToString(value) {
857
857
  var result = value + "";
858
858
  return result == "0" && 1 / value == -Infinity ? "-0" : result;
859
859
  }
860
- var reWhitespace = /\s/;
861
- function trimmedEndIndex(string2) {
862
- var index = string2.length;
863
- while (index-- && reWhitespace.test(string2.charAt(index))) {
864
- }
865
- return index;
866
- }
867
- var reTrimStart = /^\s+/;
868
- function baseTrim(string2) {
869
- return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
870
- }
871
860
  function isObject(value) {
872
861
  var type = typeof value;
873
862
  return value != null && (type == "object" || type == "function");
874
863
  }
875
- var NAN = 0 / 0;
876
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
877
- var reIsBinary = /^0b[01]+$/i;
878
- var reIsOctal = /^0o[0-7]+$/i;
879
- var freeParseInt = parseInt;
880
- function toNumber(value) {
881
- if (typeof value == "number") {
882
- return value;
883
- }
884
- if (isSymbol(value)) {
885
- return NAN;
886
- }
887
- if (isObject(value)) {
888
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
889
- value = isObject(other) ? other + "" : other;
890
- }
891
- if (typeof value != "string") {
892
- return value === 0 ? value : +value;
893
- }
894
- value = baseTrim(value);
895
- var isBinary = reIsBinary.test(value);
896
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
897
- }
898
864
  function identity(value) {
899
865
  return value;
900
866
  }
@@ -1086,11 +1052,11 @@ function copyObject(source, props, object, customizer) {
1086
1052
  }
1087
1053
  return object;
1088
1054
  }
1089
- var nativeMax$1 = Math.max;
1055
+ var nativeMax = Math.max;
1090
1056
  function overRest(func, start2, transform) {
1091
- start2 = nativeMax$1(start2 === void 0 ? func.length - 1 : start2, 0);
1057
+ start2 = nativeMax(start2 === void 0 ? func.length - 1 : start2, 0);
1092
1058
  return function() {
1093
- var args = arguments, index = -1, length = nativeMax$1(args.length - start2, 0), array = Array(length);
1059
+ var args = arguments, index = -1, length = nativeMax(args.length - start2, 0), array = Array(length);
1094
1060
  while (++index < length) {
1095
1061
  array[index] = args[start2 + index];
1096
1062
  }
@@ -1400,10 +1366,10 @@ MapCache.prototype["delete"] = mapCacheDelete;
1400
1366
  MapCache.prototype.get = mapCacheGet;
1401
1367
  MapCache.prototype.has = mapCacheHas;
1402
1368
  MapCache.prototype.set = mapCacheSet;
1403
- var FUNC_ERROR_TEXT$2 = "Expected a function";
1369
+ var FUNC_ERROR_TEXT = "Expected a function";
1404
1370
  function memoize(func, resolver) {
1405
1371
  if (typeof func != "function" || resolver != null && typeof resolver != "function") {
1406
- throw new TypeError(FUNC_ERROR_TEXT$2);
1372
+ throw new TypeError(FUNC_ERROR_TEXT);
1407
1373
  }
1408
1374
  var memoized = function() {
1409
1375
  var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
@@ -1822,92 +1788,6 @@ var CLONE_DEEP_FLAG$1 = 1, CLONE_SYMBOLS_FLAG$1 = 4;
1822
1788
  function cloneDeep(value) {
1823
1789
  return baseClone(value, CLONE_DEEP_FLAG$1 | CLONE_SYMBOLS_FLAG$1);
1824
1790
  }
1825
- var now = function() {
1826
- return root.Date.now();
1827
- };
1828
- var FUNC_ERROR_TEXT$1 = "Expected a function";
1829
- var nativeMax = Math.max, nativeMin = Math.min;
1830
- function debounce(func, wait, options) {
1831
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
1832
- if (typeof func != "function") {
1833
- throw new TypeError(FUNC_ERROR_TEXT$1);
1834
- }
1835
- wait = toNumber(wait) || 0;
1836
- if (isObject(options)) {
1837
- leading = !!options.leading;
1838
- maxing = "maxWait" in options;
1839
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
1840
- trailing = "trailing" in options ? !!options.trailing : trailing;
1841
- }
1842
- function invokeFunc(time) {
1843
- var args = lastArgs, thisArg = lastThis;
1844
- lastArgs = lastThis = void 0;
1845
- lastInvokeTime = time;
1846
- result = func.apply(thisArg, args);
1847
- return result;
1848
- }
1849
- function leadingEdge(time) {
1850
- lastInvokeTime = time;
1851
- timerId = setTimeout(timerExpired, wait);
1852
- return leading ? invokeFunc(time) : result;
1853
- }
1854
- function remainingWait(time) {
1855
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
1856
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
1857
- }
1858
- function shouldInvoke(time) {
1859
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
1860
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
1861
- }
1862
- function timerExpired() {
1863
- var time = now();
1864
- if (shouldInvoke(time)) {
1865
- return trailingEdge(time);
1866
- }
1867
- timerId = setTimeout(timerExpired, remainingWait(time));
1868
- }
1869
- function trailingEdge(time) {
1870
- timerId = void 0;
1871
- if (trailing && lastArgs) {
1872
- return invokeFunc(time);
1873
- }
1874
- lastArgs = lastThis = void 0;
1875
- return result;
1876
- }
1877
- function cancel() {
1878
- if (timerId !== void 0) {
1879
- clearTimeout(timerId);
1880
- }
1881
- lastInvokeTime = 0;
1882
- lastArgs = lastCallTime = lastThis = timerId = void 0;
1883
- }
1884
- function flush() {
1885
- return timerId === void 0 ? result : trailingEdge(now());
1886
- }
1887
- function debounced() {
1888
- var time = now(), isInvoking = shouldInvoke(time);
1889
- lastArgs = arguments;
1890
- lastThis = this;
1891
- lastCallTime = time;
1892
- if (isInvoking) {
1893
- if (timerId === void 0) {
1894
- return leadingEdge(lastCallTime);
1895
- }
1896
- if (maxing) {
1897
- clearTimeout(timerId);
1898
- timerId = setTimeout(timerExpired, wait);
1899
- return invokeFunc(lastCallTime);
1900
- }
1901
- }
1902
- if (timerId === void 0) {
1903
- timerId = setTimeout(timerExpired, wait);
1904
- }
1905
- return result;
1906
- }
1907
- debounced.cancel = cancel;
1908
- debounced.flush = flush;
1909
- return debounced;
1910
- }
1911
1791
  function last$1(array) {
1912
1792
  var length = array == null ? 0 : array.length;
1913
1793
  return length ? array[length - 1] : void 0;
@@ -1945,22 +1825,6 @@ var omit = flatRest(function(object, paths) {
1945
1825
  }
1946
1826
  return result;
1947
1827
  });
1948
- var FUNC_ERROR_TEXT = "Expected a function";
1949
- function throttle(func, wait, options) {
1950
- var leading = true, trailing = true;
1951
- if (typeof func != "function") {
1952
- throw new TypeError(FUNC_ERROR_TEXT);
1953
- }
1954
- if (isObject(options)) {
1955
- leading = "leading" in options ? !!options.leading : leading;
1956
- trailing = "trailing" in options ? !!options.trailing : trailing;
1957
- }
1958
- return debounce(func, wait, {
1959
- "leading": leading,
1960
- "maxWait": wait,
1961
- "trailing": trailing
1962
- });
1963
- }
1964
1828
  const isElement = (value) => {
1965
1829
  return isPlainObject$1(value) && Node.isNodeList(value.children) && !Editor.isEditor(value);
1966
1830
  };
@@ -5477,6 +5341,19 @@ const PLACEHOLDER_SYMBOL = Symbol("placeholder");
5477
5341
  const MARK_PLACEHOLDER_SYMBOL = Symbol(
5478
5342
  "mark-placeholder"
5479
5343
  );
5344
+ function getFirefoxNodeEl(node2, offset) {
5345
+ var _a2;
5346
+ if (node2.nodeType !== 3 || node2.textContent !== "") {
5347
+ return [node2, offset];
5348
+ } else {
5349
+ const isLeft = node2.previousSibling === null;
5350
+ let el = node2[isLeft ? "nextSibling" : "previousSibling"];
5351
+ while (el == null ? void 0 : el.firstChild) {
5352
+ el = isLeft ? el.firstChild : el.lastChild;
5353
+ }
5354
+ return [el || node2, isLeft ? 0 : ((_a2 = el == null ? void 0 : el.textContent) == null ? void 0 : _a2.length) || 0];
5355
+ }
5356
+ }
5480
5357
  const DOMEditor = {
5481
5358
  androidPendingDiffs: (editor) => EDITOR_TO_PENDING_DIFFS.get(editor),
5482
5359
  androidScheduleFlush: (editor) => {
@@ -5516,7 +5393,9 @@ const DOMEditor = {
5516
5393
  }
5517
5394
  const { clientX: x, clientY: y, target } = event;
5518
5395
  if (x == null || y == null) {
5519
- throw new Error(`Cannot resolve a Slate range from a DOM event: ${event}`);
5396
+ throw new Error(
5397
+ `Cannot resolve a Slate range from a DOM event: ${event}`
5398
+ );
5520
5399
  }
5521
5400
  const node2 = DOMEditor.toSlateNode(editor, event.target);
5522
5401
  const path2 = DOMEditor.findPath(editor, node2);
@@ -5545,7 +5424,9 @@ const DOMEditor = {
5545
5424
  }
5546
5425
  }
5547
5426
  if (!domRange) {
5548
- throw new Error(`Cannot resolve a Slate range from a DOM event: ${event}`);
5427
+ throw new Error(
5428
+ `Cannot resolve a Slate range from a DOM event: ${event}`
5429
+ );
5549
5430
  }
5550
5431
  const range2 = DOMEditor.toSlateRange(editor, domRange, {
5551
5432
  exactMatch: false,
@@ -5881,7 +5762,7 @@ const DOMEditor = {
5881
5762
  return { path: path2, offset };
5882
5763
  },
5883
5764
  toSlateRange: (editor, domRange, options) => {
5884
- var _a2, _b2, _c;
5765
+ var _a2;
5885
5766
  const { exactMatch, suppressThrow } = options;
5886
5767
  const el = isDOMSelection(domRange) ? domRange.anchorNode : domRange.startContainer;
5887
5768
  let anchorNode;
@@ -5891,59 +5772,13 @@ const DOMEditor = {
5891
5772
  let isCollapsed;
5892
5773
  if (el) {
5893
5774
  if (isDOMSelection(domRange)) {
5894
- if (IS_FIREFOX && domRange.rangeCount > 1) {
5895
- focusNode = domRange.focusNode;
5896
- const firstRange = domRange.getRangeAt(0);
5897
- const lastRange = domRange.getRangeAt(domRange.rangeCount - 1);
5898
- if (focusNode instanceof HTMLTableRowElement && firstRange.startContainer instanceof HTMLTableRowElement && lastRange.startContainer instanceof HTMLTableRowElement) {
5899
- let getLastChildren = function(element) {
5900
- if (element.childElementCount > 0) {
5901
- return getLastChildren(element.children[0]);
5902
- } else {
5903
- return element;
5904
- }
5905
- };
5906
- const firstNodeRow = firstRange.startContainer;
5907
- const lastNodeRow = lastRange.startContainer;
5908
- const firstNode = getLastChildren(
5909
- firstNodeRow.children[firstRange.startOffset]
5910
- );
5911
- const lastNode = getLastChildren(
5912
- lastNodeRow.children[lastRange.startOffset]
5913
- );
5914
- focusOffset = 0;
5915
- if (lastNode.childNodes.length > 0) {
5916
- anchorNode = lastNode.childNodes[0];
5917
- } else {
5918
- anchorNode = lastNode;
5919
- }
5920
- if (firstNode.childNodes.length > 0) {
5921
- focusNode = firstNode.childNodes[0];
5922
- } else {
5923
- focusNode = firstNode;
5924
- }
5925
- if (lastNode instanceof HTMLElement) {
5926
- anchorOffset = lastNode.innerHTML.length;
5927
- } else {
5928
- anchorOffset = 0;
5929
- }
5930
- } else {
5931
- if (firstRange.startContainer === focusNode) {
5932
- anchorNode = lastRange.endContainer;
5933
- anchorOffset = lastRange.endOffset;
5934
- focusOffset = firstRange.startOffset;
5935
- } else {
5936
- anchorNode = firstRange.startContainer;
5937
- anchorOffset = firstRange.endOffset;
5938
- focusOffset = lastRange.startOffset;
5939
- }
5940
- }
5941
- } else {
5942
- anchorNode = domRange.anchorNode;
5943
- anchorOffset = domRange.anchorOffset;
5944
- focusNode = domRange.focusNode;
5945
- focusOffset = domRange.focusOffset;
5946
- if (IS_FIREFOX && ((_a2 = domRange.anchorNode) == null ? void 0 : _a2.role) === "textbox" && ((_b2 = domRange.focusNode) == null ? void 0 : _b2.role) === "textbox") {
5775
+ anchorNode = domRange.anchorNode;
5776
+ anchorOffset = domRange.anchorOffset;
5777
+ focusNode = domRange.focusNode;
5778
+ focusOffset = domRange.focusOffset;
5779
+ if (IS_FIREFOX) {
5780
+ const attributes = anchorNode instanceof HTMLElement ? anchorNode.attributes : null;
5781
+ if (attributes && attributes.getNamedItem("data-slate-editor")) {
5947
5782
  while (anchorNode == null ? void 0 : anchorNode.firstElementChild) {
5948
5783
  anchorNode = anchorNode.firstElementChild;
5949
5784
  }
@@ -5951,10 +5786,25 @@ const DOMEditor = {
5951
5786
  focusNode = focusNode.lastElementChild;
5952
5787
  }
5953
5788
  anchorNode = anchorNode.firstChild;
5789
+ anchorOffset = 0;
5954
5790
  focusNode = focusNode.lastChild;
5955
5791
  focusOffset = focusNode.length;
5792
+ } else {
5793
+ if (anchorNode) {
5794
+ const [el2, offset] = getFirefoxNodeEl(anchorNode, anchorOffset);
5795
+ anchorNode = el2;
5796
+ anchorOffset = offset;
5797
+ }
5798
+ if (focusNode) {
5799
+ const [el2, offset] = getFirefoxNodeEl(focusNode, focusOffset);
5800
+ focusNode = el2;
5801
+ focusOffset = offset;
5802
+ }
5956
5803
  }
5957
5804
  }
5805
+ if (!anchorNode || !focusNode) {
5806
+ return null;
5807
+ }
5958
5808
  if (IS_CHROME && hasShadowRoot(anchorNode) || IS_FIREFOX) {
5959
5809
  isCollapsed = domRange.anchorNode === domRange.focusNode && domRange.anchorOffset === domRange.focusOffset;
5960
5810
  } else {
@@ -5966,6 +5816,18 @@ const DOMEditor = {
5966
5816
  focusNode = domRange.endContainer;
5967
5817
  focusOffset = domRange.endOffset;
5968
5818
  isCollapsed = domRange.collapsed;
5819
+ if (IS_FIREFOX) {
5820
+ if (anchorNode) {
5821
+ const [el2, offset] = getFirefoxNodeEl(anchorNode, anchorOffset);
5822
+ anchorNode = el2;
5823
+ anchorOffset = offset;
5824
+ }
5825
+ if (focusNode) {
5826
+ const [el2, offset] = getFirefoxNodeEl(focusNode, focusOffset);
5827
+ focusNode = el2;
5828
+ focusOffset = offset;
5829
+ }
5830
+ }
5969
5831
  }
5970
5832
  }
5971
5833
  if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
@@ -5973,7 +5835,7 @@ const DOMEditor = {
5973
5835
  `Cannot resolve a Slate range from DOM range: ${domRange}`
5974
5836
  );
5975
5837
  }
5976
- if (IS_FIREFOX && ((_c = focusNode.textContent) == null ? void 0 : _c.endsWith("\n\n")) && focusOffset === focusNode.textContent.length) {
5838
+ if (IS_FIREFOX && ((_a2 = focusNode.textContent) == null ? void 0 : _a2.endsWith("\n\n")) && focusOffset === focusNode.textContent.length) {
5977
5839
  focusOffset--;
5978
5840
  }
5979
5841
  const anchor = DOMEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {
@@ -6963,7 +6825,6 @@ const debug = (..._) => {
6963
6825
  const isDataTransfer = (value) => (value == null ? void 0 : value.constructor.name) === "DataTransfer";
6964
6826
  function createAndroidInputManager({
6965
6827
  editor,
6966
- scheduleOnDOMSelectionChange,
6967
6828
  onDOMSelectionChange
6968
6829
  }) {
6969
6830
  let flushing = false;
@@ -7001,7 +6862,7 @@ function createAndroidInputManager({
7001
6862
  }
7002
6863
  action.run();
7003
6864
  };
7004
- const flush = () => {
6865
+ const flush = async () => {
7005
6866
  var _a2, _b2;
7006
6867
  if (flushTimeoutId) {
7007
6868
  clearTimeout(flushTimeoutId);
@@ -7029,7 +6890,7 @@ function createAndroidInputManager({
7029
6890
  EDITOR_TO_PENDING_ACTION.get(editor),
7030
6891
  EDITOR_TO_PENDING_DIFFS.get(editor)
7031
6892
  );
7032
- let scheduleSelectionChange = hasPendingDiffs();
6893
+ hasPendingDiffs();
7033
6894
  let diff;
7034
6895
  while (diff = (_a2 = EDITOR_TO_PENDING_DIFFS.get(editor)) == null ? void 0 : _a2[0]) {
7035
6896
  const pendingMarks = EDITOR_TO_PENDING_INSERTION_MARKS.get(editor);
@@ -7056,13 +6917,10 @@ function createAndroidInputManager({
7056
6917
  )
7057
6918
  );
7058
6919
  if (!verifyDiffState(editor, diff)) {
7059
- scheduleSelectionChange = false;
7060
6920
  EDITOR_TO_PENDING_ACTION.delete(editor);
7061
6921
  EDITOR_TO_USER_MARKS.delete(editor);
7062
6922
  flushing = "action";
7063
6923
  EDITOR_TO_PENDING_SELECTION.delete(editor);
7064
- scheduleOnDOMSelectionChange.cancel();
7065
- onDOMSelectionChange.cancel();
7066
6924
  selectionRef == null ? void 0 : selectionRef.unref();
7067
6925
  }
7068
6926
  }
@@ -7074,11 +6932,7 @@ function createAndroidInputManager({
7074
6932
  performAction();
7075
6933
  return;
7076
6934
  }
7077
- if (scheduleSelectionChange) {
7078
- scheduleOnDOMSelectionChange();
7079
- }
7080
- scheduleOnDOMSelectionChange.flush();
7081
- onDOMSelectionChange.flush();
6935
+ await onDOMSelectionChange();
7082
6936
  applyPendingSelection();
7083
6937
  const userMarks = EDITOR_TO_USER_MARKS.get(editor);
7084
6938
  EDITOR_TO_USER_MARKS.delete(editor);
@@ -7140,18 +6994,16 @@ function createAndroidInputManager({
7140
6994
  diff: merged
7141
6995
  };
7142
6996
  };
7143
- const scheduleAction = (run, { at } = {}) => {
6997
+ const scheduleAction = async (run, { at } = {}) => {
7144
6998
  insertPositionHint = false;
7145
6999
  EDITOR_TO_PENDING_SELECTION.delete(editor);
7146
- scheduleOnDOMSelectionChange.cancel();
7147
- onDOMSelectionChange.cancel();
7148
7000
  if (hasPendingAction()) {
7149
- flush();
7001
+ await flush();
7150
7002
  }
7151
7003
  EDITOR_TO_PENDING_ACTION.set(editor, { at, run });
7152
7004
  actionTimeoutId = setTimeout(flush);
7153
7005
  };
7154
- const handleDOMBeforeInput = (event) => {
7006
+ const handleDOMBeforeInput = async (event) => {
7155
7007
  if (flushTimeoutId) {
7156
7008
  clearTimeout(flushTimeoutId);
7157
7009
  flushTimeoutId = null;
@@ -8173,33 +8025,31 @@ const Editable = defineComponent({
8173
8025
  );
8174
8026
  const state = reactive({
8175
8027
  isDraggingInternally: false,
8176
- isUpdatingSelection: false,
8177
8028
  latestElement: null
8178
8029
  });
8179
8030
  const placeholderHeight = ref();
8180
8031
  const onPlaceholderResize = (h2) => placeholderHeight.value = h2;
8181
8032
  const androidInputManagerRef = ref(null);
8182
- const processing = ref(false);
8183
- const onDOMSelectionChange = throttle(() => {
8184
- if (IS_NODE_MAP_DIRTY.get(editor)) {
8185
- onDOMSelectionChange();
8033
+ const onDOMSelectionChange = (event) => {
8034
+ const target = event == null ? void 0 : event.target;
8035
+ const targetElement = target instanceof HTMLElement ? target : null;
8036
+ const targetTagName = targetElement == null ? void 0 : targetElement.tagName;
8037
+ if (targetTagName === "INPUT" || targetTagName === "TEXTAREA") {
8186
8038
  return;
8187
8039
  }
8188
8040
  const el = DOMEditor.toDOMNode(editor, editor);
8189
8041
  const root2 = el.getRootNode();
8190
- if (!processing.value && IS_WEBKIT && root2 instanceof ShadowRoot) {
8191
- processing.value = true;
8042
+ if (IS_WEBKIT && root2 instanceof ShadowRoot) {
8192
8043
  const active = getActiveElement();
8193
8044
  if (active) {
8194
8045
  document.execCommand("indent");
8195
8046
  } else {
8196
8047
  Transforms.deselect(editor);
8197
8048
  }
8198
- processing.value = false;
8199
8049
  return;
8200
8050
  }
8201
8051
  const androidInputManager = androidInputManagerRef.value;
8202
- if ((IS_ANDROID || !DOMEditor.isComposing(editor)) && (!state.isUpdatingSelection || (androidInputManager == null ? void 0 : androidInputManager.isFlushing())) && !state.isDraggingInternally) {
8052
+ if ((IS_ANDROID || !DOMEditor.isComposing(editor)) && !state.isDraggingInternally) {
8203
8053
  const root22 = DOMEditor.findDocumentOrShadowRoot(editor);
8204
8054
  const { activeElement } = root22;
8205
8055
  const el2 = DOMEditor.toDOMNode(editor, editor);
@@ -8233,15 +8083,12 @@ const Editable = defineComponent({
8233
8083
  Transforms.deselect(editor);
8234
8084
  }
8235
8085
  }
8236
- }, 100);
8237
- const scheduleOnDOMSelectionChange = debounce(onDOMSelectionChange, 0);
8086
+ };
8238
8087
  const editableRef = ref();
8239
8088
  androidInputManagerRef.value = useAndroidInputManager({
8240
8089
  node: editableRef,
8241
- onDOMSelectionChange,
8242
- scheduleOnDOMSelectionChange
8090
+ onDOMSelectionChange
8243
8091
  });
8244
- const timeoutId = ref();
8245
8092
  const { onUserInput } = useRestoreDOM(editableRef, editor);
8246
8093
  onMounted(() => {
8247
8094
  let window2;
@@ -8253,8 +8100,6 @@ const Editable = defineComponent({
8253
8100
  }
8254
8101
  });
8255
8102
  onUnmounted(() => {
8256
- onDOMSelectionChange.cancel();
8257
- scheduleOnDOMSelectionChange.cancel();
8258
8103
  EDITOR_TO_ELEMENT.delete(editor);
8259
8104
  NODE_TO_ELEMENT.delete(editor);
8260
8105
  });
@@ -8269,7 +8114,7 @@ const Editable = defineComponent({
8269
8114
  return false;
8270
8115
  }
8271
8116
  });
8272
- const setDomSelection = (forceChange) => {
8117
+ const setDomSelection = () => {
8273
8118
  var _a2;
8274
8119
  const root2 = DOMEditor.findDocumentOrShadowRoot(editor);
8275
8120
  const domSelection = getSelection(root2);
@@ -8298,7 +8143,7 @@ const Editable = defineComponent({
8298
8143
  if (editorElement.contains(anchorNode) && editorElement.contains(focusNode)) {
8299
8144
  hasDomSelectionInEditor = true;
8300
8145
  }
8301
- if (hasDomSelection && hasDomSelectionInEditor && editor.selection && !forceChange) {
8146
+ if (hasDomSelection && hasDomSelectionInEditor && editor.selection) {
8302
8147
  const slateRange = DOMEditor.toSlateRange(editor, domSelection, {
8303
8148
  exactMatch: true,
8304
8149
  // domSelection is not necessarily a valid Slate range
@@ -8323,7 +8168,6 @@ const Editable = defineComponent({
8323
8168
  });
8324
8169
  return;
8325
8170
  }
8326
- state.isUpdatingSelection = true;
8327
8171
  let newDomRange = null;
8328
8172
  try {
8329
8173
  newDomRange = editor.selection && DOMEditor.toDOMRange(editor, editor.selection);
@@ -8353,16 +8197,7 @@ const Editable = defineComponent({
8353
8197
  }
8354
8198
  return newDomRange;
8355
8199
  };
8356
- const ensureDomSelection = (forceChange) => {
8357
- try {
8358
- const el = DOMEditor.toDOMNode(editor, editor);
8359
- el.focus();
8360
- setDomSelection(forceChange);
8361
- } catch (e2) {
8362
- }
8363
- };
8364
- const animationFrameId = ref();
8365
- const changeEffect = () => {
8200
+ useChangeEffect(() => {
8366
8201
  var _a2, _b2;
8367
8202
  const root2 = DOMEditor.findDocumentOrShadowRoot(editor);
8368
8203
  const domSelection = getSelection(root2);
@@ -8374,35 +8209,13 @@ const Editable = defineComponent({
8374
8209
  }
8375
8210
  const ensureSelection = ((_b2 = androidInputManagerRef.value) == null ? void 0 : _b2.isFlushing()) === "action";
8376
8211
  if (!IS_ANDROID || !ensureSelection) {
8377
- setTimeout(() => {
8378
- state.isUpdatingSelection = false;
8379
- });
8380
8212
  return;
8381
8213
  }
8382
- animationFrameId.value = requestAnimationFrame(() => {
8383
- if (ensureSelection) {
8384
- ensureDomSelection();
8385
- timeoutId.value = setTimeout(() => {
8386
- ensureDomSelection(true);
8387
- state.isUpdatingSelection = false;
8388
- });
8389
- }
8390
- });
8391
- };
8392
- useChangeEffect(changeEffect);
8393
- onUnmounted(() => {
8394
- animationFrameId.value && cancelAnimationFrame(animationFrameId.value);
8395
- if (timeoutId) {
8396
- clearTimeout(timeoutId.value);
8397
- }
8398
8214
  });
8399
8215
  const stoppedDragging = () => state.isDraggingInternally = false;
8400
8216
  onMounted(() => {
8401
8217
  const window2 = DOMEditor.getWindow(editor);
8402
- window2.document.addEventListener(
8403
- "selectionchange",
8404
- scheduleOnDOMSelectionChange
8405
- );
8218
+ window2.document.addEventListener("selectionchange", onDOMSelectionChange);
8406
8219
  window2.document.addEventListener("dragend", stoppedDragging);
8407
8220
  window2.document.addEventListener("drop", stoppedDragging);
8408
8221
  });
@@ -8410,7 +8223,7 @@ const Editable = defineComponent({
8410
8223
  const window2 = DOMEditor.getWindow(editor);
8411
8224
  window2.document.removeEventListener(
8412
8225
  "selectionchange",
8413
- scheduleOnDOMSelectionChange
8226
+ onDOMSelectionChange
8414
8227
  );
8415
8228
  window2.document.removeEventListener("dragend", stoppedDragging);
8416
8229
  window2.document.removeEventListener("drop", stoppedDragging);
@@ -8424,7 +8237,7 @@ const Editable = defineComponent({
8424
8237
  if (HAS_BEFORE_INPUT_SUPPORT) {
8425
8238
  const el = DOMEditor.toDOMNode(editor, editor);
8426
8239
  const root2 = el.getRootNode();
8427
- if ((processing == null ? void 0 : processing.value) && IS_WEBKIT && root2 instanceof ShadowRoot) {
8240
+ if (IS_WEBKIT && root2 instanceof ShadowRoot) {
8428
8241
  const ranges = event.getTargetRanges();
8429
8242
  const range2 = ranges[0];
8430
8243
  const newRange = new window.Range();
@@ -8444,8 +8257,6 @@ const Editable = defineComponent({
8444
8257
  if (androidInputManagerRef.value) {
8445
8258
  return androidInputManagerRef.value.handleDOMBeforeInput(event);
8446
8259
  }
8447
- scheduleOnDOMSelectionChange.flush();
8448
- onDOMSelectionChange.flush();
8449
8260
  const { selection } = editor;
8450
8261
  const { inputType } = event;
8451
8262
  const data = event.dataTransfer || event.data || void 0;
@@ -8632,7 +8443,7 @@ const Editable = defineComponent({
8632
8443
  }
8633
8444
  };
8634
8445
  const onBlur = (event) => {
8635
- if (readOnly || state.isUpdatingSelection || !DOMEditor.hasSelectableTarget(editor, event.target) || isEventHandled(event, attributes.onBlur)) {
8446
+ if (readOnly || !DOMEditor.hasSelectableTarget(editor, event.target) || isEventHandled(event, attributes.onBlur)) {
8636
8447
  return;
8637
8448
  }
8638
8449
  const root2 = DOMEditor.findDocumentOrShadowRoot(editor);
@@ -8814,7 +8625,7 @@ const Editable = defineComponent({
8814
8625
  }
8815
8626
  };
8816
8627
  const onFocus = (event) => {
8817
- if (!readOnly && !state.isUpdatingSelection && DOMEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
8628
+ if (!readOnly && DOMEditor.hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
8818
8629
  const el = DOMEditor.toDOMNode(editor, editor);
8819
8630
  const root2 = DOMEditor.findDocumentOrShadowRoot(editor);
8820
8631
  state.latestElement = root2.activeElement;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "description": "slate-react library implemented with vue3",
9
+ "license": "MIT",
9
10
  "files": [
10
11
  "dist/"
11
12
  ],
@@ -43,7 +44,7 @@
43
44
  "prismjs": "^1.29.0",
44
45
  "slate-hyperscript": "^0.100.0",
45
46
  "typescript": "~5.7.2",
46
- "vite": "^6.1.0",
47
+ "vite": "^6.2.0",
47
48
  "vite-plugin-dts": "^4.5.0",
48
49
  "vitest": "^3.0.5",
49
50
  "vue-router": "^4.5.0"
@@ -62,6 +63,6 @@
62
63
  ],
63
64
  "repository": {
64
65
  "type": "git",
65
- "url": "https://github.com/Guan-Erjia/slate-vue3"
66
+ "url": "git+https://github.com/Guan-Erjia/slate-vue3.git"
66
67
  }
67
68
  }