@lvce-editor/editor-worker 11.0.0 → 11.2.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.
@@ -1742,77 +1742,6 @@ const clamp = (num, min, max) => {
1742
1742
  return Math.min(Math.max(num, min), max);
1743
1743
  };
1744
1744
 
1745
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1746
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1747
- return scrollBarOffset;
1748
- };
1749
- const getScrollBarY = getScrollBarOffset;
1750
-
1751
- const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1752
- if (size >= contentSize) {
1753
- return 0;
1754
- }
1755
- return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
1756
- };
1757
-
1758
- const getScrollBarWidth = (width, longestLineWidth) => {
1759
- if (width > longestLineWidth) {
1760
- return 0;
1761
- }
1762
- return width ** 2 / longestLineWidth;
1763
- };
1764
-
1765
- const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
1766
- const halfScrollBarHeight = scrollBarHeight / 2;
1767
- if (relativeY <= halfScrollBarHeight) {
1768
- // clicked at top
1769
- return {
1770
- percent: 0,
1771
- handleOffset: relativeY
1772
- };
1773
- }
1774
- if (relativeY <= height - halfScrollBarHeight) {
1775
- // clicked in middle
1776
- return {
1777
- percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
1778
- handleOffset: halfScrollBarHeight
1779
- };
1780
- }
1781
- // clicked at bottom
1782
- return {
1783
- percent: 1,
1784
- handleOffset: scrollBarHeight - height + relativeY
1785
- };
1786
- };
1787
-
1788
- // TODO this should be in a separate scrolling module
1789
- const setDeltaY$2 = (state, value) => {
1790
- object(state);
1791
- number(value);
1792
- const {
1793
- finalDeltaY,
1794
- deltaY,
1795
- numberOfVisibleLines,
1796
- height,
1797
- scrollBarHeight,
1798
- itemHeight
1799
- } = state;
1800
- const newDeltaY = clamp(value, 0, finalDeltaY);
1801
- if (deltaY === newDeltaY) {
1802
- return state;
1803
- }
1804
- const newMinLineY = Math.floor(newDeltaY / itemHeight);
1805
- const newMaxLineY = newMinLineY + numberOfVisibleLines;
1806
- const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height, scrollBarHeight);
1807
- return {
1808
- ...state,
1809
- minLineY: newMinLineY,
1810
- maxLineY: newMaxLineY,
1811
- deltaY: newDeltaY,
1812
- scrollBarY
1813
- };
1814
- };
1815
-
1816
1745
  const Link$1 = 'Link';
1817
1746
  const Function = 'Function';
1818
1747
  const Parameter = 'Parameter';
@@ -2669,6 +2598,96 @@ const getVisible$1 = async (editor, syncIncremental) => {
2669
2598
  };
2670
2599
  };
2671
2600
 
2601
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
2602
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
2603
+ return scrollBarOffset;
2604
+ };
2605
+ const getScrollBarY = getScrollBarOffset;
2606
+
2607
+ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
2608
+ if (size >= contentSize) {
2609
+ return 0;
2610
+ }
2611
+ return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
2612
+ };
2613
+
2614
+ const getScrollBarWidth = (width, longestLineWidth) => {
2615
+ if (width > longestLineWidth) {
2616
+ return 0;
2617
+ }
2618
+ return width ** 2 / longestLineWidth;
2619
+ };
2620
+
2621
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
2622
+ const halfScrollBarHeight = scrollBarHeight / 2;
2623
+ if (relativeY <= halfScrollBarHeight) {
2624
+ // clicked at top
2625
+ return {
2626
+ percent: 0,
2627
+ handleOffset: relativeY
2628
+ };
2629
+ }
2630
+ if (relativeY <= height - halfScrollBarHeight) {
2631
+ // clicked in middle
2632
+ return {
2633
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
2634
+ handleOffset: halfScrollBarHeight
2635
+ };
2636
+ }
2637
+ // clicked at bottom
2638
+ return {
2639
+ percent: 1,
2640
+ handleOffset: scrollBarHeight - height + relativeY
2641
+ };
2642
+ };
2643
+
2644
+ let enabled = false;
2645
+ const setEnabled = value => {
2646
+ enabled = value;
2647
+ };
2648
+ const getEnabled = () => {
2649
+ return enabled;
2650
+ };
2651
+
2652
+ // TODO this should be in a separate scrolling module
2653
+ const setDeltaY$2 = async (state, value) => {
2654
+ object(state);
2655
+ number(value);
2656
+ const {
2657
+ finalDeltaY,
2658
+ deltaY,
2659
+ numberOfVisibleLines,
2660
+ height,
2661
+ scrollBarHeight,
2662
+ itemHeight
2663
+ } = state;
2664
+ const newDeltaY = clamp(value, 0, finalDeltaY);
2665
+ if (deltaY === newDeltaY) {
2666
+ return state;
2667
+ }
2668
+ const newMinLineY = Math.floor(newDeltaY / itemHeight);
2669
+ const newMaxLineY = newMinLineY + numberOfVisibleLines;
2670
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height, scrollBarHeight);
2671
+ const newEditor1 = {
2672
+ ...state,
2673
+ minLineY: newMinLineY,
2674
+ maxLineY: newMaxLineY,
2675
+ deltaY: newDeltaY,
2676
+ scrollBarY
2677
+ };
2678
+ const syncIncremental = getEnabled();
2679
+ const {
2680
+ textInfos,
2681
+ differences
2682
+ } = await getVisible$1(newEditor1, syncIncremental);
2683
+ const newEditor2 = {
2684
+ ...newEditor1,
2685
+ textInfos,
2686
+ differences
2687
+ };
2688
+ return newEditor2;
2689
+ };
2690
+
2672
2691
  const emptyIncrementalEdits = [];
