@lvce-editor/output-view 2.24.1 → 2.24.3

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.
@@ -1841,6 +1841,214 @@ const text = data => {
1841
1841
  };
1842
1842
  };
1843
1843
 
1844
+ const HandleBlur = 'handleBlur';
1845
+ const HandleClearFilterClick = 'handleClearFilterClick';
1846
+ const HandleContextMenu = 'handleContextMenu';
1847
+ const HandleFilterInput = 'handleFilterInput';
1848
+ const HandlePointerDown = 'handlePointerDown';
1849
+ const HandleSelect = 'handleSelect';
1850
+ const HandleButtonClick = 'handleButtonClick';
1851
+ const HandleSourceLinkClick = 'handleSourceLinkClick';
1852
+ const HandleWheel = 'handleWheel';
1853
+ const HandleKeyDown = 'handleKeyDown';
1854
+ const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
1855
+ const HandleScrollBarMove = 'handleScrollBarMove';
1856
+ const HandleScrollBarPointerCaptureLost = 'handleScrollBarPointerCaptureLost';
1857
+
1858
+ const noNodes = [];
1859
+ const repeatCountNode = {
1860
+ childCount: 1,
1861
+ className: OutputRepeatCount,
1862
+ type: Span
1863
+ };
1864
+ const spaceNode = text(' ');
1865
+ const getLevel = parts => {
1866
+ return parts.find(part => part.type === LogLevel)?.value || '';
1867
+ };
1868
+ const getLinePartDom = part => {
1869
+ switch (part.type) {
1870
+ case Link:
1871
+ {
1872
+ const isSourceLink = part.className === OutputSourceLink;
1873
+ const linkNode = {
1874
+ childCount: 1,
1875
+ href: part.value,
1876
+ rel: 'noopener noreferrer',
1877
+ target: '_blank',
1878
+ type: A,
1879
+ ...(part.className && {
1880
+ className: part.className
1881
+ }),
1882
+ ...(part.columnNumber !== undefined && {
1883
+ 'data-column': part.columnNumber
1884
+ }),
1885
+ ...(part.lineNumber !== undefined && {
1886
+ 'data-line': part.lineNumber
1887
+ }),
1888
+ ...(isSourceLink && {
1889
+ onClick: HandleSourceLinkClick
1890
+ })
1891
+ };
1892
+ return {
1893
+ childCount: 1,
1894
+ nodes: [linkNode, text(part.label || part.value)]
1895
+ };
1896
+ }
1897
+ case RepeatCount:
1898
+ return {
1899
+ childCount: 2,
1900
+ nodes: [repeatCountNode, text(part.value), spaceNode]
1901
+ };
1902
+ case Text:
1903
+ return {
1904
+ childCount: 1,
1905
+ nodes: [text(part.value)]
1906
+ };
1907
+ default:
1908
+ return {
1909
+ childCount: 0,
1910
+ nodes: noNodes
1911
+ };
1912
+ }
1913
+ };
1914
+ const getLineDom = parts => {
1915
+ const children = [];
1916
+ let childCount = 0;
1917
+ for (const part of parts) {
1918
+ const partDom = getLinePartDom(part);
1919
+ children.push(...partDom.nodes);
1920
+ childCount += partDom.childCount;
1921
+ }
1922
+ const level = getLevel(parts);
1923
+ const className = level ? mergeClassNames(Line, level) : Line;
1924
+ const lineNode = {
1925
+ childCount,
1926
+ className,
1927
+ type: Div
1928
+ };
1929
+ return [lineNode, ...children];
1930
+ };
1931
+
1932
+ const Focusable = 0;
1933
+
1934
+ const getContentDom = (lines, error) => {
1935
+ if (error) {
1936
+ return [];
1937
+ }
1938
+ return [{
1939
+ childCount: lines.length,
1940
+ className: OutputContent,
1941
+ onKeyDown: HandleKeyDown,
1942
+ onWheel: HandleWheel,
1943
+ role: Log,
1944
+ tabIndex: Focusable,
1945
+ type: Div
1946
+ }, ...lines.flatMap(getLineDom)];
1947
+ };
1948
+
1949
+ const LogFileNotFound$1 = 1;
1950
+
1951
+ const emptyObject = {};
1952
+ const i18nString = (key, placeholders = emptyObject) => {
1953
+ if (placeholders === emptyObject) {
1954
+ return key;
1955
+ }
1956
+ let result = key;
1957
+ for (const [placeholder, replacement] of Object.entries(placeholders)) {
1958
+ result = result.split(`{${placeholder}}`).join(String(replacement));
1959
+ }
1960
+ return result;
1961
+ };
1962
+
1963
+ const ClearOutput = 'clear output';
1964
+ const Filter$1 = 'Filter';
1965
+ const LogFileNotFound = 'The log file was not found.';
1966
+ const Settings$1 = 'Settings';
1967
+ const TurnOffAutoScroll = 'Turn auto scrolling off';
1968
+
1969
+ const clearOutput = () => {
1970
+ return i18nString(ClearOutput);
1971
+ };
1972
+ const turnOffAutoScroll = () => {
1973
+ return i18nString(TurnOffAutoScroll);
1974
+ };
1975
+ const settings = () => {
1976
+ return i18nString(Settings$1);
1977
+ };
1978
+ const logFileNotFound = () => {
1979
+ return i18nString(LogFileNotFound);
1980
+ };
1981
+ const filter = () => {
1982
+ return i18nString(Filter$1);
1983
+ };
1984
+
1985
+ const messageNode = {
1986
+ childCount: 1,
1987
+ className: Message,
1988
+ tabIndex: Focusable,
1989
+ type: Div
1990
+ };
1991
+ const getLogFileNotFoundDom = () => {
1992
+ return [messageNode, text(logFileNotFound())];
1993
+ };
1994
+
1995
+ const errorNode = {
1996
+ childCount: 1,
1997
+ className: Error$1,
1998
+ tabIndex: Focusable,
1999
+ type: Div
2000
+ };
2001
+ const getErrorDom = (errorCode, error) => {
2002
+ if (!error) {
2003
+ return [];
2004
+ }
2005
+ if (errorCode === LogFileNotFound$1) {
2006
+ return getLogFileNotFoundDom();
2007
+ }
2008
+ return [errorNode, text(error)];
2009
+ };
2010
+
2011
+ const scrollBarNode = {
2012
+ childCount: 1,
2013
+ className: mergeClassNames(ScrollBar, ScrollBarSmall),
2014
+ onPointerDown: HandleScrollBarPointerDown,
2015
+ type: Div
2016
+ };
2017
+ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarActive) => {
2018
+ if (scrollBarHeight <= 0) {
2019
+ return [];
2020
+ }
2021
+ return [scrollBarNode, {
2022
+ childCount: 0,
2023
+ className: mergeClassNames(ScrollBarThumb, scrollBarActive ? ScrollBarThumbActive : ''),
2024
+ type: Div
2025
+ }];
2026
+ };
2027
+
2028
+ const outputNode = {
2029
+ childCount: 1,
2030
+ className: mergeClassNames(Viewlet, Output$1),
2031
+ type: Div
2032
+ };
2033
+ const getOutputVirtualDom = (lines, errorCode, error, scrollBarHeight = 0, scrollBarActive = false) => {
2034
+ const scrollBarDom = error ? [] : getScrollBarVirtualDom(scrollBarHeight, scrollBarActive);
2035
+ return [{
2036
+ ...outputNode,
2037
+ childCount: scrollBarDom.length > 0 ? 2 : 1
2038
+ }, ...getContentDom(lines, error), ...getErrorDom(errorCode, error), ...scrollBarDom];
2039
+ };
2040
+
2041
+ const getComponentDom = uid => {
2042
+ const {
2043
+ newState
2044
+ } = get(uid);
2045
+ return getOutputVirtualDom(newState.filteredItems.slice(newState.minLineY, newState.maxLineY), newState.errorCode, newState.error, newState.scrollBarHeight, newState.scrollBarActive);
2046
+ };
2047
+
2048
+ const getComponentState = uid => {
2049
+ return get(uid).newState;
2050
+ };
2051
+
1844
2052
  const FocusProblems = 19;
