@lvce-editor/output-view 2.23.0 → 2.23.1

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.
@@ -1442,6 +1442,10 @@ const Error$1 = 'Error';
1442
1442
  const Line = 'Line';
1443
1443
  const OutputRepeatCount = 'OutputRepeatCount';
1444
1444
  const OutputSourceLink = 'OutputSourceLink';
1445
+ const ScrollBar = 'ScrollBar';
1446
+ const ScrollBarSmall = 'ScrollBarSmall';
1447
+ const ScrollBarThumb = 'ScrollBarThumb';
1448
+ const ScrollBarThumbActive = 'ScrollBarThumbActive';
1445
1449
 
1446
1450
  const RE_URL = /(?:https?:\/\/|file:\/\/|lvce(?:-oss)?:\/\/)\S+/;
1447
1451
  const trailingPunctuation = '!),.;?]}';
@@ -1659,14 +1663,18 @@ const create = (id, uri, x, y, width, height, platform, parentId) => {
1659
1663
  const state = {
1660
1664
  buttons: [],
1661
1665
  collapsedUris: [],
1666
+ deltaY: 0,
1662
1667
  error: '',
1663
1668
  errorCode: 0,
1664
1669
  filteredItems: [],
1665
1670
  filterValue: '',
1671
+ finalDeltaY: 0,
1666
1672
  focusedIndex: -2,
1673
+ followOutput: true,
1674
+ handleOffset: 0,
1667
1675
  height,
1668
1676
  inputSource: User,
1669
- itemHeight: 22,
1677
+ itemHeight: 18,
1670
1678
  listItems: [],
1671
1679
  logLevel: 0,
1672
1680
  maxLineY: 0,
@@ -1675,6 +1683,8 @@ const create = (id, uri, x, y, width, height, platform, parentId) => {
1675
1683
  options: [],
1676
1684
  parentId,
1677
1685
  platform,
1686
+ scrollBarActive: false,
1687
+ scrollBarHeight: 0,
1678
1688
  scrollLockEnabled: false,
1679
1689
  selectedOption: '',
1680
1690
  smallWidthBreakPoint: 650,
@@ -1694,19 +1704,20 @@ const isEqual$2 = (oldState, newState) => {
1694
1704
  };
1695
1705
 
1696
1706
  const isEqual$1 = (oldState, newState) => {
1697
- return oldState.selectedOption === newState.selectedOption && oldState.listItems === newState.listItems && oldState.filteredItems === newState.filteredItems;
1707
+ return oldState.deltaY === newState.deltaY && oldState.height === newState.height && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.scrollBarActive === newState.scrollBarActive && oldState.error === newState.error && oldState.errorCode === newState.errorCode && oldState.selectedOption === newState.selectedOption && oldState.listItems === newState.listItems && oldState.filteredItems === newState.filteredItems;
1698
1708
  };
1699
1709
 
1700
1710
  const isEqual = (oldState, newState) => {
1701
1711
  return oldState.selectedOption === newState.selectedOption;
1702
1712
  };
1703
1713
 
1714
+ const RenderCss = 4;
1704
1715
  const RenderItems = 1;
1705
1716
  const RenderFilterValue = 2;
1706
1717
  const RenderSelectedItem = 3;
1707
1718
 
1708
- const modules = [isEqual$1, isEqual$2, isEqual];
1709
- const numbers = [RenderItems, RenderFilterValue, RenderSelectedItem];
1719
+ const modules = [isEqual$1, isEqual$1, isEqual$2, isEqual];
1720
+ const numbers = [RenderCss, RenderItems, RenderFilterValue, RenderSelectedItem];
1710
1721
 
1711
1722
  const diff = (oldState, newState) => {
1712
1723
  const diffResult = [];
@@ -1719,12 +1730,46 @@ const diff = (oldState, newState) => {
1719
1730
  return diffResult;
1720
1731
  };
1721
1732
 
1733
+ const updateVirtualList = (state, requestedDeltaY) => {
1734
+ const {
1735
+ deltaY: currentDeltaY,
1736
+ filteredItems,
1737
+ followOutput,
1738
+ height,
1739
+ itemHeight,
1740
+ scrollLockEnabled
1741
+ } = state;
1742
+ const listHeight = Math.max(0, height);
1743
+ const contentHeight = filteredItems.length * itemHeight;
1744
+ const finalDeltaY = Math.max(0, contentHeight - listHeight);
1745
+ const requested = requestedDeltaY ?? (followOutput && !scrollLockEnabled ? finalDeltaY : currentDeltaY);
1746
+ const deltaY = Math.max(0, Math.min(Number.isFinite(requested) ? requested : 0, finalDeltaY));
1747
+ const minLineY = itemHeight > 0 ? Math.floor(deltaY / itemHeight) : 0;
1748
+ const maxLineY = itemHeight > 0 && listHeight > 0 ? Math.min(filteredItems.length, Math.ceil((deltaY + listHeight) / itemHeight)) : minLineY;
1749
+ const scrollBarHeight = finalDeltaY > 0 && listHeight > 0 ? Math.min(listHeight, Math.max(20, listHeight ** 2 / contentHeight)) : 0;
1750
+ return {
1751
+ ...state,
1752
+ deltaY,
1753
+ finalDeltaY,
1754
+ maxLineY,
1755
+ minLineY,
1756
+ scrollBarHeight
1757
+ };
1758
+ };
1759
+
1722
1760
  const diff2 = uid => {
1723
1761
  const {
1724
1762
  newState,
1725
1763
  oldState
1726
1764
  } = get(uid);
1727
- const diffResult = diff(oldState, newState);
1765
+ const reset = oldState.selectedOption !== newState.selectedOption || oldState.filterValue !== newState.filterValue;
1766
+ const updatedState = updateVirtualList(reset ? {
1767
+ ...newState,
1768
+ deltaY: 0,
1769
+ followOutput: true
1770
+ } : newState);
1771
+ set$1(uid, oldState, updatedState);
1772
+ const diffResult = diff(oldState, updatedState);
1728
1773
  return diffResult;
1729
1774
  };
1730
1775
 
@@ -1737,6 +1782,7 @@ const disableScrollLock = async state => {
1737
1782
  }
1738
1783
  return {
1739
1784
  ...state,
1785
+ followOutput: true,
1740
1786
  scrollLockEnabled: false
1741
1787
  };
1742
1788
  };
@@ -1881,6 +1927,39 @@ const handleFilterInput = async (state, value, inputSource = User) => {
1881
1927
  };
1882
1928
  };
1883
1929
 
1930
+ const setDeltaY = (state, deltaY) => {
1931
+ const newState = updateVirtualList(state, deltaY);
1932
+ return {
1933
+ ...newState,
1934
+ followOutput: newState.deltaY === newState.finalDeltaY
1935
+ };
1936
+ };
1937
+
1938
+ const handleKeyDown = (state, key) => {
1939
+ const {
1940
+ deltaY,
1941
+ finalDeltaY,
1942
+ height,
1943
+ itemHeight
1944
+ } = state;
1945
+ switch (key) {
1946
+ case 'ArrowDown':
1947
+ return setDeltaY(state, deltaY + itemHeight);
1948
+ case 'ArrowUp':
1949
+ return setDeltaY(state, deltaY - itemHeight);
1950
+ case 'End':
1951
+ return setDeltaY(state, finalDeltaY);
1952
+ case 'Home':
1953
+ return setDeltaY(state, 0);
1954
+ case 'PageDown':
1955
+ return setDeltaY(state, deltaY + height);
1956
+ case 'PageUp':
1957
+ return setDeltaY(state, deltaY - height);
1958
+ default:
1959
+ return state;
1960
+ }
1961
+ };
1962
+
1884
1963
  const state = {
1885
1964
  connected: false
1886
1965
  };
@@ -1918,6 +1997,69 @@ const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess =
1918
1997
  }
1919
1998
  };