2673
2692
 
2674
2693
  const getIncrementalEdits = async (oldState, newState) => {
@@ -2711,14 +2730,6 @@ const splitLines = lines => {
2711
2730
  return lines.split('\n');
2712
2731
  };
2713
2732
 
2714
- let enabled = false;
2715
- const setEnabled = value => {
2716
- enabled = value;
2717
- };
2718
- const getEnabled = () => {
2719
- return enabled;
2720
- };
2721
-
2722
2733
  const getSelectionPairs = (selections, i) => {
2723
2734
  const first = selections[i];
2724
2735
  const second = selections[i + 1];
@@ -3589,9 +3600,9 @@ const createEditor = async ({
3589
3600
  if (lineToReveal && columnToReveal) {
3590
3601
  const delta = lineToReveal * rowHeight;
3591
3602
  // TODO scroll to this line
3592
- newEditor3 = setDeltaY$2(newEditor2, delta);
3603
+ newEditor3 = await setDeltaY$2(newEditor2, delta);
3593
3604
  } else {
3594
- newEditor3 = setDeltaY$2(newEditor2, 0);
3605
+ newEditor3 = await setDeltaY$2(newEditor2, 0);
3595
3606
  }
3596
3607
  const syncIncremental = getEnabled();
3597
3608
  const {
@@ -3601,6 +3612,7 @@ const createEditor = async ({
3601
3612
  const newEditor4 = {
3602
3613
  ...newEditor3,
3603
3614
  focused: true,
3615
+ focus: FocusEditorText$1,
3604
3616
  textInfos,
3605
3617
  differences
3606
3618
  };
@@ -4906,7 +4918,7 @@ const getChanges$4 = (editor, getDelta) => {
4906
4918
  } = editor;
4907
4919
  for (let i = 0; i < selections.length; i += 4) {
4908
4920
  // @ts-ignore
4909
- const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
4921
+ const [selectionStartRow, selectionStartColumn] = getSelectionPairs(selections, i);
4910
4922
  const start = {
4911
4923
  rowIndex: selectionStartRow,
4912
4924
  columnIndex: selectionStartColumn
@@ -6852,7 +6864,7 @@ const getNewSelections$4 = (selections, lines, getDelta) => {
6852
6864
  const newSelections = clone(selections);
6853
6865
  for (let i = 0; i < selections.length; i += 4) {
6854
6866
  // @ts-ignore
6855
- const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn, reversed] = getSelectionPairs(selections, i);
6867
+ const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
6856
6868
  if (selectionStartRow === selectionEndRow && selectionStartColumn === selectionEndColumn) {
6857
6869
  moveToPositionLeft(newSelections, i + 2, selectionStartRow, selectionStartColumn, lines, getDelta);
6858
6870
  moveToPositionEqual(newSelections, i, selectionEndRow, selectionEndColumn);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "11.0.0",
3
+ "version": "11.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Lvce Editor",
6
6
  "type": "module",
7
7
  "main": "dist/editorWorkerMain.js",
8
8
  "dependencies": {
9
- "@lvce-editor/constants": "^1.23.0"
9
+ "@lvce-editor/constants": "^1.24.0"
10
10
  }
11
11
  }