tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ui.js (5973B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 /* eslint-disable complexity */
      6 
      7 /**
      8 * UI reducer
      9 *
     10 * @module reducers/ui
     11 */
     12 
     13 import { prefs, features } from "../utils/prefs";
     14 import { searchKeys } from "../constants";
     15 
     16 export const initialUIState = () => ({
     17  selectedPrimaryPaneTab: "sources",
     18  activeSearch: null,
     19  startPanelCollapsed: prefs.startPanelCollapsed,
     20  endPanelCollapsed: prefs.endPanelCollapsed,
     21  frameworkGroupingOn: prefs.frameworkGroupingOn,
     22 
     23  // This is used from Outline's copy to clipboard context menu
     24  // and QuickOpen to highlight lines temporarily.
     25  // If defined, it will be an object with following attributes:
     26  // - sourceId, String
     27  // - start, Number, start line to highlight, 1-based
     28  // - end, Number, end line to highlight, 1-based
     29  highlightedLineRange: null,
     30 
     31  conditionalPanelLocation: null,
     32  isLogPoint: false,
     33  orientation: "horizontal",
     34  viewport: null,
     35  inlinePreviewEnabled: features.inlinePreview,
     36  editorWrappingEnabled: prefs.editorWrapping,
     37  javascriptEnabled: true,
     38  mutableSearchOptions: prefs.searchOptions || {
     39    [searchKeys.FILE_SEARCH]: {
     40      regexMatch: false,
     41      wholeWord: false,
     42      caseSensitive: false,
     43      excludePatterns: "",
     44    },
     45    [searchKeys.PROJECT_SEARCH]: {
     46      regexMatch: false,
     47      wholeWord: false,
     48      caseSensitive: false,
     49      excludePatterns: "",
     50    },
     51    [searchKeys.QUICKOPEN_SEARCH]: {
     52      regexMatch: false,
     53      wholeWord: false,
     54      caseSensitive: false,
     55      excludePatterns: "",
     56    },
     57  },
     58  projectSearchQuery: "",
     59  hideIgnoredSources: prefs.hideIgnoredSources,
     60  sourceMapsEnabled: prefs.clientSourceMapsEnabled,
     61  sourceMapIgnoreListEnabled: prefs.sourceMapIgnoreListEnabled,
     62  pausedOverlayEnabled: prefs.pausedOverlayEnabled,
     63 });
     64 
     65 function update(state = initialUIState(), action) {
     66  switch (action.type) {
     67    case "TOGGLE_ACTIVE_SEARCH": {
     68      return { ...state, activeSearch: action.value };
     69    }
     70 
     71    case "TOGGLE_FRAMEWORK_GROUPING": {
     72      prefs.frameworkGroupingOn = action.value;
     73      return { ...state, frameworkGroupingOn: action.value };
     74    }
     75 
     76    case "TOGGLE_INLINE_PREVIEW": {
     77      features.inlinePreview = action.value;
     78      return { ...state, inlinePreviewEnabled: action.value };
     79    }
     80 
     81    case "TOGGLE_EDITOR_WRAPPING": {
     82      prefs.editorWrapping = action.value;
     83      return { ...state, editorWrappingEnabled: action.value };
     84    }
     85 
     86    case "TOGGLE_JAVASCRIPT_ENABLED": {
     87      return { ...state, javascriptEnabled: action.value };
     88    }
     89 
     90    case "TOGGLE_SOURCE_MAPS_ENABLED": {
     91      prefs.clientSourceMapsEnabled = action.value;
     92      return { ...state, sourceMapsEnabled: action.value };
     93    }
     94 
     95    case "SET_ORIENTATION": {
     96      return { ...state, orientation: action.orientation };
     97    }
     98 
     99    case "TOGGLE_PANE": {
    100      if (action.position == "start") {
    101        prefs.startPanelCollapsed = action.paneCollapsed;
    102        return { ...state, startPanelCollapsed: action.paneCollapsed };
    103      }
    104 
    105      prefs.endPanelCollapsed = action.paneCollapsed;
    106      return { ...state, endPanelCollapsed: action.paneCollapsed };
    107    }
    108 
    109    case "HIGHLIGHT_LINES": {
    110      return { ...state, highlightedLineRange: action.location };
    111    }
    112 
    113    case "CLOSE_QUICK_OPEN":
    114    case "CLEAR_HIGHLIGHT_LINES":
    115      if (!state.highlightedLineRange) {
    116        return state;
    117      }
    118      return { ...state, highlightedLineRange: null };
    119 
    120    case "OPEN_CONDITIONAL_PANEL":
    121      return {
    122        ...state,
    123        conditionalPanelLocation: action.location,
    124        isLogPoint: action.log,
    125      };
    126 
    127    case "CLOSE_CONDITIONAL_PANEL":
    128      return { ...state, conditionalPanelLocation: null };
    129 
    130    case "SET_PRIMARY_PANE_TAB":
    131      return { ...state, selectedPrimaryPaneTab: action.tabName };
    132 
    133    case "CLOSE_PROJECT_SEARCH": {
    134      if (state.activeSearch === "project") {
    135        return { ...state, activeSearch: null };
    136      }
    137      return state;
    138    }
    139 
    140    case "SET_VIEWPORT": {
    141      return { ...state, viewport: action.viewport };
    142    }
    143 
    144    case "NAVIGATE": {
    145      return { ...state, highlightedLineRange: null };
    146    }
    147 
    148    case "REMOVE_SOURCES": {
    149      // Reset the highlighted range if the related source has been removed
    150      const source = state.highlightedLineRange?.source;
    151      if (source && action.sources.includes(source)) {
    152        return { ...state, highlightedLineRange: null };
    153      }
    154      return state;
    155    }
    156 
    157    case "SET_SEARCH_OPTIONS": {
    158      state.mutableSearchOptions[action.searchKey] = {
    159        ...state.mutableSearchOptions[action.searchKey],
    160        ...action.searchOptions,
    161      };
    162      prefs.searchOptions = state.mutableSearchOptions;
    163      return { ...state };
    164    }
    165 
    166    case "SET_PROJECT_SEARCH_QUERY": {
    167      if (action.query != state.projectSearchQuery) {
    168        state.projectSearchQuery = action.query;
    169        return { ...state };
    170      }
    171      return state;
    172    }
    173 
    174    case "HIDE_IGNORED_SOURCES": {
    175      const { shouldHide } = action;
    176      if (shouldHide !== state.hideIgnoredSources) {
    177        prefs.hideIgnoredSources = shouldHide;
    178        return { ...state, hideIgnoredSources: shouldHide };
    179      }
    180      return state;
    181    }
    182 
    183    case "ENABLE_SOURCEMAP_IGNORELIST": {
    184      const { shouldEnable } = action;
    185      if (shouldEnable !== state.sourceMapIgnoreListEnabled) {
    186        prefs.sourceMapIgnoreListEnabled = shouldEnable;
    187        return { ...state, sourceMapIgnoreListEnabled: shouldEnable };
    188      }
    189      return state;
    190    }
    191 
    192    case "ENABLE_PAUSED_OVERLAY": {
    193      const { shouldEnable } = action;
    194      if (shouldEnable !== state.pausedOverlayEnabled) {
    195        prefs.pausedOverlayEnabled = shouldEnable;
    196        return { ...state, pausedOverlayEnabled: shouldEnable };
    197      }
    198      return state;
    199    }
    200 
    201    default: {
    202      return state;
    203    }
    204  }
    205 }
    206 
    207 export default update;