1920
1999
 
2000
+ const handleScrollBarCaptureLost = state => {
2001
+ return {
2002
+ ...state,
2003
+ scrollBarActive: false
2004
+ };
2005
+ };
2006
+
2007
+ const getScrollBarTop = state => {
2008
+ const {
2009
+ deltaY,
2010
+ finalDeltaY,
2011
+ height,
2012
+ scrollBarHeight
2013
+ } = state;
2014
+ return finalDeltaY > 0 ? deltaY / finalDeltaY * (height - scrollBarHeight) : 0;
2015
+ };
2016
+
2017
+ const handleScrollBarClick = (state, eventY) => {
2018
+ const {
2019
+ finalDeltaY,
2020
+ height,
2021
+ scrollBarHeight,
2022
+ y
2023
+ } = state;
2024
+ if (scrollBarHeight <= 0) {
2025
+ return state;
2026
+ }
2027
+ const relativeY = eventY - y;
2028
+ const offset = relativeY - getScrollBarTop(state);
2029
+ if (offset >= 0 && offset < scrollBarHeight) {
2030
+ return {
2031
+ ...state,
2032
+ handleOffset: offset,
2033
+ scrollBarActive: true
2034
+ };
2035
+ }
2036
+ const handleOffset = scrollBarHeight / 2;
2037
+ const trackHeight = height - scrollBarHeight;
2038
+ const deltaY = trackHeight > 0 ? (relativeY - handleOffset) / trackHeight * finalDeltaY : 0;
2039
+ return {
2040
+ ...setDeltaY(state, deltaY),
2041
+ handleOffset,
2042
+ scrollBarActive: true
2043
+ };
2044
+ };
2045
+
2046
+ const handleScrollBarMove = (state, eventY) => {
2047
+ const {
2048
+ finalDeltaY,
2049
+ handleOffset,
2050
+ height,
2051
+ scrollBarActive,
2052
+ scrollBarHeight,
2053
+ y
2054
+ } = state;
2055
+ if (!scrollBarActive) {
2056
+ return state;
2057
+ }
2058
+ const trackHeight = height - scrollBarHeight;
2059
+ const deltaY = trackHeight > 0 ? (eventY - y - handleOffset) / trackHeight * finalDeltaY : 0;
2060
+ return setDeltaY(state, deltaY);
2061
+ };
2062
+
1921
2063
  const createWatchId = () => {
1922
2064
  const watchId = Math.random();
1923
2065
  return watchId;
@@ -2016,6 +2158,21 @@ const handleSourceLinkClick = async (state, uri, lineNumber, columnNumber) => {
2016
2158
  return state;
2017
2159
  };
2018
2160
 
2161
+ const handleWheel = (state, deltaMode, deltaY) => {
2162
+ const {
2163
+ deltaY: currentDeltaY,
2164
+ height,
2165
+ itemHeight
2166
+ } = state;
2167
+ let multiplier = 1;
2168
+ if (deltaMode === 1) {
2169
+ multiplier = itemHeight;
2170
+ } else if (deltaMode === 2) {
2171
+ multiplier = height;
2172
+ }
2173
+ return setDeltaY(state, currentDeltaY + deltaY * multiplier);
2174
+ };
2175
+
2019
2176
  const createExtensionManagementWorkerRpc = async () => {
2020
2177
  const rpc = await create$4({
2021
2178
  commandMap: {},
@@ -2234,6 +2391,7 @@ const getMatchingOpen = (options, id) => {
2234
2391
  const loadContent = async (state, savedState) => {
2235
2392
  const {
2236
2393
  platform,
2394
+ uri: requestedChannel,
2237
2395
  watchId
2238
2396
  } = state;
2239
2397
  const collapsedUris = getSavedCollapsedUris(savedState);
@@ -2242,7 +2400,7 @@ const loadContent = async (state, savedState) => {
2242
2400
  scrollLockEnabled,
2243
2401
  selectedOption
2244
2402
  } = restoreState(savedState);
2245
- const selectedId = getSelectedItem(selectedOption, platform);
2403
+ const selectedId = getSelectedItem(requestedChannel || selectedOption, platform);
2246
2404
  const options = await loadOptions(platform);
2247
2405
  const option = getMatchingOpen(options, selectedId);
2248
2406
  if (!option) {
@@ -2272,7 +2430,7 @@ const loadContent = async (state, savedState) => {
2272
2430
  listItems: lines,
2273
2431
  options,
2274
2432
  scrollLockEnabled,
2275
- selectedOption: selectedId,
2433
+ selectedOption: option.id,
2276
2434
  watchId: newWatchId
2277
2435
  };
2278
2436
  };
@@ -2313,6 +2471,43 @@ const refresh = async state => {
2313
2471
  };
2314
2472
  };
2315
2473
 
2474
+ const renderCss = (oldState, newState) => {
2475
+ const {
2476
+ deltaY,
2477
+ itemHeight,
2478
+ minLineY,
2479
+ scrollBarHeight,
2480
+ uid
2481
+ } = newState;
2482
+ const offset = minLineY * itemHeight - deltaY;
2483
+ const css = `.Output {
2484
+ position: relative;
2485
+ overflow: hidden;
2486
+ }
2487
+ .OutputContent {
2488
+ overflow-x: auto;
2489
+ overflow-y: hidden;
2490
+ scrollbar-width: none;
2491
+ padding-right: ${scrollBarHeight > 0 ? 14 : 0}px;
2492
+ }
2493
+ .OutputContent::-webkit-scrollbar {
2494
+ display: none;
2495
+ }
2496
+ .Output .Line {
2497
+ height: ${itemHeight}px;
2498
+ min-height: ${itemHeight}px;
2499
+ line-height: ${itemHeight}px;
2500
+ }
2501
+ .Output .Line:first-child {
2502
+ margin-top: ${offset}px;
2503
+ }
2504
+ .Output .ScrollBarThumb {
2505
+ height: ${scrollBarHeight}px;
2506
+ translate: 0 ${getScrollBarTop(newState)}px;
2507
+ }`;
2508
+ return ['Viewlet.setCss', uid, css];
2509
+ };
2510
+
2316
2511
  const renderFilterValue = (oldState, newState) => {
2317
2512
  return ['Viewlet.setValueByName', newState.uid, Filter$1, newState.filterValue];
2318
2513
  };
@@ -2325,6 +2520,11 @@ const HandlePointerDown = 'handlePointerDown';
2325
2520
  const HandleSelect = 'handleSelect';
2326
2521
  const HandleButtonClick = 'handleButtonClick';
2327
2522
  const HandleSourceLinkClick = 'handleSourceLinkClick';
2523
+ const HandleWheel = 'handleWheel';
2524
+ const HandleKeyDown = 'handleKeyDown';
2525
+ const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
2526
+ const HandleScrollBarMove = 'handleScrollBarMove';
2527
+ const HandleScrollBarPointerCaptureLost = 'handleScrollBarPointerCaptureLost';
2328
2528
 
2329
2529
  const noNodes = [];
2330
2530
  const repeatCountNode = {
@@ -2409,6 +2609,8 @@ const getContentDom = (lines, error) => {
2409
2609
  return [{
2410
2610
  childCount: lines.length,
2411
2611
  className: OutputContent,
2612
+ onKeyDown: HandleKeyDown,
2613
+ onWheel: HandleWheel,
2412
2614
  role: Log,
2413
2615
  tabIndex: Focusable,
2414
2616
  type: Div
@@ -2443,17 +2645,38 @@ const getErrorDom = (errorCode, error) => {
2443
2645
  return [errorNode, text(error)];
2444
2646
  };
2445
2647
 
2648
+ const scrollBarNode = {
2649
+ childCount: 1,
2650
+ className: mergeClassNames(ScrollBar, ScrollBarSmall),
2651
+ onPointerDown: HandleScrollBarPointerDown,
2652
+ type: Div
2653
+ };
2654
+ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarActive) => {
2655
+ if (scrollBarHeight <= 0) {
2656
+ return [];
2657
+ }
2658
+ return [scrollBarNode, {
2659
+ childCount: 0,
2660
+ className: mergeClassNames(ScrollBarThumb, scrollBarActive ? ScrollBarThumbActive : ''),
2661
+ type: Div
2662
+ }];
2663
+ };
2664
+
2446
2665
  const outputNode = {
2447
2666
  childCount: 1,
2448
2667
  className: mergeClassNames(Viewlet, Output$1),
2449
2668
  type: Div
2450
2669
  };
2451
- const getOutputVirtualDom = (lines, errorCode, error) => {
2452
- return [outputNode, ...getContentDom(lines, error), ...getErrorDom(errorCode, error)];
2670
+ const getOutputVirtualDom = (lines, errorCode, error, scrollBarHeight = 0, scrollBarActive = false) => {
2671
+ const scrollBarDom = error ? [] : getScrollBarVirtualDom(scrollBarHeight, scrollBarActive);
2672
+ return [{
2673
+ ...outputNode,
2674
+ childCount: scrollBarDom.length > 0 ? 2 : 1
2675
+ }, ...getContentDom(lines, error), ...getErrorDom(errorCode, error), ...scrollBarDom];
2453
2676
  };
2454
2677
 
2455
2678
  const renderItems = (oldState, newState) => {
2456
- const dom = getOutputVirtualDom(newState.filteredItems, newState.errorCode, newState.error);
2679
+ const dom = getOutputVirtualDom(newState.filteredItems.slice(newState.minLineY, newState.maxLineY), newState.errorCode, newState.error, newState.scrollBarHeight, newState.scrollBarActive);
2457
2680
  return ['Viewlet.setDom2', newState.uid, dom];
2458
2681
  };
2459
2682
 
@@ -2465,6 +2688,8 @@ const renderSelectedItem = (oldState, newState) => {
2465
2688
 
2466
2689
  const getRenderer = diffType => {
2467
2690
  switch (diffType) {
2691
+ case RenderCss:
2692
+ return renderCss;
2468
2693
  case RenderFilterValue:
2469
2694
  return renderFilterValue;
2470
2695
  case RenderItems:
@@ -2544,7 +2769,7 @@ const getFilterVirtualDom = () => {
2544
2769
  }];
2545
2770
  };
2546
2771
 
2547
- const getOptionVirtualDom = option => {
2772
+ const getOptionVirtualDom = (option, selected = false) => {
2548
2773
  const {
2549
2774
  id,
2550
2775
  label
@@ -2552,19 +2777,20 @@ const getOptionVirtualDom = option => {
2552
2777
  return [{
2553
2778
  childCount: 1,
2554
2779
  className: Option,
2780
+ selected,
2555
2781
  type: Option$1,
2556
2782
  value: id
2557
2783
  }, text(label)];
2558
2784
  };
2559
2785
 
2560
- const getSelectVirtualDom = options => {
2786
+ const getSelectVirtualDom = (options, selectedOption = '') => {
2561
2787
  return [{
2562
2788
  childCount: options.length,
2563
2789
  className: Select,
2564
2790
  name: Output,
2565
2791
  onChange: HandleSelect,
2566
2792
  type: Select$1
2567
- }, ...options.flatMap(getOptionVirtualDom)];
2793
+ }, ...options.flatMap(option => getOptionVirtualDom(option, option.id === selectedOption))];
2568
2794
  };
2569
2795
 
2570
2796
  const getChildCount = buttonsLength => {
@@ -2572,27 +2798,47 @@ const getChildCount = buttonsLength => {
2572
2798
  const filterCount = 1;
2573
2799
  return buttonsLength + filterCount + selectLength;
2574
2800
  };
2575
- const getActionsVirtualDom = (options, buttons) => {
2801
+ const getActionsVirtualDom = (options, buttons, selectedOption = '') => {
2576
2802
  const childCount = getChildCount(buttons.length);
2577
2803
  return [{
2578
2804
  childCount,
2579
2805
  className: Actions,
2580
2806
  role: ToolBar,
2581
2807
  type: Div
2582
- }, ...getFilterVirtualDom(), ...getSelectVirtualDom(options), ...getActionButtonsVirtualDom(buttons)];
2808
+ }, ...getFilterVirtualDom(), ...getSelectVirtualDom(options, selectedOption), ...getActionButtonsVirtualDom(buttons)];
2583
2809
  };
2584
2810
 
2585
2811
  const renderActions = state => {
2586
2812
  const {
2587
2813
  buttons,
2588
- options
2814
+ options,
2815
+ selectedOption
2589
2816
  } = state;
2590
- const dom = getActionsVirtualDom(options, buttons);
2817
+ const dom = getActionsVirtualDom(options, buttons, selectedOption);
2591
2818
  return dom;
2592
2819
  };
2593
2820
 
2594
2821
  const renderEventListeners = () => {
2595
2822
  return [{
2823
+ name: HandleWheel,
2824
+ params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
2825
+ passive: true
2826
+ }, {
2827
+ name: HandleKeyDown,
2828
+ params: ['handleKeyDown', 'event.key']
2829
+ }, {
2830
+ name: HandleScrollBarPointerDown,
2831
+ params: ['handleScrollBarClick', 'event.clientY'],
2832
+ preventDefault: true,
2833
+ stopPropagation: true,
2834
+ trackPointerEvents: [HandleScrollBarMove, HandleScrollBarPointerCaptureLost]
2835
+ }, {
2836
+ name: HandleScrollBarMove,
2837
+ params: ['handleScrollBarMove', 'event.clientY']
2838
+ }, {
2839
+ name: HandleScrollBarPointerCaptureLost,
2840
+ params: ['handleScrollBarCaptureLost']
2841
+ }, {
2596
2842
  name: HandleBlur,
2597
2843
  params: ['handleBlur']
2598
2844
  }, {
@@ -2703,9 +2949,14 @@ const commandMap = {
2703
2949
  'Output.handleData': wrapCommand(handleData),
2704
2950
  'Output.handleError': wrapCommand(handleError),
2705
2951
  'Output.handleFilterInput': wrapCommand(handleFilterInput),
2952
+ 'Output.handleKeyDown': wrapCommand(handleKeyDown),
2706
2953
  'Output.handleMessagePort': handleDirectMessagePort,
2954
+ 'Output.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
2955
+ 'Output.handleScrollBarClick': wrapCommand(handleScrollBarClick),
2956
+ 'Output.handleScrollBarMove': wrapCommand(handleScrollBarMove),
2707
2957
  'Output.handleSelect': wrapCommand(handleSelect),
2708
2958
  'Output.handleSourceLinkClick': wrapCommand(handleSourceLinkClick),
2959
+ 'Output.handleWheel': wrapCommand(handleWheel),
2709
2960
  'Output.initialize': initialize,
2710
2961
  'Output.loadContent2': wrapCommand(loadContent),
2711
2962
  'Output.openFindWidget': wrapCommand(openFindWidget),
@@ -2713,10 +2964,11 @@ const commandMap = {
2713
2964
  'Output.render2': render2,
2714
2965
  'Output.renderActions': wrapGetter(renderActions),
2715
2966
  'Output.renderEventListeners': renderEventListeners,
2716
- 'Output.resize': resize,
2967
+ 'Output.resize': wrapCommand(resize),
2717
2968
  'Output.saveAs': wrapCommand(saveOutputAs),
2718
2969
  'Output.saveState': wrapGetter(saveState),
2719
2970
  'Output.selectChannel': wrapCommand(selectChannel),
2971
+ 'Output.setDeltaY': wrapCommand(setDeltaY),
2720
2972
  'Output.setLogLevel': setLogLevel,
2721
2973
  'Output.setOutputChannel': wrapCommand(setOutputChannel),
2722
2974
  'Output.terminate': terminate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "2.23.0",
3
+ "version": "2.23.1",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",