actionZindex.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React from "react";
  2. import {
  3. moveOneLeft,
  4. moveOneRight,
  5. moveAllLeft,
  6. moveAllRight,
  7. } from "../zindex";
  8. import { KEYS, isDarwin, CODES } from "../keys";
  9. import { t } from "../i18n";
  10. import { getShortcutKey } from "../utils";
  11. import { register } from "./register";
  12. import {
  13. SendBackwardIcon,
  14. BringToFrontIcon,
  15. SendToBackIcon,
  16. BringForwardIcon,
  17. } from "../components/icons";
  18. export const actionSendBackward = register({
  19. name: "sendBackward",
  20. perform: (elements, appState) => {
  21. return {
  22. elements: moveOneLeft(elements, appState),
  23. appState,
  24. commitToHistory: true,
  25. };
  26. },
  27. contextItemLabel: "labels.sendBackward",
  28. keyPriority: 40,
  29. keyTest: (event) =>
  30. event[KEYS.CTRL_OR_CMD] &&
  31. !event.shiftKey &&
  32. event.code === CODES.BRACKET_LEFT,
  33. PanelComponent: ({ updateData, appState }) => (
  34. <button
  35. type="button"
  36. className="zIndexButton"
  37. onClick={() => updateData(null)}
  38. title={`${t("labels.sendBackward")} — ${getShortcutKey("CtrlOrCmd+[")}`}
  39. >
  40. <SendBackwardIcon theme={appState.theme} />
  41. </button>
  42. ),
  43. });
  44. export const actionBringForward = register({
  45. name: "bringForward",
  46. perform: (elements, appState) => {
  47. return {
  48. elements: moveOneRight(elements, appState),
  49. appState,
  50. commitToHistory: true,
  51. };
  52. },
  53. contextItemLabel: "labels.bringForward",
  54. keyPriority: 40,
  55. keyTest: (event) =>
  56. event[KEYS.CTRL_OR_CMD] &&
  57. !event.shiftKey &&
  58. event.code === CODES.BRACKET_RIGHT,
  59. PanelComponent: ({ updateData, appState }) => (
  60. <button
  61. type="button"
  62. className="zIndexButton"
  63. onClick={() => updateData(null)}
  64. title={`${t("labels.bringForward")} — ${getShortcutKey("CtrlOrCmd+]")}`}
  65. >
  66. <BringForwardIcon theme={appState.theme} />
  67. </button>
  68. ),
  69. });
  70. export const actionSendToBack = register({
  71. name: "sendToBack",
  72. perform: (elements, appState) => {
  73. return {
  74. elements: moveAllLeft(elements, appState),
  75. appState,
  76. commitToHistory: true,
  77. };
  78. },
  79. contextItemLabel: "labels.sendToBack",
  80. keyTest: (event) =>
  81. isDarwin
  82. ? event[KEYS.CTRL_OR_CMD] &&
  83. event.altKey &&
  84. event.code === CODES.BRACKET_LEFT
  85. : event[KEYS.CTRL_OR_CMD] &&
  86. event.shiftKey &&
  87. event.code === CODES.BRACKET_LEFT,
  88. PanelComponent: ({ updateData, appState }) => (
  89. <button
  90. type="button"
  91. className="zIndexButton"
  92. onClick={() => updateData(null)}
  93. title={`${t("labels.sendToBack")} — ${
  94. isDarwin
  95. ? getShortcutKey("CtrlOrCmd+Alt+[")
  96. : getShortcutKey("CtrlOrCmd+Shift+[")
  97. }`}
  98. >
  99. <SendToBackIcon theme={appState.theme} />
  100. </button>
  101. ),
  102. });
  103. export const actionBringToFront = register({
  104. name: "bringToFront",
  105. perform: (elements, appState) => {
  106. return {
  107. elements: moveAllRight(elements, appState),
  108. appState,
  109. commitToHistory: true,
  110. };
  111. },
  112. contextItemLabel: "labels.bringToFront",
  113. keyTest: (event) =>
  114. isDarwin
  115. ? event[KEYS.CTRL_OR_CMD] &&
  116. event.altKey &&
  117. event.code === CODES.BRACKET_RIGHT
  118. : event[KEYS.CTRL_OR_CMD] &&
  119. event.shiftKey &&
  120. event.code === CODES.BRACKET_RIGHT,
  121. PanelComponent: ({ updateData, appState }) => (
  122. <button
  123. type="button"
  124. className="zIndexButton"
  125. onClick={(event) => updateData(null)}
  126. title={`${t("labels.bringToFront")} — ${
  127. isDarwin
  128. ? getShortcutKey("CtrlOrCmd+Alt+]")
  129. : getShortcutKey("CtrlOrCmd+Shift+]")
  130. }`}
  131. >
  132. <BringToFrontIcon theme={appState.theme} />
  133. </button>
  134. ),
  135. });