useDisplayValues.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _treeUtil = require("../utils/treeUtil");
  7. var _commonUtil = require("../utils/commonUtil");
  8. var _vue = require("vue");
  9. var _propsUtil = require("../../_util/props-util");
  10. var _vnode = require("../../_util/vnode");
  11. var _default = (rawValues, options, fieldNames, multiple, displayRender) => {
  12. return (0, _vue.computed)(() => {
  13. const mergedDisplayRender = displayRender.value || (
  14. // Default displayRender
  15. _ref => {
  16. let {
  17. labels
  18. } = _ref;
  19. const mergedLabels = multiple.value ? labels.slice(-1) : labels;
  20. const SPLIT = ' / ';
  21. if (mergedLabels.every(label => ['string', 'number'].includes(typeof label))) {
  22. return mergedLabels.join(SPLIT);
  23. }
  24. // If exist non-string value, use VueNode instead
  25. return mergedLabels.reduce((list, label, index) => {
  26. const keyedLabel = (0, _propsUtil.isValidElement)(label) ? (0, _vnode.cloneElement)(label, {
  27. key: index
  28. }) : label;
  29. if (index === 0) {
  30. return [keyedLabel];
  31. }
  32. return [...list, SPLIT, keyedLabel];
  33. }, []);
  34. });
  35. return rawValues.value.map(valueCells => {
  36. const valueOptions = (0, _treeUtil.toPathOptions)(valueCells, options.value, fieldNames.value);
  37. const label = mergedDisplayRender({
  38. labels: valueOptions.map(_ref2 => {
  39. let {
  40. option,
  41. value
  42. } = _ref2;
  43. var _a;
  44. return (_a = option === null || option === void 0 ? void 0 : option[fieldNames.value.label]) !== null && _a !== void 0 ? _a : value;
  45. }),
  46. selectedOptions: valueOptions.map(_ref3 => {
  47. let {
  48. option
  49. } = _ref3;
  50. return option;
  51. })
  52. });
  53. const value = (0, _commonUtil.toPathKey)(valueCells);
  54. return {
  55. label,
  56. value,
  57. key: value,
  58. valueCells
  59. };
  60. });
  61. });
  62. };
  63. exports.default = _default;