@lvce-editor/editor-worker 11.1.0 → 12.0.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 {
@@ -8492,6 +8503,9 @@ const createFn = (key, name, widgetId) => {
8492
8503
  };
8493
8504
  const fn = async (editor, ...args) => {
8494
8505
  const childIndex = editor.widgets.findIndex(isWidget);
8506
+ if (childIndex === -1) {
8507
+ return editor;
8508
+ }
8495
8509
  // TODO scroll up/down if necessary
8496
8510
  const childWidget = editor.widgets[childIndex];
8497
8511
  const state = childWidget.newState;
@@ -10334,13 +10348,13 @@ const renderFocusContext = {
10334
10348
  };
10335
10349
  const renderAdditionalFocusContext = {
10336
10350
  isEqual(oldState, newState) {
10337
- return newState.additionalFocus === newState.additionalFocus;
10351
+ return oldState.additionalFocus === newState.additionalFocus;
10338
10352
  },
10339
10353
  apply(oldState, newState) {
10340
10354
  if (newState.additionalFocus) {
10341
- return ['Focus.setAdditionalFocus', newState.uid, newState.additionalFocus];
10355
+ return ['Viewlet.setAdditionalFocus', newState.uid, newState.additionalFocus];
10342
10356
  }
10343
- return ['Focus.unsetAdditionalFocus', newState.uid, newState.additionalFocus];
10357
+ return ['viewlet.unsetAdditionalFocus', newState.uid, newState.additionalFocus];
10344
10358
  }
10345
10359
  };
10346
10360
  const renderDecorations = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "11.1.0",
3
+ "version": "12.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Lvce Editor",
6
6
  "type": "module",