-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yan Heng
committed
Aug 26, 2023
1 parent
6f4d3f5
commit 39715d8
Showing
18 changed files
with
281 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@pictode/plugin-selector", | ||
"private": true, | ||
"version": "0.0.1", | ||
"main": "dist/pictode-plugin-selector.umd.js", | ||
"module": "dist/pictode-plugin-selector.mjs", | ||
"types": "types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/pictode-plugin-selector.mjs", | ||
"require": "./dist/pictode-plugin-selector.umd.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "npm run build:type && vite build", | ||
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json", | ||
"clear:type": "rimraf ./types" | ||
}, | ||
"dependencies": { | ||
"@pictode/core": "workspace:^0.0.1", | ||
"@pictode/utils": "workspace:^0.0.1", | ||
"dot": "2.0.0-beta.1", | ||
"rimraf": "^3.0.2", | ||
"roughjs": "^4.5.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.3", | ||
"vite": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { App, Plugin } from '@pictode/core'; | ||
|
||
import './methods'; | ||
|
||
import Selector from './selector'; | ||
import { Options } from './types'; | ||
|
||
export class SelectorPlugin implements Plugin { | ||
public name: string = 'selectorPlugin'; | ||
public selector?: Selector; | ||
public app?: App; | ||
public options?: Options; | ||
|
||
constructor(options?: Options) { | ||
this.options = options; | ||
} | ||
|
||
public install(app: App) { | ||
this.app = app; | ||
this.selector = new Selector(app, this.options); | ||
this.selector.app = app; | ||
this.app.emit('selector:installed', { selector: this }); | ||
} | ||
|
||
public destroy(): void { | ||
this.selector?.destroy(); | ||
this.app?.emit('selector:destroy', { selector: this }); | ||
} | ||
|
||
public enable(): void { | ||
if (!this.selector) { | ||
return; | ||
} | ||
this.selector.triggerSelector(true); | ||
} | ||
|
||
public disable(): void { | ||
if (!this.selector) { | ||
return; | ||
} | ||
this.selector.cancelSelect(); | ||
this.selector.triggerSelector(false); | ||
} | ||
|
||
public isEnabled(): boolean { | ||
return this.selector?.enable ?? false; | ||
} | ||
} | ||
|
||
export default SelectorPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { App, Konva, KonvaMouseEvent, KonvaNode } from '@pictode/core'; | ||
|
||
import { SelectorPlugin } from './index'; | ||
|
||
Object.defineProperty(App.prototype, 'selected', { | ||
get() { | ||
const selectorPlugin = this.getPlugin('selectorPlugin') as SelectorPlugin; | ||
if (selectorPlugin) { | ||
return [...(selectorPlugin.selector?.selected.values() ?? [])]; | ||
} | ||
return []; | ||
}, | ||
}); | ||
|
||
App.prototype.select = function (...nodes: KonvaNode[]): App { | ||
const selectorPlugin = this.getPlugin('selectorPlugin') as SelectorPlugin; | ||
if (selectorPlugin) { | ||
selectorPlugin.selector?.select(...nodes); | ||
} | ||
return this; | ||
}; | ||
|
||
App.prototype.cancelSelect = function (...nodes: KonvaNode[]): App { | ||
const selectorPlugin = this.getPlugin('selectorPlugin') as SelectorPlugin; | ||
if (selectorPlugin) { | ||
selectorPlugin.selector?.cancelSelect(...nodes); | ||
} | ||
return this; | ||
}; | ||
|
||
App.prototype.selectByEvent = function (event: KonvaMouseEvent): App { | ||
const selectorPlugin = this.getPlugin('selectorPlugin') as SelectorPlugin; | ||
if (selectorPlugin) { | ||
if (event.target instanceof Konva.Stage) { | ||
this.cancelSelect(); | ||
} else { | ||
this.select(event.target); | ||
} | ||
} | ||
return this; | ||
}; |
Oops, something went wrong.