From c58f43450912e68a5c88f29d90220dec182ae286 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 3 Feb 2022 22:19:18 -0800 Subject: [PATCH] Fix missing method error --- packages/mindplot/src/components/Designer.ts | 14 ++ ...esignerKeyboard.js => DesignerKeyboard.ts} | 157 +++++++++--------- .../components/{Keyboard.js => Keyboard.ts} | 0 3 files changed, 95 insertions(+), 76 deletions(-) rename packages/mindplot/src/components/{DesignerKeyboard.js => DesignerKeyboard.ts} (85%) rename packages/mindplot/src/components/{Keyboard.js => Keyboard.ts} (100%) diff --git a/packages/mindplot/src/components/Designer.ts b/packages/mindplot/src/components/Designer.ts index b20a6050..3aacb33c 100644 --- a/packages/mindplot/src/components/Designer.ts +++ b/packages/mindplot/src/components/Designer.ts @@ -354,6 +354,20 @@ class Designer extends Events { } } + shrinkSelectedBranch() { + const nodes = this.getModel().filterSelectedTopics(); + if (nodes.length <= 0 || nodes.length !== 1) { + // If there are more than one node selected, + $notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED_COLLAPSE')); + return; + } + // Execute event ... + const topic = nodes[0]; + if (topic.getType() !== 'CentralTopic') { + this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken()); + } + } + copyToClipboard(): void { let topics = this.getModel().filterSelectedTopics(); if (topics.length <= 0) { diff --git a/packages/mindplot/src/components/DesignerKeyboard.js b/packages/mindplot/src/components/DesignerKeyboard.ts similarity index 85% rename from packages/mindplot/src/components/DesignerKeyboard.js rename to packages/mindplot/src/components/DesignerKeyboard.ts index 117301eb..9018f6ab 100644 --- a/packages/mindplot/src/components/DesignerKeyboard.js +++ b/packages/mindplot/src/components/DesignerKeyboard.ts @@ -18,15 +18,19 @@ import $ from 'jquery'; import { $assert } from '@wisemapping/core-js'; import Keyboard from './Keyboard'; +import { Designer } from '..'; +import Topic from './Topic'; class DesignerKeyboard extends Keyboard { - constructor(designer) { - super(designer); + static _instance: any; + + constructor(designer: Designer) { + super(); $assert(designer, 'designer can not be null'); this._registerEvents(designer); } - _registerEvents(designer) { + private _registerEvents(designer: Designer) { // Try with the keyboard .. const model = designer.getModel(); this.addShortcut( @@ -250,8 +254,9 @@ class DesignerKeyboard extends Keyboard { keyCode = event.keyCode; } - const specialKey = $.hotkeys.specialKeys[keyCode]; - if (['enter', 'capslock'].indexOf(specialKey) === -1 && !$.hotkeys.shiftNums[keyCode]) { + const jq: any = $; + const specialKey = jq.hotkeys.specialKeys[keyCode]; + if (['enter', 'capslock'].indexOf(specialKey) === -1 && !jq.hotkeys.shiftNums[keyCode]) { const nodes = designer.getModel().filterSelectedTopics(); if (nodes.length > 0) { // If a modifier is press, the key selected must be ignored. @@ -266,7 +271,7 @@ class DesignerKeyboard extends Keyboard { }); } - _goToBrother(designer, node, direction) { + private _goToBrother(designer: Designer, node: Topic, direction) { const parent = node.getParent(); if (parent) { const brothers = parent.getChildren(); @@ -305,7 +310,7 @@ class DesignerKeyboard extends Keyboard { } } - _goToSideChild(designer, node, side) { + private _goToSideChild(designer: Designer, node: Topic, side: 'LEFT' | 'RIGHT') { const children = node.getChildren(); if (children.length > 0) { let target = children[0]; @@ -331,14 +336,14 @@ class DesignerKeyboard extends Keyboard { } } - _goToParent(designer, node) { + private _goToParent(designer: Designer, node: Topic) { const parent = node.getParent(); if (parent) { this._goToNode(designer, parent); } } - _goToChild(designer, node) { + private _goToChild(designer, node) { const children = node.getChildren(); if (children.length > 0) { let target = children[0]; @@ -354,79 +359,79 @@ class DesignerKeyboard extends Keyboard { } } - _goToNode(designer, node) { + private _goToNode(designer: Designer, node: Topic) { // First deselect all the nodes ... designer.deselectAll(); // Give focus to the selected node.... node.setOnFocus(true); } + + static register = function register(designer: Designer) { + this._instance = new DesignerKeyboard(designer); + }; + + static specialKeys = { + 8: 'backspace', + 9: 'tab', + 10: 'return', + 13: 'enter', + 16: 'shift', + 17: 'ctrl', + 18: 'alt', + 19: 'pause', + 20: 'capslock', + 27: 'esc', + 32: 'space', + 33: 'pageup', + 34: 'pagedown', + 35: 'end', + 36: 'home', + 37: 'left', + 38: 'up', + 39: 'right', + 40: 'down', + 45: 'insert', + 46: 'del', + 96: '0', + 97: '1', + 98: '2', + 99: '3', + 100: '4', + 101: '5', + 102: '6', + 103: '7', + 104: '8', + 105: '9', + 106: '*', + 107: '+', + 109: '-', + 110: '.', + 111: '/', + 112: 'f1', + 113: 'f2', + 114: 'f3', + 115: 'f4', + 116: 'f5', + 117: 'f6', + 118: 'f7', + 119: 'f8', + 120: 'f9', + 121: 'f10', + 122: 'f11', + 123: 'f12', + 144: 'numlock', + 145: 'scroll', + 186: ';', + 191: '/', + 220: '\\', + 222: "'", + 224: 'meta', + }; + + static getInstance() { + return this._instance; + } } -DesignerKeyboard.specialKeys = { - 8: 'backspace', - 9: 'tab', - 10: 'return', - 13: 'enter', - 16: 'shift', - 17: 'ctrl', - 18: 'alt', - 19: 'pause', - 20: 'capslock', - 27: 'esc', - 32: 'space', - 33: 'pageup', - 34: 'pagedown', - 35: 'end', - 36: 'home', - 37: 'left', - 38: 'up', - 39: 'right', - 40: 'down', - 45: 'insert', - 46: 'del', - 96: '0', - 97: '1', - 98: '2', - 99: '3', - 100: '4', - 101: '5', - 102: '6', - 103: '7', - 104: '8', - 105: '9', - 106: '*', - 107: '+', - 109: '-', - 110: '.', - 111: '/', - 112: 'f1', - 113: 'f2', - 114: 'f3', - 115: 'f4', - 116: 'f5', - 117: 'f6', - 118: 'f7', - 119: 'f8', - 120: 'f9', - 121: 'f10', - 122: 'f11', - 123: 'f12', - 144: 'numlock', - 145: 'scroll', - 186: ';', - 191: '/', - 220: '\\', - 222: "'", - 224: 'meta', -}; - -DesignerKeyboard.register = function register(designer) { - this._instance = new DesignerKeyboard(designer); -}; - -DesignerKeyboard.getInstance = function getInstance() { - return this._instance; -}; - export default DesignerKeyboard; diff --git a/packages/mindplot/src/components/Keyboard.js b/packages/mindplot/src/components/Keyboard.ts similarity index 100% rename from packages/mindplot/src/components/Keyboard.js rename to packages/mindplot/src/components/Keyboard.ts