-
Notifications
You must be signed in to change notification settings - Fork 546
/
Copy pathcomponentBuilderHelper.js
47 lines (42 loc) · 1.2 KB
/
componentBuilderHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { camelize } from "../util/string";
import { events, isReadOnly } from "./sortableEvents";
import { isHtmlAttribute } from "../util/tags";
function project(entries) {
return entries.reduce((res, [key, value]) => {
res[key] = value;
return res;
}, {});
}
function getComponentAttributes({ $attrs, componentData = {} }) {
const attributes = project(
Object.entries($attrs).filter(([key, _]) => isHtmlAttribute(key))
);
return {
...attributes,
...componentData
};
}
function createSortableOption({ $attrs, callBackBuilder }) {
const options = project(getValidSortableEntries($attrs));
Object.entries(callBackBuilder).forEach(([eventType, eventBuilder]) => {
events[eventType].forEach(event => {
options[`on${event}`] = eventBuilder(event);
});
});
const draggable = `[data-draggable]${options.draggable || ""}`;
return {
...options,
draggable
};
}
function getValidSortableEntries(value) {
return Object.entries(value)
.filter(([key, _]) => !isHtmlAttribute(key))
.map(([key, value]) => [camelize(key), value])
.filter(([key, _]) => !isReadOnly(key));
}
export {
getComponentAttributes,
createSortableOption,
getValidSortableEntries
};