config.mjs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import { h } from 'vue';
  2. import { ElCheckbox } from '../../checkbox/index.mjs';
  3. import { ElIcon } from '../../icon/index.mjs';
  4. import { ArrowRight, Loading } from '@element-plus/icons-vue';
  5. import { isNumber, isBoolean } from '../../../utils/types.mjs';
  6. import { isFunction } from '@vue/shared';
  7. import { getProp } from '../../../utils/objects.mjs';
  8. const defaultClassNames = {
  9. selection: "table-column--selection",
  10. expand: "table__expand-column"
  11. };
  12. const cellStarts = {
  13. default: {
  14. order: ""
  15. },
  16. selection: {
  17. width: 48,
  18. minWidth: 48,
  19. realWidth: 48,
  20. order: ""
  21. },
  22. expand: {
  23. width: 48,
  24. minWidth: 48,
  25. realWidth: 48,
  26. order: ""
  27. },
  28. index: {
  29. width: 48,
  30. minWidth: 48,
  31. realWidth: 48,
  32. order: ""
  33. }
  34. };
  35. const getDefaultClassName = (type) => {
  36. return defaultClassNames[type] || "";
  37. };
  38. const cellForced = {
  39. selection: {
  40. renderHeader({ store }) {
  41. var _a;
  42. function isDisabled() {
  43. return store.states.data.value && store.states.data.value.length === 0;
  44. }
  45. return h(ElCheckbox, {
  46. disabled: isDisabled(),
  47. size: store.states.tableSize.value,
  48. indeterminate: store.states.selection.value.length > 0 && !store.states.isAllSelected.value,
  49. "onUpdate:modelValue": (_a = store.toggleAllSelection) != null ? _a : void 0,
  50. modelValue: store.states.isAllSelected.value,
  51. ariaLabel: store.t("el.table.selectAllLabel")
  52. });
  53. },
  54. renderCell({
  55. row,
  56. column,
  57. store,
  58. $index
  59. }) {
  60. return h(ElCheckbox, {
  61. disabled: column.selectable ? !column.selectable.call(null, row, $index) : false,
  62. size: store.states.tableSize.value,
  63. onChange: () => {
  64. store.commit("rowSelectedChanged", row);
  65. },
  66. onClick: (event) => event.stopPropagation(),
  67. modelValue: store.isSelected(row),
  68. ariaLabel: store.t("el.table.selectRowLabel")
  69. });
  70. },
  71. sortable: false,
  72. resizable: false
  73. },
  74. index: {
  75. renderHeader({
  76. column
  77. }) {
  78. return column.label || "#";
  79. },
  80. renderCell({
  81. column,
  82. $index
  83. }) {
  84. let i = $index + 1;
  85. const index = column.index;
  86. if (isNumber(index)) {
  87. i = $index + index;
  88. } else if (isFunction(index)) {
  89. i = index($index);
  90. }
  91. return h("div", {}, [i]);
  92. },
  93. sortable: false
  94. },
  95. expand: {
  96. renderHeader({
  97. column
  98. }) {
  99. return column.label || "";
  100. },
  101. renderCell({
  102. column,
  103. row,
  104. store,
  105. expanded
  106. }) {
  107. const { ns } = store;
  108. const classes = [ns.e("expand-icon")];
  109. if (!column.renderExpand && expanded) {
  110. classes.push(ns.em("expand-icon", "expanded"));
  111. }
  112. const callback = function(e) {
  113. e.stopPropagation();
  114. store.toggleRowExpansion(row);
  115. };
  116. return h(
  117. "button",
  118. {
  119. type: "button",
  120. "aria-label": store.t(
  121. expanded ? "el.table.collapseRowLabel" : "el.table.expandRowLabel"
  122. ),
  123. "aria-expanded": expanded,
  124. class: classes,
  125. onClick: callback
  126. },
  127. {
  128. default: () => {
  129. if (column.renderExpand) {
  130. return [
  131. column.renderExpand({
  132. expanded
  133. })
  134. ];
  135. }
  136. return [
  137. h(ElIcon, null, {
  138. default: () => {
  139. return [h(ArrowRight)];
  140. }
  141. })
  142. ];
  143. }
  144. }
  145. );
  146. },
  147. sortable: false,
  148. resizable: false
  149. }
  150. };
  151. function defaultRenderCell({
  152. row,
  153. column,
  154. $index
  155. }) {
  156. var _a;
  157. const property = column.property;
  158. const value = property && getProp(row, property).value;
  159. if (column && column.formatter) {
  160. return column.formatter(row, column, value, $index);
  161. }
  162. return ((_a = value == null ? void 0 : value.toString) == null ? void 0 : _a.call(value)) || "";
  163. }
  164. function treeCellPrefix({
  165. row,
  166. treeNode,
  167. store
  168. }, createPlaceholder = false) {
  169. const { ns } = store;
  170. if (!treeNode) {
  171. if (createPlaceholder) {
  172. return [
  173. h("span", {
  174. class: ns.e("placeholder")
  175. })
  176. ];
  177. }
  178. return null;
  179. }
  180. const ele = [];
  181. const callback = function(e) {
  182. e.stopPropagation();
  183. if (treeNode.loading) {
  184. return;
  185. }
  186. store.loadOrToggle(row);
  187. };
  188. if (treeNode.indent) {
  189. ele.push(
  190. h("span", {
  191. class: ns.e("indent"),
  192. style: { "padding-left": `${treeNode.indent}px` }
  193. })
  194. );
  195. }
  196. if (isBoolean(treeNode.expanded) && !treeNode.noLazyChildren) {
  197. const expandClasses = [
  198. ns.e("expand-icon"),
  199. treeNode.expanded ? ns.em("expand-icon", "expanded") : ""
  200. ];
  201. let icon = ArrowRight;
  202. if (treeNode.loading) {
  203. icon = Loading;
  204. }
  205. ele.push(
  206. h(
  207. "button",
  208. {
  209. type: "button",
  210. "aria-label": store.t(
  211. treeNode.expanded ? "el.table.collapseRowLabel" : "el.table.expandRowLabel"
  212. ),
  213. "aria-expanded": treeNode.expanded,
  214. class: expandClasses,
  215. onClick: callback
  216. },
  217. {
  218. default: () => {
  219. return [
  220. h(
  221. ElIcon,
  222. { class: ns.is("loading", treeNode.loading) },
  223. {
  224. default: () => [h(icon)]
  225. }
  226. )
  227. ];
  228. }
  229. }
  230. )
  231. );
  232. } else {
  233. ele.push(
  234. h("span", {
  235. class: ns.e("placeholder")
  236. })
  237. );
  238. }
  239. return ele;
  240. }
  241. export { cellForced, cellStarts, defaultRenderCell, getDefaultClassName, treeCellPrefix };
  242. //# sourceMappingURL=config.mjs.map