1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | Object.defineProperty(exports, "ListItemProps", {
|
7 | enumerable: true,
|
8 | get: function get() {
|
9 | return _Item.ListItemProps;
|
10 | }
|
11 | });
|
12 | Object.defineProperty(exports, "ListItemMetaProps", {
|
13 | enumerable: true,
|
14 | get: function get() {
|
15 | return _Item.ListItemMetaProps;
|
16 | }
|
17 | });
|
18 | Object.defineProperty(exports, "ListItemMeta", {
|
19 | enumerable: true,
|
20 | get: function get() {
|
21 | return _Item.ListItemMeta;
|
22 | }
|
23 | });
|
24 | exports.default = exports.ListProps = exports.ListSize = exports.ListGridType = exports.ColumnType = exports.ColumnCount = void 0;
|
25 |
|
26 | var _vue = require("vue");
|
27 |
|
28 | var _omit = _interopRequireDefault(require("omit.js"));
|
29 |
|
30 | var _vueTypes = _interopRequireWildcard(require("../_util/vue-types"));
|
31 |
|
32 | var _classNames2 = _interopRequireDefault(require("../_util/classNames"));
|
33 |
|
34 | var _configProvider = require("../config-provider");
|
35 |
|
36 | var _spin = _interopRequireDefault(require("../spin"));
|
37 |
|
38 | var _pagination = _interopRequireWildcard(require("../pagination"));
|
39 |
|
40 | var _grid = require("../grid");
|
41 |
|
42 | var _Item = _interopRequireWildcard(require("./Item"));
|
43 |
|
44 | var _propsUtil = require("../_util/props-util");
|
45 |
|
46 | var _initDefaultProps = _interopRequireDefault(require("../_util/props-util/initDefaultProps"));
|
47 |
|
48 | var _vnode = require("../_util/vnode");
|
49 |
|
50 | var _type = require("../_util/type");
|
51 |
|
52 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
53 |
|
54 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
55 |
|
56 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
57 |
|
58 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
59 |
|
60 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
61 |
|
62 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
63 |
|
64 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
65 |
|
66 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
67 |
|
68 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
69 |
|
70 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
71 |
|
72 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
73 |
|
74 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
75 |
|
76 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
77 |
|
78 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
79 |
|
80 | var __rest = void 0 && (void 0).__rest || function (s, e) {
|
81 | var t = {};
|
82 |
|
83 | for (var p in s) {
|
84 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
85 | }
|
86 |
|
87 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
88 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
89 | }
|
90 | return t;
|
91 | };
|
92 |
|
93 | function _isSlot(s) {
|
94 | return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !(0, _vue.isVNode)(s);
|
95 | }
|
96 |
|
97 | var ColumnCount = ['', 1, 2, 3, 4, 6, 8, 12, 24];
|
98 | exports.ColumnCount = ColumnCount;
|
99 | var ColumnType = ['gutter', 'column', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
|
100 | exports.ColumnType = ColumnType;
|
101 | var ListGridType = {
|
102 | gutter: _vueTypes.default.number,
|
103 | column: _vueTypes.default.oneOf(ColumnCount),
|
104 | xs: _vueTypes.default.oneOf(ColumnCount),
|
105 | sm: _vueTypes.default.oneOf(ColumnCount),
|
106 | md: _vueTypes.default.oneOf(ColumnCount),
|
107 | lg: _vueTypes.default.oneOf(ColumnCount),
|
108 | xl: _vueTypes.default.oneOf(ColumnCount),
|
109 | xxl: _vueTypes.default.oneOf(ColumnCount)
|
110 | };
|
111 | exports.ListGridType = ListGridType;
|
112 | var ListSize = (0, _type.tuple)('small', 'default', 'large');
|
113 | exports.ListSize = ListSize;
|
114 | var paginationProps = (0, _pagination.PaginationConfig)();
|
115 |
|
116 | var ListProps = function ListProps() {
|
117 | return {
|
118 | bordered: _vueTypes.default.looseBool,
|
119 | dataSource: _vueTypes.default.array,
|
120 | extra: _vueTypes.default.any,
|
121 | grid: _vueTypes.default.shape(ListGridType).loose,
|
122 | itemLayout: _vueTypes.default.string,
|
123 | loading: (0, _vueTypes.withUndefined)(_vueTypes.default.oneOfType([_vueTypes.default.looseBool, _vueTypes.default.object])),
|
124 | loadMore: _vueTypes.default.any,
|
125 | pagination: (0, _vueTypes.withUndefined)(_vueTypes.default.oneOfType([_vueTypes.default.shape(paginationProps).loose, _vueTypes.default.looseBool])),
|
126 | prefixCls: _vueTypes.default.string,
|
127 | rowKey: _vueTypes.default.any,
|
128 | renderItem: _vueTypes.default.any,
|
129 | size: _vueTypes.default.oneOf(ListSize),
|
130 | split: _vueTypes.default.looseBool,
|
131 | header: _vueTypes.default.any,
|
132 | footer: _vueTypes.default.any,
|
133 | locale: _vueTypes.default.object
|
134 | };
|
135 | };
|
136 |
|
137 | exports.ListProps = ListProps;
|
138 | var List = (0, _vue.defineComponent)({
|
139 | name: 'AList',
|
140 | inheritAttrs: false,
|
141 | Item: _Item.default,
|
142 | props: (0, _initDefaultProps.default)(ListProps(), {
|
143 | dataSource: [],
|
144 | bordered: false,
|
145 | split: true,
|
146 | loading: false,
|
147 | pagination: false
|
148 | }),
|
149 | setup: function setup() {
|
150 | return {
|
151 | keys: [],
|
152 | defaultPaginationProps: {},
|
153 | onPaginationChange: null,
|
154 | onPaginationShowSizeChange: null,
|
155 | configProvider: (0, _vue.inject)('configProvider', _configProvider.defaultConfigProvider)
|
156 | };
|
157 | },
|
158 | data: function data() {
|
159 | var pagination = this.$props.pagination;
|
160 | var paginationObj = pagination && _typeof(pagination) === 'object' ? pagination : {};
|
161 | return {
|
162 | paginationCurrent: paginationObj.defaultCurrent || 1,
|
163 | paginationSize: paginationObj.defaultPageSize || 10
|
164 | };
|
165 | },
|
166 | created: function created() {
|
167 | var _this = this;
|
168 |
|
169 | (0, _vue.provide)('listContext', this);
|
170 | this.defaultPaginationProps = {
|
171 | current: 1,
|
172 | pageSize: 10,
|
173 | onChange: function onChange(page, pageSize) {
|
174 | var pagination = _this.pagination;
|
175 | _this.paginationCurrent = page;
|
176 |
|
177 | if (pagination && pagination.onChange) {
|
178 | pagination.onChange(page, pageSize);
|
179 | }
|
180 | },
|
181 | total: 0
|
182 | };
|
183 | this.onPaginationChange = this.triggerPaginationEvent('onChange');
|
184 | this.onPaginationShowSizeChange = this.triggerPaginationEvent('onShowSizeChange');
|
185 | },
|
186 | methods: {
|
187 | triggerPaginationEvent: function triggerPaginationEvent(eventName) {
|
188 | var _this2 = this;
|
189 |
|
190 | return function (page, pageSize) {
|
191 | var pagination = _this2.$props.pagination;
|
192 | _this2.paginationCurrent = page;
|
193 | _this2.paginationSize = pageSize;
|
194 |
|
195 | if (pagination && pagination[eventName]) {
|
196 | pagination[eventName](page, pageSize);
|
197 | }
|
198 | };
|
199 | },
|
200 | innerRenderItem: function innerRenderItem(item, index) {
|
201 | var renderItem = this.$slots.renderItem,
|
202 | rowKey = this.rowKey;
|
203 | var renderer = this.renderItem || renderItem;
|
204 | if (!renderer) return null;
|
205 | var key;
|
206 |
|
207 | if (typeof rowKey === 'function') {
|
208 | key = rowKey(item);
|
209 | } else if (typeof rowKey === 'string') {
|
210 | key = item[rowKey];
|
211 | } else {
|
212 | key = item.key;
|
213 | }
|
214 |
|
215 | if (!key) {
|
216 | key = "list-item-".concat(index);
|
217 | }
|
218 |
|
219 | this.keys[index] = key;
|
220 | return renderer({
|
221 | item: item,
|
222 | index: index
|
223 | });
|
224 | },
|
225 | isSomethingAfterLastItem: function isSomethingAfterLastItem() {
|
226 | var pagination = this.pagination;
|
227 | var loadMore = (0, _propsUtil.getComponent)(this, 'loadMore');
|
228 | var footer = (0, _propsUtil.getComponent)(this, 'footer');
|
229 | return !!(loadMore || pagination || footer);
|
230 | },
|
231 | renderEmpty: function renderEmpty(prefixCls, _renderEmpty) {
|
232 | var locale = this.locale;
|
233 | return (0, _vue.createVNode)("div", {
|
234 | "class": "".concat(prefixCls, "-empty-text")
|
235 | }, [locale && locale.emptyText || _renderEmpty('List')]);
|
236 | }
|
237 | },
|
238 | render: function render() {
|
239 | var _classNames,
|
240 | _this3 = this;
|
241 |
|
242 | var customizePrefixCls = this.prefixCls,
|
243 | bordered = this.bordered,
|
244 | split = this.split,
|
245 | itemLayout = this.itemLayout,
|
246 | pagination = this.pagination,
|
247 | grid = this.grid,
|
248 | _this$dataSource = this.dataSource,
|
249 | dataSource = _this$dataSource === void 0 ? [] : _this$dataSource,
|
250 | size = this.size,
|
251 | loading = this.loading,
|
252 | paginationCurrent = this.paginationCurrent,
|
253 | paginationSize = this.paginationSize,
|
254 | $attrs = this.$attrs;
|
255 | var getPrefixCls = this.configProvider.getPrefixCls;
|
256 | var prefixCls = getPrefixCls('list', customizePrefixCls);
|
257 |
|
258 | var className = $attrs.class,
|
259 | restAttrs = __rest($attrs, ["class"]);
|
260 |
|
261 | var loadMore = (0, _propsUtil.getComponent)(this, 'loadMore');
|
262 | var footer = (0, _propsUtil.getComponent)(this, 'footer');
|
263 | var header = (0, _propsUtil.getComponent)(this, 'header');
|
264 | var children = (0, _propsUtil.getSlot)(this);
|
265 | var loadingProp = loading;
|
266 |
|
267 | if (typeof loadingProp === 'boolean') {
|
268 | loadingProp = {
|
269 | spinning: loadingProp
|
270 | };
|
271 | }
|
272 |
|
273 | var isLoading = loadingProp && loadingProp.spinning;
|
274 |
|
275 |
|
276 | var sizeCls = '';
|
277 |
|
278 | switch (size) {
|
279 | case 'large':
|
280 | sizeCls = 'lg';
|
281 | break;
|
282 |
|
283 | case 'small':
|
284 | sizeCls = 'sm';
|
285 | break;
|
286 |
|
287 | default:
|
288 | break;
|
289 | }
|
290 |
|
291 | var classString = (0, _classNames2.default)(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-vertical"), itemLayout === 'vertical'), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(sizeCls), sizeCls), _defineProperty(_classNames, "".concat(prefixCls, "-split"), split), _defineProperty(_classNames, "".concat(prefixCls, "-bordered"), bordered), _defineProperty(_classNames, "".concat(prefixCls, "-loading"), isLoading), _defineProperty(_classNames, "".concat(prefixCls, "-grid"), grid), _defineProperty(_classNames, "".concat(prefixCls, "-something-after-last-item"), this.isSomethingAfterLastItem()), _classNames), className);
|
292 |
|
293 | var paginationProps = _extends(_extends(_extends({}, this.defaultPaginationProps), {
|
294 | total: dataSource.length,
|
295 | current: paginationCurrent,
|
296 | pageSize: paginationSize
|
297 | }), pagination || {});
|
298 |
|
299 | classString;
|
300 | var largestPage = Math.ceil(paginationProps.total / paginationProps.pageSize);
|
301 |
|
302 | if (paginationProps.current > largestPage) {
|
303 | paginationProps.current = largestPage;
|
304 | }
|
305 |
|
306 | var cls = paginationProps.class,
|
307 | style = paginationProps.style,
|
308 | restProps = __rest(paginationProps, ["class", "style"]);
|
309 |
|
310 | var paginationContent = pagination ? (0, _vue.createVNode)("div", {
|
311 | "class": "".concat(prefixCls, "-pagination")
|
312 | }, [(0, _vue.createVNode)(_pagination.default, _extends(_extends({}, (0, _omit.default)(restProps, ['onChange'])), {
|
313 | class: cls,
|
314 | style: style,
|
315 | onChange: this.onPaginationChange,
|
316 | onShowSizeChange: this.onPaginationShowSizeChange
|
317 | }), null)]) : null;
|
318 |
|
319 | var splitDataSource = _toConsumableArray(dataSource);
|
320 |
|
321 | if (pagination) {
|
322 | if (dataSource.length > (paginationProps.current - 1) * paginationProps.pageSize) {
|
323 | splitDataSource = _toConsumableArray(dataSource).splice((paginationProps.current - 1) * paginationProps.pageSize, paginationProps.pageSize);
|
324 | }
|
325 | }
|
326 |
|
327 | var childrenContent;
|
328 | childrenContent = isLoading && (0, _vue.createVNode)("div", {
|
329 | "style": {
|
330 | minHeight: 53
|
331 | }
|
332 | }, null);
|
333 |
|
334 | if (splitDataSource.length > 0) {
|
335 | var items = splitDataSource.map(function (item, index) {
|
336 | return _this3.innerRenderItem(item, index);
|
337 | });
|
338 | var childrenList = items.map(function (child, index) {
|
339 | return (0, _vnode.cloneElement)(child, {
|
340 | key: _this3.keys[index]
|
341 | });
|
342 | });
|
343 | childrenContent = grid ? (0, _vue.createVNode)(_grid.Row, {
|
344 | "gutter": grid.gutter
|
345 | }, _isSlot(childrenList) ? childrenList : {
|
346 | default: function _default() {
|
347 | return [childrenList];
|
348 | }
|
349 | }) : (0, _vue.createVNode)("ul", {
|
350 | "class": "".concat(prefixCls, "-items")
|
351 | }, _isSlot(childrenList) ? childrenList : {
|
352 | default: function _default() {
|
353 | return [childrenList];
|
354 | }
|
355 | });
|
356 | } else if (!children.length && !isLoading) {
|
357 | var renderEmpty = this.configProvider.renderEmpty;
|
358 | childrenContent = this.renderEmpty(prefixCls, renderEmpty);
|
359 | }
|
360 |
|
361 | var paginationPosition = paginationProps.position || 'bottom';
|
362 | return (0, _vue.createVNode)("div", _objectSpread({
|
363 | "class": classString
|
364 | }, restAttrs), [(paginationPosition === 'top' || paginationPosition === 'both') && paginationContent, header && (0, _vue.createVNode)("div", {
|
365 | "class": "".concat(prefixCls, "-header")
|
366 | }, _isSlot(header) ? header : {
|
367 | default: function _default() {
|
368 | return [header];
|
369 | }
|
370 | }), (0, _vue.createVNode)(_spin.default, loadingProp, {
|
371 | default: function _default() {
|
372 | return [childrenContent, children];
|
373 | }
|
374 | }), footer && (0, _vue.createVNode)("div", {
|
375 | "class": "".concat(prefixCls, "-footer")
|
376 | }, _isSlot(footer) ? footer : {
|
377 | default: function _default() {
|
378 | return [footer];
|
379 | }
|
380 | }), loadMore || (paginationPosition === 'bottom' || paginationPosition === 'both') && paginationContent]);
|
381 | }
|
382 | });
|
383 |
|
384 |
|
385 | List.install = function (app) {
|
386 | app.component(List.name, List);
|
387 | app.component(List.Item.name, List.Item);
|
388 | app.component(List.Item.Meta.displayName, List.Item.Meta);
|
389 | return app;
|
390 | };
|
391 |
|
392 | var _default2 = List;
|
393 | exports.default = _default2; |
\ | No newline at end of file |