c3d469b5ed023ec9cd55a58a90e82eaf46ee0014ea44763c2e5441df9bc0d5fce76e0f105fc928c98bacc2b4fbd3ed5f3df2e95264c933f0b5b27d4fa34236 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { camelize } from "../util/string";
  2. import { events, isReadOnly } from "./sortableEvents";
  3. import { isHtmlAttribute } from "../util/tags";
  4. function project(entries) {
  5. return entries.reduce((res, [key, value]) => {
  6. res[key] = value;
  7. return res;
  8. }, {});
  9. }
  10. function getComponentAttributes({ $attrs, componentData = {} }) {
  11. const attributes = project(
  12. Object.entries($attrs).filter(([key, _]) => isHtmlAttribute(key))
  13. );
  14. return {
  15. ...attributes,
  16. ...componentData
  17. };
  18. }
  19. function createSortableOption({ $attrs, callBackBuilder }) {
  20. const options = project(getValidSortableEntries($attrs));
  21. Object.entries(callBackBuilder).forEach(([eventType, eventBuilder]) => {
  22. events[eventType].forEach(event => {
  23. options[`on${event}`] = eventBuilder(event);
  24. });
  25. });
  26. const draggable = `[data-draggable]${options.draggable || ""}`;
  27. return {
  28. ...options,
  29. draggable
  30. };
  31. }
  32. function getValidSortableEntries(value) {
  33. return Object.entries(value)
  34. .filter(([key, _]) => !isHtmlAttribute(key))
  35. .map(([key, value]) => [camelize(key), value])
  36. .filter(([key, _]) => !isReadOnly(key));
  37. }
  38. export {
  39. getComponentAttributes,
  40. createSortableOption,
  41. getValidSortableEntries
  42. };