1
1
import { capitalize } from "../util/string" ;
2
2
import { camelize } from "../util/string" ;
3
- import { events } from "./sortableEvents" ;
3
+ import { events , isReadOnlyEvent } from "./sortableEvents" ;
4
+
5
+ function isHtmlAttribute ( value ) {
6
+ return [ "id" , "class" ] . includes ( value ) || value . startsWith ( "data-" ) ;
7
+ }
4
8
5
9
function getComponentAttributes ( $attrs , componentData ) {
6
10
const attributes = Object . entries ( $attrs )
7
- . filter (
8
- ( [ key , _ ] ) => [ "id" , "class" ] . includes ( key ) || key . startsWith ( "data-" )
9
- )
11
+ . filter ( ( [ key , _ ] ) => isHtmlAttribute ( key ) )
10
12
. reduce ( ( res , [ key , value ] ) => {
11
13
res [ key ] = value ;
12
14
return res ;
@@ -22,27 +24,22 @@ function getComponentAttributes($attrs, componentData) {
22
24
return { ...attributes , ...attrs , ...props } ;
23
25
}
24
26
25
- function getDraggableOption ( {
26
- $attrs,
27
- callBackBuilder : { manageAndEmit, emit, manage }
28
- } ) {
27
+ function getSortableOption ( { $attrs, callBackBuilder } ) {
29
28
const options = {
30
29
draggable : ">*"
31
30
} ;
32
- Object . entries ( $attrs ) . forEach ( ( [ key , value ] ) => {
33
- options [ camelize ( key ) ] = value ;
34
- } ) ;
35
- const builders = {
36
- emit,
37
- manageAndEmit,
38
- manage
39
- } ;
40
- Object . entries ( builders ) . forEach ( ( [ eventType , eventBuilder ] ) => {
31
+ Object . entries ( $attrs )
32
+ . map ( ( [ key , value ] ) => [ camelize ( key ) , value ] )
33
+ . filter ( ( [ key , _ ] ) => ! isHtmlAttribute ( key ) && ! isReadOnlyEvent ( key ) )
34
+ . forEach ( ( [ key , value ] ) => {
35
+ options [ key ] = value ;
36
+ } ) ;
37
+ Object . entries ( callBackBuilder ) . forEach ( ( [ eventType , eventBuilder ] ) => {
41
38
events [ eventType ] . forEach ( event => {
42
39
options [ `on${ event } ` ] = eventBuilder ( event ) ;
43
40
} ) ;
44
41
} ) ;
45
42
return options ;
46
43
}
47
44
48
- export { getComponentAttributes , getDraggableOption } ;
45
+ export { getComponentAttributes , getSortableOption } ;
0 commit comments