items.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Utilities
  2. import { computed } from 'vue';
  3. import { getPropertyFromItem, propsFactory } from "../../../util/index.mjs"; // Types
  4. // Composables
  5. export const makeDataIteratorItemsProps = propsFactory({
  6. items: {
  7. type: Array,
  8. default: () => []
  9. },
  10. itemValue: {
  11. type: [String, Array, Function],
  12. default: 'id'
  13. },
  14. itemSelectable: {
  15. type: [String, Array, Function],
  16. default: null
  17. },
  18. returnObject: Boolean
  19. }, 'DataIterator-items');
  20. export function transformItem(props, item) {
  21. const value = props.returnObject ? item : getPropertyFromItem(item, props.itemValue);
  22. const selectable = getPropertyFromItem(item, props.itemSelectable, true);
  23. return {
  24. type: 'item',
  25. value,
  26. selectable,
  27. raw: item
  28. };
  29. }
  30. export function transformItems(props, items) {
  31. const array = [];
  32. for (const item of items) {
  33. array.push(transformItem(props, item));
  34. }
  35. return array;
  36. }
  37. export function useDataIteratorItems(props) {
  38. const items = computed(() => transformItems(props, props.items));
  39. return {
  40. items
  41. };
  42. }
  43. //# sourceMappingURL=items.mjs.map