1845
2053
 
1846
2054
  const getKeyBindings = () => {
@@ -1891,14 +2099,14 @@ const getKeyBindings = () => {
1891
2099
  }];
1892
2100
  };
1893
2101
 
1894
- const Filter$1 = 'filter';
2102
+ const Filter = 'filter';
1895
2103
  const Output = 'output';
1896
2104
  const MainProcess = 'MainProcess';
1897
2105
  const SharedProcess = 'SharedProcess';
1898
2106
  const Window = 'Window';
1899
2107
  const PreviewSandbox = 'PreviewSandbox';
1900
2108
  const Clear = 'Clear';
1901
- const Settings$1 = 'Settings';
2109
+ const Settings = 'Settings';
1902
2110
  const ScrollLock = 'ScrollLock';
1903
2111
 
1904
2112
  const noop = async state => {
@@ -2116,6 +2324,9 @@ const setupChangeListener = async (oldWatchId, newWatchId, uri) => {
2116
2324
  unregisterWatchCallback(oldWatchId);
2117
2325
  await unwatchFile(oldWatchId);
2118
2326
  }
2327
+ if (!uri) {
2328
+ return;
2329
+ }
2119
2330
  if (isExtensionOutputUri(uri)) {
2120
2331
  return;
2121
2332
  }
@@ -2247,40 +2458,6 @@ const getSelectedItem = (selectedOption, platform) => {
2247
2458
  return MainProcess;
2248
2459
  };
2249
2460
 
2250
- const emptyObject = {};
2251
- const i18nString = (key, placeholders = emptyObject) => {
2252
- if (placeholders === emptyObject) {
2253
- return key;
2254
- }
2255
- let result = key;
2256
- for (const [placeholder, replacement] of Object.entries(placeholders)) {
2257
- result = result.split(`{${placeholder}}`).join(String(replacement));
2258
- }
2259
- return result;
2260
- };
2261
-
2262
- const ClearOutput = 'clear output';
2263
- const Filter = 'Filter';
2264
- const LogFileNotFound$1 = 'The log file was not found.';
2265
- const Settings = 'Settings';
2266
- const TurnOffAutoScroll = 'Turn auto scrolling off';
2267
-
2268
- const clearOutput = () => {
2269
- return i18nString(ClearOutput);
2270
- };
2271
- const turnOffAutoScroll = () => {
2272
- return i18nString(TurnOffAutoScroll);
2273
- };
2274
- const settings = () => {
2275
- return i18nString(Settings);
2276
- };
2277
- const logFileNotFound = () => {
2278
- return i18nString(LogFileNotFound$1);
2279
- };
2280
- const filter = () => {
2281
- return i18nString(Filter);
2282
- };
2283
-
2284
2461
  const loadButtons = () => {
2285
2462
  return [{
2286
2463
  icon: 'MaskIconClearAll',
@@ -2292,7 +2469,7 @@ const loadButtons = () => {
2292
2469
  label: turnOffAutoScroll()
2293
2470
  }, {
2294
2471
  icon: 'MaskIconSettingsGear',
2295
- id: Settings$1,
2472
+ id: Settings,
2296
2473
  label: settings()
2297
2474
  }];
2298
2475
  };
@@ -2454,7 +2631,22 @@ const loadContent = async (state, savedState) => {
2454
2631
  const options = await loadOptions(platform);
2455
2632
  const option = getMatchingOpen(options, selectedId);
2456
2633
  if (!option) {
2457
- throw new Error('option not found');
2634
+ await setupChangeListener(watchId, 0, '');
2635
+ const buttons = loadButtons();
2636
+ return {
2637
+ ...state,
2638
+ buttons,
2639
+ collapsedUris,
2640
+ error: '',
2641
+ errorCode: 0,
2642
+ filteredItems: [],
2643
+ filterValue,
2644
+ listItems: [],
2645
+ options,
2646
+ scrollLockEnabled,
2647
+ selectedOption: '',
2648
+ watchId: 0
2649
+ };
2458
2650
  }
2459
2651
  const {
2460
2652
  uri
@@ -2559,170 +2751,7 @@ const renderCss = (oldState, newState) => {
2559
2751
  };
2560
2752
 
2561
2753
  const renderFilterValue = (oldState, newState) => {
2562
- return ['Viewlet.setValueByName', newState.uid, Filter$1, newState.filterValue];
2563
- };
2564
-
2565
- const HandleBlur = 'handleBlur';
2566
- const HandleClearFilterClick = 'handleClearFilterClick';
2567
- const HandleContextMenu = 'handleContextMenu';
2568
- const HandleFilterInput = 'handleFilterInput';
2569
- const HandlePointerDown = 'handlePointerDown';
2570
- const HandleSelect = 'handleSelect';
2571
- const HandleButtonClick = 'handleButtonClick';
2572
- const HandleSourceLinkClick = 'handleSourceLinkClick';
2573
- const HandleWheel = 'handleWheel';
2574
- const HandleKeyDown = 'handleKeyDown';
2575
- const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
2576
- const HandleScrollBarMove = 'handleScrollBarMove';
2577
- const HandleScrollBarPointerCaptureLost = 'handleScrollBarPointerCaptureLost';
2578
-
2579
- const noNodes = [];
2580
- const repeatCountNode = {
2581
- childCount: 1,
2582
- className: OutputRepeatCount,
2583
- type: Span
2584
- };
2585
- const spaceNode = text(' ');
2586
- const getLevel = parts => {
2587
- return parts.find(part => part.type === LogLevel)?.value || '';
2588
- };
2589
- const getLinePartDom = part => {
2590
- switch (part.type) {
2591
- case Link:
2592
- {
2593
- const isSourceLink = part.className === OutputSourceLink;
2594
- const linkNode = {
2595
- childCount: 1,
2596
- href: part.value,
2597
- rel: 'noopener noreferrer',
2598
- target: '_blank',
2599
- type: A,
2600
- ...(part.className && {
2601
- className: part.className
2602
- }),
2603
- ...(part.columnNumber !== undefined && {
2604
- 'data-column': part.columnNumber
2605
- }),
2606
- ...(part.lineNumber !== undefined && {
2607
- 'data-line': part.lineNumber
2608
- }),
2609
- ...(isSourceLink && {
2610
- onClick: HandleSourceLinkClick
2611
- })
2612
- };
2613
- return {
2614
- childCount: 1,
2615
- nodes: [linkNode, text(part.label || part.value)]
2616
- };
2617
- }
2618
- case RepeatCount:
2619
- return {
2620
- childCount: 2,
2621
- nodes: [repeatCountNode, text(part.value), spaceNode]
2622
- };
2623
- case Text:
2624
- return {
2625
- childCount: 1,
2626
- nodes: [text(part.value)]
2627
- };
2628
- default:
2629
- return {
2630
- childCount: 0,
2631
- nodes: noNodes
2632
- };
2633
- }
2634
- };
2635
- const getLineDom = parts => {
2636
- const children = [];
2637
- let childCount = 0;
2638
- for (const part of parts) {
2639
- const partDom = getLinePartDom(part);
2640
- children.push(...partDom.nodes);
2641
- childCount += partDom.childCount;
2642
- }
2643
- const level = getLevel(parts);
2644
- const className = level ? mergeClassNames(Line, level) : Line;
2645
- const lineNode = {
2646
- childCount,
2647
- className,
2648
- type: Div
2649
- };
2650
- return [lineNode, ...children];
2651
- };
2652
-
2653
- const Focusable = 0;
2654
-
2655
- const getContentDom = (lines, error) => {
2656
- if (error) {
2657
- return [];
2658
- }
2659
- return [{
2660
- childCount: lines.length,
2661
- className: OutputContent,
2662
- onKeyDown: HandleKeyDown,
2663
- onWheel: HandleWheel,
2664
- role: Log,
2665
- tabIndex: Focusable,
2666
- type: Div
2667
- }, ...lines.flatMap(getLineDom)];
2668
- };
2669
-
2670
- const LogFileNotFound = 1;
2671
-
2672
- const messageNode = {
2673
- childCount: 1,
2674
- className: Message,
2675
- tabIndex: Focusable,
2676
- type: Div
2677
- };
2678
- const getLogFileNotFoundDom = () => {
2679
- return [messageNode, text(logFileNotFound())];
2680
- };
2681
-
2682
- const errorNode = {
2683
- childCount: 1,
2684
- className: Error$1,
2685
- tabIndex: Focusable,
2686
- type: Div
2687
- };
2688
- const getErrorDom = (errorCode, error) => {
2689
- if (!error) {
2690
- return [];
2691
- }
2692
- if (errorCode === LogFileNotFound) {
2693
- return getLogFileNotFoundDom();
2694
- }
2695
- return [errorNode, text(error)];
2696
- };
2697
-
2698
- const scrollBarNode = {
2699
- childCount: 1,
2700
- className: mergeClassNames(ScrollBar, ScrollBarSmall),
2701
- onPointerDown: HandleScrollBarPointerDown,
2702
- type: Div
2703
- };
2704
- const getScrollBarVirtualDom = (scrollBarHeight, scrollBarActive) => {
2705
- if (scrollBarHeight <= 0) {
2706
- return [];
2707
- }
2708
- return [scrollBarNode, {
2709
- childCount: 0,
2710
- className: mergeClassNames(ScrollBarThumb, scrollBarActive ? ScrollBarThumbActive : ''),
2711
- type: Div
2712
- }];
2713
- };
2714
-
2715
- const outputNode = {
2716
- childCount: 1,
2717
- className: mergeClassNames(Viewlet, Output$1),
2718
- type: Div
2719
- };
2720
- const getOutputVirtualDom = (lines, errorCode, error, scrollBarHeight = 0, scrollBarActive = false) => {
2721
- const scrollBarDom = error ? [] : getScrollBarVirtualDom(scrollBarHeight, scrollBarActive);
2722
- return [{
2723
- ...outputNode,
2724
- childCount: scrollBarDom.length > 0 ? 2 : 1
2725
- }, ...getContentDom(lines, error), ...getErrorDom(errorCode, error), ...scrollBarDom];
2754
+ return ['Viewlet.setValueByName', newState.uid, Filter, newState.filterValue];
2726
2755
  };
2727
2756
 
2728
2757
  const renderItems = (oldState, newState) => {
@@ -2813,7 +2842,7 @@ const getFilterVirtualDom = () => {
2813
2842
  return [filterNode, {
2814
2843
  childCount: 0,
2815
2844
  className: filterInputClassName,
2816
- name: Filter$1,
2845
+ name: Filter,
2817
2846
  onInput: HandleFilterInput,
2818
2847
  placeholder,
2819
2848
  type: Input
@@ -2968,6 +2997,26 @@ const saveState = state => {
2968
2997
  };
2969
2998
  };
2970
2999
 
3000
+ const applyComponentState = (currentState, state) => {
3001
+ if (!state || typeof state !== 'object' || Array.isArray(state)) {
3002
+ throw new TypeError('Output state must be an object');
3003
+ }
3004
+ const {
3005
+ uid
3006
+ } = state;
3007
+ const {
3008
+ uid: currentUid
3009
+ } = currentState;
3010
+ if (uid !== currentUid) {
3011
+ throw new Error(`Output state uid must remain ${currentUid}`);
3012
+ }
3013
+ return {
3014
+ ...state,
3015
+ watchId: currentState.watchId
3016
+ };
3017
+ };
3018
+ const setComponentState = wrapCommand(applyComponentState);
3019
+
2971
3020
  const setLogLevel = async (state, logLevel) => {
2972
3021
  return {
2973
3022
  ...state,
@@ -2994,6 +3043,8 @@ const commandMap = {
2994
3043
  'Output.focusIndex': wrapCommand(focusIndex),
2995
3044
  'Output.getActions': getActions,
2996
3045
  'Output.getCommandIds': getCommandIds,
3046
+ 'Output.getComponentDom': getComponentDom,
3047
+ 'Output.getComponentState': getComponentState,
2997
3048
  'Output.getKeyBindings': getKeyBindings,
2998
3049
  'Output.handleButtonClick': wrapCommand(handleButtonClick),
2999
3050
  'Output.handleContextMenu': wrapCommand(handleContextMenu),
@@ -3019,6 +3070,7 @@ const commandMap = {
3019
3070
  'Output.saveAs': wrapCommand(saveOutputAs),
3020
3071
  'Output.saveState': wrapGetter(saveState),
3021
3072
  'Output.selectChannel': wrapCommand(selectChannel),
3073
+ 'Output.setComponentState': setComponentState,
3022
3074
  'Output.setDeltaY': wrapCommand(setDeltaY),
3023
3075
  'Output.setLogLevel': setLogLevel,
3024
3076
  'Output.setOutputChannel': wrapCommand(setOutputChannel),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "2.24.1",
3
+ "version": "2.24.3",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",