mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
* N8N-3029 Add Node Type for Wokrflow Stickies/Notes * N8N-3029 Update Content, Update Aliasses * N8N-3030 Created N8N Sticky Component in Design System * N8N-3030 Fixed Code spaccing Sticky Component * N8N-3030 Fixed Code spaccing StickyStories Component * N8N-3030 Fixed Code spaccing Markdown Component * N8N-3030 Added Sticky Colors Pallete into Storybook, Update Color Variables for Sticky Component * N8N-3030 Added Unfocus Event * N8N-3030 Update Default Placeholder, Markdown Styles, Fixed Edit State, Added Text to EditState, Fixed Height of Area, Turned off Resize of textarea * N8N-3030 Update Sticky Overflow, Update Hover States, Updated Markdown Overflow * N8N-3030, N8N-3031 - Add Resize to Sticky, Created N8n-Resize component * N8N-3031 Fixed Importing Components in Editor-ui * N8N-3031 Fixed Resize Component, Fixed Gradient * N8N-3030, N8N-3031 Update Note Description * N8N-3032 Hotfix Building Storybook * N8N-3032 - Select Behaviour, Changes in Resize Component, Emit on Width/Height/Top/Left Change * N8N-3032 Update Resize Component to emmit left/top, Update Dynamic Resize on Selected Background * N8N-3032 Updated / Dragging vs Resizing, prevent open Modal for stickies * N8N-3032 Added ID props to n8n-sticky // dynamic id for multi resizing in NodeView * N8N-3033 Add dynamic size Tooltip on Sticky * N8N-3033 Updated Z-index for Sticky Component * N8N-3033 Updated N8N-Resize Component, Fixed SelectedBackround for Sticky Component * N8N-3033 Refactor * N8N-3033 Focus/Defocus on TextArea * N8N-3033 Fixed Resizing on NW Point * N8N-3030 Save content in vuex on input change * N8N-3033 Fixed Resizer, Save Width and Height in Vue * N8N-3033 Hide Sticky Footer on small height/width * N8N-3033 Fixed Resizer * N8N-3033 Dynamic Z-index for Stickies * N8N-3033 Dynamic Z-index for Stickies * N8N-3033 Removed static z-index for select sticky class * N8N-3034 Added Telemetry * N8N-3030 Formatter * N8N-3030 Format code * N8N-3030 Fixed Selecting Stickies * N8N-3033 Fixed Notifications * N8N-3030 Added new paddings for Default Stickies * N8N-3033 Prevent Scrolling NodeView when Sticky is in Edit mode and Mouse is Over the TextArea * N8N-3030 Prevent double clicking to switch state of Sticky component in Edit Mode * N8N-3033 Fixed Z-index of Stickies * N8N-3033 Prevent delete node when in EditMode * N8N-3030 Prevent Delete Button to delete the Sticky while in Edit Mode * N8N-3030 Change EditMode (emit) on keyboard shortucts, update Markdown Links & Images, Added new props * N8N-3030 Sticky Component - No padding when hiding footer text * N8N-3033 Fix Resizing enter into Edit Mode * N8N-3033 Selecting different nodes - exit the edit mode * N8N-3033 Auto Select Text in text-area by default - Sticky Component * N8N-3033 Prevent Default behaviour for CTRL + X, CTRL + A when Sticky is Active && inEditMode * N8N-3033 Refactor Resizer, Refactor Sticky, Update zIndex inEditMode * N8N-3033 Updated Default Text // Node-base, Storybook * N8N-3033 Add Resizing in EditMode - Components update * N8N-3033 Fixed Footer - Show/Hide on Resize in EditMode * N8N-3033 Fix ActiveSticky on Init * N8N-3033 Refactor Sticky in Vuex, Fixed Init Sticky Tweaks, Prevent Modal Openning, Save on Keyboard shortcuts * Stickies - Update Note node with new props * N8N-3030 Updated Default Note text, Update the Markdown Link * N8N-3030 CMD-C does not copy the text fix * N8N-3030 Fix Max Zoom / Zoom out shortcuts disabled in editState * N8N-3030 Z-index fixed during Edit Mode typing * N8N-3030 Prevent Autoselect Text in Stickies if the text is not default * N8N-3030 Fixed ReadOnly Bugs / Prevent showing Tooltip, Resizing * N8N-3030 Added Sticky Creator Button * N8N-3030 Update Icon / Sticky Creator Button * N8N-3033 Update Sticky Icon / StickyCreator Button * update package lock * 🔩 update note props * 🚿 clean props * 🔧 linting * 🔧 fix spacing * remove resize component * remove resize component * ✂ clean up sticky * revert back to height width * revert back to height/width * replace zindex property * replace default text property * use i18n to translate * update package lock * move resize * clean up how height/width are set * fix resize for sticky to support left/top * clean up resize * fix lasso/highlight bug * remove unused props * fix zoom to fit * fix padding for demo view * fix readonly * remove iseditable, use active state * clean up keyboard events * chang button size, no edit on insert * scale resizing correctly * make active on resize * fix select on resize/move * use outline icon * allow for multiple line breaks * fix multi line bug * fix edit mode outline * keep edit open as one resizes * respect multiple spaces * fix scrolling bug * clean up hover impl * clean up references to note * disable for rename * fix drifting while drag * fix mouse cursor on resize * fix sticky min height * refactor resize into component * fix pulling too far bug * fix delete/cut all bug * fix padding bottom * fix active change on resize * add transition to button * Fix sticky markdown click * add solid fa icon * update node graph, telemetry event * add snapping * change alt text * update package lock * fix bug in button hover * add back transition * clean up resize * add grid size as param * remove breaks * clean up markdown * lint fixes * fix spacing * clean up markdown colors * clean up classes in resize * clean up resize * update sticky story * fix spacing * clean up classes * revert change * revert change * revert change * clean up sticky component * remove unused component * remove unnessary data * remove unnessary data * clean up actions * clean up sticky size * clean up unnessary border style * fix bug * replace sticky note name * update description * remove support for multi spaces * update tracking name * update telemetry reqs * fix enter bug * update alt text * update sticky notes doc url * fix readonly bug * update class name * update quote marks Co-authored-by: SchnapsterDog <olivertrajceski@yahoo.com>
200 lines
6.1 KiB
TypeScript
200 lines
6.1 KiB
TypeScript
import { INodeUi, XYPosition } from '@/Interface';
|
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
import { deviceSupportHelpers } from '@/components/mixins/deviceSupportHelpers';
|
|
import { nodeIndex } from '@/components/mixins/nodeIndex';
|
|
import { getMousePosition, getRelativePosition } from '@/views/canvasHelpers';
|
|
|
|
export const mouseSelect = mixins(
|
|
deviceSupportHelpers,
|
|
nodeIndex,
|
|
).extend({
|
|
data () {
|
|
return {
|
|
selectActive: false,
|
|
selectBox: document.createElement('span'),
|
|
};
|
|
},
|
|
mounted () {
|
|
this.createSelectBox();
|
|
},
|
|
methods: {
|
|
createSelectBox () {
|
|
this.selectBox.id = 'select-box';
|
|
this.selectBox.style.margin = '0px auto';
|
|
this.selectBox.style.border = '2px dotted #FF0000';
|
|
// Positioned absolutely within #node-view. This is consistent with how nodes are positioned.
|
|
this.selectBox.style.position = 'absolute';
|
|
this.selectBox.style.zIndex = '100';
|
|
this.selectBox.style.visibility = 'hidden';
|
|
|
|
this.selectBox.addEventListener('mouseup', this.mouseUpMouseSelect);
|
|
|
|
const nodeViewEl = this.$el.querySelector('#node-view') as HTMLDivElement;
|
|
nodeViewEl.appendChild(this.selectBox);
|
|
},
|
|
isCtrlKeyPressed (e: MouseEvent | KeyboardEvent): boolean {
|
|
if (this.isTouchDevice === true) {
|
|
return true;
|
|
}
|
|
if (this.isMacOs) {
|
|
return e.metaKey;
|
|
}
|
|
return e.ctrlKey;
|
|
},
|
|
getMousePositionWithinNodeView (event: MouseEvent | TouchEvent): XYPosition {
|
|
const [x, y] = getMousePosition(event);
|
|
// @ts-ignore
|
|
return getRelativePosition(x, y, this.nodeViewScale, this.$store.getters.getNodeViewOffsetPosition);
|
|
},
|
|
showSelectBox (event: MouseEvent) {
|
|
const [x, y] = this.getMousePositionWithinNodeView(event);
|
|
this.selectBox = Object.assign(this.selectBox, {x, y});
|
|
|
|
// @ts-ignore
|
|
this.selectBox.style.left = this.selectBox.x + 'px';
|
|
// @ts-ignore
|
|
this.selectBox.style.top = this.selectBox.y + 'px';
|
|
this.selectBox.style.visibility = 'visible';
|
|
|
|
this.selectActive = true;
|
|
},
|
|
updateSelectBox (event: MouseEvent) {
|
|
const selectionBox = this.getSelectionBox(event);
|
|
this.selectBox.style.left = selectionBox.x + 'px';
|
|
this.selectBox.style.top = selectionBox.y + 'px';
|
|
|
|
this.selectBox.style.width = selectionBox.width + 'px';
|
|
this.selectBox.style.height = selectionBox.height + 'px';
|
|
},
|
|
hideSelectBox () {
|
|
this.selectBox.style.visibility = 'hidden';
|
|
// @ts-ignore
|
|
this.selectBox.x = 0;
|
|
// @ts-ignore
|
|
this.selectBox.y = 0;
|
|
this.selectBox.style.left = '0px';
|
|
this.selectBox.style.top = '0px';
|
|
this.selectBox.style.width = '0px';
|
|
this.selectBox.style.height = '0px';
|
|
|
|
this.selectActive = false;
|
|
},
|
|
getSelectionBox (event: MouseEvent) {
|
|
const [x, y] = this.getMousePositionWithinNodeView(event);
|
|
return {
|
|
// @ts-ignore
|
|
x: Math.min(x, this.selectBox.x),
|
|
// @ts-ignore
|
|
y: Math.min(y, this.selectBox.y),
|
|
// @ts-ignore
|
|
width: Math.abs(x - this.selectBox.x),
|
|
// @ts-ignore
|
|
height: Math.abs(y - this.selectBox.y),
|
|
};
|
|
},
|
|
getNodesInSelection (event: MouseEvent): INodeUi[] {
|
|
const returnNodes: INodeUi[] = [];
|
|
const selectionBox = this.getSelectionBox(event);
|
|
|
|
// Go through all nodes and check if they are selected
|
|
this.$store.getters.allNodes.forEach((node: INodeUi) => {
|
|
// TODO: Currently always uses the top left corner for checking. Should probably use the center instead
|
|
if (node.position[0] < selectionBox.x || node.position[0] > (selectionBox.x + selectionBox.width)) {
|
|
return;
|
|
}
|
|
if (node.position[1] < selectionBox.y || node.position[1] > (selectionBox.y + selectionBox.height)) {
|
|
return;
|
|
}
|
|
returnNodes.push(node);
|
|
});
|
|
|
|
return returnNodes;
|
|
},
|
|
mouseDownMouseSelect (e: MouseEvent) {
|
|
if (this.isCtrlKeyPressed(e) === true) {
|
|
// We only care about it when the ctrl key is not pressed at the same time.
|
|
// So we exit when it is pressed.
|
|
return;
|
|
}
|
|
|
|
if (this.$store.getters.isActionActive('dragActive')) {
|
|
// If a node does currently get dragged we do not activate the selection
|
|
return;
|
|
}
|
|
this.showSelectBox(e);
|
|
|
|
// @ts-ignore // Leave like this. Do not add a anonymous function because then remove would not work anymore
|
|
this.$el.addEventListener('mousemove', this.mouseMoveSelect);
|
|
},
|
|
mouseUpMouseSelect (e: MouseEvent) {
|
|
if (this.selectActive === false) {
|
|
if (this.isTouchDevice === true) {
|
|
// @ts-ignore
|
|
if (e.target && e.target.id.includes('node-view')) {
|
|
// Deselect all nodes
|
|
this.deselectAllNodes();
|
|
}
|
|
}
|
|
// If it is not active return direcly.
|
|
// Else normal node dragging will not work.
|
|
return;
|
|
}
|
|
|
|
// @ts-ignore
|
|
this.$el.removeEventListener('mousemove', this.mouseMoveSelect);
|
|
|
|
// Deselect all nodes
|
|
this.deselectAllNodes();
|
|
|
|
// Select the nodes which are in the selection box
|
|
const selectedNodes = this.getNodesInSelection(e);
|
|
selectedNodes.forEach((node) => {
|
|
this.nodeSelected(node);
|
|
});
|
|
|
|
if (selectedNodes.length === 1) {
|
|
this.$store.commit('setLastSelectedNode', selectedNodes[0].name);
|
|
}
|
|
|
|
this.hideSelectBox();
|
|
},
|
|
mouseMoveSelect (e: MouseEvent) {
|
|
if (e.buttons === 0) {
|
|
// Mouse button is not pressed anymore so stop selection mode
|
|
// Happens normally when mouse leave the view pressed and then
|
|
// comes back unpressed.
|
|
this.mouseUpMouseSelect(e);
|
|
return;
|
|
}
|
|
|
|
this.updateSelectBox(e);
|
|
},
|
|
|
|
nodeDeselected (node: INodeUi) {
|
|
this.$store.commit('removeNodeFromSelection', node);
|
|
const nodeElement = `node-${this.getNodeIndex(node.name)}`;
|
|
// @ts-ignore
|
|
this.instance.removeFromDragSelection(nodeElement);
|
|
},
|
|
nodeSelected (node: INodeUi) {
|
|
this.$store.commit('addSelectedNode', node);
|
|
const nodeElement = `node-${this.getNodeIndex(node.name)}`;
|
|
// @ts-ignore
|
|
this.instance.addToDragSelection(nodeElement);
|
|
},
|
|
deselectAllNodes () {
|
|
// @ts-ignore
|
|
this.instance.clearDragSelection();
|
|
this.$store.commit('resetSelectedNodes');
|
|
this.$store.commit('setLastSelectedNode', null);
|
|
this.$store.commit('setLastSelectedNodeOutputIndex', null);
|
|
// @ts-ignore
|
|
this.lastSelectedConnection = null;
|
|
// @ts-ignore
|
|
this.newNodeInsertPosition = null;
|
|
},
|
|
},
|
|
});
|