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

reducer.js 4.8KB

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