app.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { APP_STATE } from "./core/enums/app-state-enum";
  2. import { stageManager as Stages } from "./core/application/stage-manager";
  3. import { objects as Objects } from "./core/application/objects";
  4. import { state as State } from "./core/application/state";
  5. import { selector as Selector } from "./core/application/selector";
  6. import { menu as Menu } from "./core/application/menu";
  7. import Konva from "konva";
  8. import { COMPONENT_TYPE } from "./core/enums/component-type-enum";
  9. import { headerMenu } from "./core/application/header-menu";
  10. export const app = (function () {
  11. let _selectedTool = [];
  12. function _bootstrap() {
  13. Konva.showWarnings = false;
  14. headerMenu.bootstrap();
  15. Selector.bootstrap();
  16. requireAll(require.context("./component-registry/", true, /\.js$/));
  17. _refreshMenu();
  18. $("body").on("mouseenter", ".li-content", e => $(e.currentTarget).parent().find('.level-1').css("background-color", "#d4d4d4"));
  19. $("body").on("mouseleave", ".li-content", e => $(e.currentTarget).parent().find('.level-1').css("background-color", "transparent"));
  20. ;
  21. }
  22. function _currentLayer() {
  23. return Stages.getCurrentKonvaLayer();
  24. }
  25. function _setSelectedTool(tool) {
  26. _clearSelectedTool(tool != undefined);
  27. _setState(APP_STATE.TOOL_SELECTED);
  28. if (tool.options.id != undefined) {
  29. document.getElementById("btn-" + tool.options.id).disabled = true;
  30. }
  31. _selectedTool.push(tool);
  32. }
  33. function _clearSelectedTool(force) {
  34. let tool = _getSelectedTool();
  35. if (tool != undefined) {
  36. if (!force && tool.options.type == COMPONENT_TYPE.SELECTOR) {
  37. return;
  38. }
  39. if (tool.options.id != undefined) {
  40. document.getElementById("btn-" + tool.options.id).disabled = false;
  41. }
  42. }
  43. _selectedTool = [];
  44. _setStatus("");
  45. _setState(APP_STATE.NONE);
  46. }
  47. function _getSelectedTool() {
  48. if (_selectedTool.length > 0) return _selectedTool[0];
  49. return undefined;
  50. }
  51. function _getRelativePointerPosition() {
  52. const stage = Stages.getCurrentKonvaStage();
  53. return stage.getPointerPosition();
  54. }
  55. function _setStatus(status) {
  56. document.getElementById("status").innerHTML = status;
  57. }
  58. function _pushObject(object) {
  59. return;
  60. Objects.add(object);
  61. }
  62. function _getObjects() {
  63. return Objects.get();
  64. }
  65. function _setState(e) {
  66. State.setState(e);
  67. }
  68. function _refreshMenu() {
  69. Menu.refresh();
  70. }
  71. function requireAll(r) {
  72. r.keys().forEach(r);
  73. }
  74. _bootstrap();
  75. return {
  76. stage: Stages.getCurrentKonvaStage,
  77. currentLayer: _currentLayer,
  78. bootstrap: _bootstrap,
  79. setSelectedTool: _setSelectedTool,
  80. clearSelectedTool: _clearSelectedTool,
  81. getSelectedTool: _getSelectedTool,
  82. pos: _getRelativePointerPosition,
  83. setStatus: _setStatus,
  84. pushObject: _pushObject,
  85. getObjects: _getObjects,
  86. setState: _setState
  87. };
  88. })();