Skip to content

Commit

Permalink
feat: add selectionContainer options, mouseSelectionButton options is…
Browse files Browse the repository at this point in the history
… WIP
  • Loading branch information
SSShooter committed Oct 16, 2024
1 parent d9a7720 commit af769d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const options: Options = {
direction: MindElixir.SIDE,
// direction: MindElixir.RIGHT,
locale: 'en',
mouseSelectionButton: 2,
draggable: true,
editable: true,
contextMenu: true,
Expand Down Expand Up @@ -66,6 +67,7 @@ mind.init(example)

const m2 = new MindElixir({
el: '#map2',
selectionContainer: 'body', // use body to make selection usable when transform is not 0
})
m2.init(data)

Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function MindElixir(
toolBar,
keypress,
mouseSelectionButton,
selectionContainer,
before,
newTopicName,
allowUndo,
Expand Down Expand Up @@ -81,6 +82,8 @@ function MindElixir(
this.bus = Bus.create()

this.container = $d.createElement('div') // map container
this.selectionContainer = selectionContainer || this.container

this.container.className = 'map-container'

const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
Expand Down
6 changes: 4 additions & 2 deletions src/plugin/selection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { Trigger } from '@viselect/vanilla'
import SelectionArea from '@viselect/vanilla'
import type { MindElixirInstance, Topic } from '..'
import dragMoveHelper from '../utils/dragMoveHelper'

export default function (mei: MindElixirInstance) {
const triggers: Trigger[] = mei.mouseSelectionButton === 2 ? [{ button: 0, modifiers: ['ctrl'] }, 2] : [0]
const selection = new SelectionArea({
selectables: ['.map-container me-tpc'],
boundaries: [mei.container],
container: 'body',
container: mei.selectionContainer,
behaviour: {
triggers,
// Scroll configuration.
scrolling: {
// On scrollable areas the number on px per frame is devided by this amount.
Expand All @@ -24,7 +27,6 @@ export default function (mei: MindElixirInstance) {
},
})
.on('beforestart', ({ event }) => {
if ((event as MouseEvent).button !== mei.mouseSelectionButton) return false
if (((event as MouseEvent).target as Topic).tagName === 'ME-TPC') return false
if (((event as MouseEvent).target as HTMLElement).id === 'input-box') return false
if (((event as MouseEvent).target as HTMLElement).className === 'circle') return false
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface MindElixirInstance extends MindElixirMethods {
redo: () => void

selection: SelectionArea
selectionContainer?: string | HTMLElement
}
type PathString = string
/**
Expand Down Expand Up @@ -132,6 +133,7 @@ export type Options = {
mobileMenu?: boolean
theme?: Theme
nodeMenu?: boolean
selectionContainer?: string | HTMLElement
}

export type Uid = string
Expand Down

0 comments on commit af769d4

Please sign in to comment.