您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // @flow
  2. import { ReducerRegistry, set } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. FULL_SCREEN_CHANGED,
  6. SET_OVERFLOW_MENU_VISIBLE,
  7. SET_TOOLBAR_HOVERED,
  8. SET_TOOLBOX_ALWAYS_VISIBLE,
  9. SET_TOOLBOX_ENABLED,
  10. SET_TOOLBOX_TIMEOUT,
  11. SET_TOOLBOX_TIMEOUT_MS,
  12. SET_TOOLBOX_VISIBLE
  13. } from './actionTypes';
  14. declare var interfaceConfig: Object;
  15. /**
  16. * Returns initial state for toolbox's part of Redux store.
  17. *
  18. * @private
  19. * @returns {{
  20. * alwaysVisible: boolean,
  21. * enabled: boolean,
  22. * hovered: boolean,
  23. * overflowMenuVisible: boolean,
  24. * timeoutID: number,
  25. * timeoutMS: number,
  26. * visible: boolean
  27. * }}
  28. */
  29. function _getInitialState() {
  30. // Does the toolbar eventually fade out, or is it always visible?
  31. let alwaysVisible = false;
  32. // Toolbar (initial) visibility.
  33. let visible = false;
  34. // Default toolbox timeout for mobile app.
  35. let timeoutMS = 5000;
  36. if (typeof interfaceConfig !== 'undefined') {
  37. if (interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
  38. timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  39. }
  40. if (typeof interfaceConfig.TOOLBAR_ALWAYS_VISIBLE !== 'undefined') {
  41. alwaysVisible = interfaceConfig.TOOLBAR_ALWAYS_VISIBLE;
  42. }
  43. }
  44. // When the toolbar is always visible, it must initially be visible too.
  45. if (alwaysVisible === true) {
  46. visible = true;
  47. }
  48. return {
  49. /**
  50. * The indicator which determines whether the Toolbox should always be
  51. * visible. When false, the toolbar will fade out after timeoutMS.
  52. *
  53. * @type {boolean}
  54. */
  55. alwaysVisible,
  56. /**
  57. * The indicator which determines whether the Toolbox is enabled.
  58. *
  59. * @type {boolean}
  60. */
  61. enabled: true,
  62. /**
  63. * The indicator which determines whether a Toolbar in the Toolbox is
  64. * hovered.
  65. *
  66. * @type {boolean}
  67. */
  68. hovered: false,
  69. /**
  70. * The indicator which determines whether the OverflowMenu is visible.
  71. *
  72. * @type {boolean}
  73. */
  74. overflowMenuVisible: false,
  75. /**
  76. * A number, non-zero value which identifies the timer created by a call
  77. * to setTimeout() with timeoutMS.
  78. *
  79. * @type {number|null}
  80. */
  81. timeoutID: null,
  82. /**
  83. * The delay in milliseconds before timeoutID executes (after its
  84. * initialization).
  85. *
  86. * @type {number}
  87. */
  88. timeoutMS,
  89. /**
  90. * The indicator which determines whether the Toolbox is visible.
  91. *
  92. * @type {boolean}
  93. */
  94. visible
  95. };
  96. }
  97. ReducerRegistry.register(
  98. 'features/toolbox',
  99. (state: Object = _getInitialState(), action: Object) => {
  100. switch (action.type) {
  101. case CLEAR_TOOLBOX_TIMEOUT:
  102. return {
  103. ...state,
  104. timeoutID: undefined
  105. };
  106. case FULL_SCREEN_CHANGED:
  107. return {
  108. ...state,
  109. fullScreen: action.fullScreen
  110. };
  111. case SET_OVERFLOW_MENU_VISIBLE:
  112. return {
  113. ...state,
  114. overflowMenuVisible: action.visible
  115. };
  116. case SET_TOOLBAR_HOVERED:
  117. return {
  118. ...state,
  119. hovered: action.hovered
  120. };
  121. case SET_TOOLBOX_ALWAYS_VISIBLE:
  122. return {
  123. ...state,
  124. alwaysVisible: action.alwaysVisible,
  125. visible: action.alwaysVisible === true ? true : state.visible
  126. };
  127. case SET_TOOLBOX_ENABLED:
  128. return {
  129. ...state,
  130. enabled: action.enabled
  131. };
  132. case SET_TOOLBOX_TIMEOUT:
  133. return {
  134. ...state,
  135. timeoutID: action.timeoutID,
  136. timeoutMS: action.timeoutMS
  137. };
  138. case SET_TOOLBOX_TIMEOUT_MS:
  139. return {
  140. ...state,
  141. timeoutMS: action.timeoutMS
  142. };
  143. case SET_TOOLBOX_VISIBLE:
  144. return set(state, 'visible', action.visible);
  145. }
  146. return state;
  147. });