forked from simonwep/selection
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
42 changed files
with
1,447 additions
and
1,286 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
node_modules | ||
lib | ||
dist | ||
.psd | ||
*.iml | ||
.idea/ | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,44 @@ | ||
/* eslint-disable no-use-before-define */ | ||
import VanillaSelectionArea from '@viselect/vanilla'; | ||
import {SelectionEvents, SelectionOptions} from '@viselect/vanilla'; | ||
import {createRef, FunctionalComponent} from 'preact'; | ||
import {HTMLAttributes} from 'preact/compat'; | ||
import {useEffect} from 'preact/hooks'; | ||
|
||
export interface SelectionAreaProps extends Omit<Partial<SelectionOptions>, 'boundaries'>, HTMLAttributes<HTMLDivElement> { | ||
id?: string; | ||
className?: string; | ||
onBeforeStart?: SelectionEvents['beforestart']; | ||
onBeforeDrag?: SelectionEvents['beforedrag']; | ||
onStart?: SelectionEvents['start']; | ||
onMove?: SelectionEvents['move']; | ||
onStop?: SelectionEvents['stop']; | ||
} | ||
|
||
export const SelectionArea: FunctionalComponent<SelectionAreaProps> = props => { | ||
const root = createRef(); | ||
|
||
useEffect(() => { | ||
const {onBeforeStart, onBeforeDrag, onStart, onMove, onStop, ...opt} = props; | ||
const areaBoundaries = root.current as HTMLElement; | ||
|
||
const selection = new VanillaSelectionArea({ | ||
boundaries: areaBoundaries, | ||
...opt | ||
}); | ||
|
||
onBeforeStart && selection.on('beforestart', onBeforeStart); | ||
onBeforeDrag && selection.on('beforedrag', onBeforeDrag); | ||
onStart && selection.on('start', onStart); | ||
onMove && selection.on('move', onMove); | ||
onStop && selection.on('stop', onStop); | ||
|
||
return () => selection.destroy(); | ||
}, []); | ||
|
||
return ( | ||
<div ref={root} className={props.className} id={props.id}> | ||
{props.children} | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {SelectionArea} from '@react/SelectionArea'; | ||
export {default as VanillaSelectionArea} from '@vanilla/index'; | ||
export * from '@vanilla/types'; | ||
import {SelectionArea} from './SelectionArea'; | ||
export {default as VanillaSelectionArea} from '@viselect/vanilla'; | ||
export * from '@viselect/vanilla'; | ||
export default SelectionArea; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/// <reference types="vite/client" /> | ||
declare const VERSION: string; |
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["./src", "./demo"], | ||
"compilerOptions": { | ||
"declarationDir": "lib", | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"jsx": "react" | ||
} | ||
"references": [{ "path": "./tsconfig.node.json" }], | ||
"include": ["src", "demo"], | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "preact" | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"include": ["vite.config.ts"], | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,46 @@ | ||
import preact from '@preact/preset-vite'; | ||
import {resolve} from 'path'; | ||
import {defineConfig} from 'vite'; | ||
import banner from 'vite-plugin-banner'; | ||
import dts from 'vite-plugin-dts'; | ||
import {version} from './package.json'; | ||
|
||
export default defineConfig({ | ||
root: './demo', | ||
const header = `/*! @viselect/preact v${version} MIT | https://github.com/Simonwep/selection/tree/master/packages/preact */`; | ||
|
||
plugins: [preact()], | ||
export default defineConfig(env => ({ | ||
root: env.mode === 'production' ? '.' : './demo', | ||
|
||
plugins: [preact(), banner(header), dts()], | ||
|
||
resolve: { | ||
alias: { | ||
'@vanilla': resolve(__dirname, '../vanilla/src'), | ||
'@react': resolve(__dirname, '../react/src'), | ||
'react': 'preact', | ||
'react-dom': 'preact/compat' | ||
'react': 'preact/compat' | ||
} | ||
}, | ||
|
||
build: { | ||
sourcemap: true, | ||
minify: 'esbuild', | ||
lib: { | ||
entry: 'src/index.tsx', | ||
name: 'SelectionArea', | ||
fileName: 'viselect', | ||
}, | ||
rollupOptions: { | ||
external: ['preact', '@viselect/react'], | ||
output: { | ||
globals: { | ||
preact: 'Preact', | ||
'@viselect/react': 'SelectionArea' | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
server: { | ||
port: 3007 | ||
port: 3006 | ||
}, | ||
|
||
define: { | ||
'VERSION': JSON.stringify(version) | ||
} | ||
}); | ||
})); |
Oops, something went wrong.