@lambo-design/detail-table 1.0.0-beta.3 → 1.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -8
- package/package.json +24 -18
- package/src/components/Col.js +149 -98
- package/src/components/Row.js +73 -69
- package/src/components/props-util.js +335 -335
- package/src/components/vnode.js +147 -147
- package/src/detail-table-item.vue +23 -19
- package/src/detail-table.vue +181 -178
- package/src/styles/css/index.less +144 -143
|
@@ -1,335 +1,335 @@
|
|
|
1
|
-
import isPlainObject from 'lodash/isPlainObject';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
function getType(fn) {
|
|
4
|
-
const match = fn && fn.toString().match(/^\s*function (\w+)/);
|
|
5
|
-
return match ? match[1] : '';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const camelizeRE = /-(\w)/g;
|
|
9
|
-
const camelize = str => {
|
|
10
|
-
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
|
|
11
|
-
};
|
|
12
|
-
const parseStyleText = (cssText = '', camel) => {
|
|
13
|
-
const res = {};
|
|
14
|
-
const listDelimiter = /;(?![^(]*\))/g;
|
|
15
|
-
const propertyDelimiter = /:(.+)/;
|
|
16
|
-
cssText.split(listDelimiter).forEach(function(item) {
|
|
17
|
-
if (item) {
|
|
18
|
-
const tmp = item.split(propertyDelimiter);
|
|
19
|
-
if (tmp.length > 1) {
|
|
20
|
-
const k = camel ? camelize(tmp[0].trim()) : tmp[0].trim();
|
|
21
|
-
res[k] = tmp[1].trim();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return res;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const hasProp = (instance, prop) => {
|
|
29
|
-
const $options = instance.$options || {};
|
|
30
|
-
const propsData = $options.propsData || {};
|
|
31
|
-
return prop in propsData;
|
|
32
|
-
};
|
|
33
|
-
const slotHasProp = (slot, prop) => {
|
|
34
|
-
const $options = slot.componentOptions || {};
|
|
35
|
-
const propsData = $options.propsData || {};
|
|
36
|
-
return prop in propsData;
|
|
37
|
-
};
|
|
38
|
-
const filterProps = (props, propsData = {}) => {
|
|
39
|
-
const res = {};
|
|
40
|
-
Object.keys(props).forEach(k => {
|
|
41
|
-
if (k in propsData || props[k] !== undefined) {
|
|
42
|
-
res[k] = props[k];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return res;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const getScopedSlots = ele => {
|
|
49
|
-
return (ele.data && ele.data.scopedSlots) || {};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const getSlots = ele => {
|
|
53
|
-
let componentOptions = ele.componentOptions || {};
|
|
54
|
-
if (ele.$vnode) {
|
|
55
|
-
componentOptions = ele.$vnode.componentOptions || {};
|
|
56
|
-
}
|
|
57
|
-
const children = ele.children || componentOptions.children || [];
|
|
58
|
-
const slots = {};
|
|
59
|
-
children.forEach(child => {
|
|
60
|
-
if (!isEmptyElement(child)) {
|
|
61
|
-
const name = (child.data && child.data.slot) || 'default';
|
|
62
|
-
slots[name] = slots[name] || [];
|
|
63
|
-
slots[name].push(child);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return { ...slots, ...getScopedSlots(ele) };
|
|
67
|
-
};
|
|
68
|
-
const getSlot = (self, name = 'default', options = {}) => {
|
|
69
|
-
return (
|
|
70
|
-
(self.$scopedSlots && self.$scopedSlots[name] && self.$scopedSlots[name](options)) ||
|
|
71
|
-
self.$slots[name] ||
|
|
72
|
-
[]
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const getAllChildren = ele => {
|
|
77
|
-
let componentOptions = ele.componentOptions || {};
|
|
78
|
-
if (ele.$vnode) {
|
|
79
|
-
componentOptions = ele.$vnode.componentOptions || {};
|
|
80
|
-
}
|
|
81
|
-
return ele.children || componentOptions.children || [];
|
|
82
|
-
};
|
|
83
|
-
const getSlotOptions = ele => {
|
|
84
|
-
if (ele.fnOptions) {
|
|
85
|
-
// 函数式组件
|
|
86
|
-
return ele.fnOptions;
|
|
87
|
-
}
|
|
88
|
-
let componentOptions = ele.componentOptions;
|
|
89
|
-
if (ele.$vnode) {
|
|
90
|
-
componentOptions = ele.$vnode.componentOptions;
|
|
91
|
-
}
|
|
92
|
-
return componentOptions ? componentOptions.Ctor.options || {} : {};
|
|
93
|
-
};
|
|
94
|
-
const getOptionProps = instance => {
|
|
95
|
-
if (instance.componentOptions) {
|
|
96
|
-
const componentOptions = instance.componentOptions;
|
|
97
|
-
const { propsData = {}, Ctor = {} } = componentOptions;
|
|
98
|
-
const props = (Ctor.options || {}).props || {};
|
|
99
|
-
const res = {};
|
|
100
|
-
for (const [k, v] of Object.entries(props)) {
|
|
101
|
-
const def = v.default;
|
|
102
|
-
if (def !== undefined) {
|
|
103
|
-
res[k] =
|
|
104
|
-
typeof def === 'function' && getType(v.type) !== 'Function' ? def.call(instance) : def;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return { ...res, ...propsData };
|
|
108
|
-
}
|
|
109
|
-
const { $options = {}, $props = {} } = instance;
|
|
110
|
-
return filterProps($props, $options.propsData);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
|
|
114
|
-
if (instance.$createElement) {
|
|
115
|
-
const h = instance.$createElement;
|
|
116
|
-
const temp = instance[prop];
|
|
117
|
-
if (temp !== undefined) {
|
|
118
|
-
return typeof temp === 'function' && execute ? temp(h, options) : temp;
|
|
119
|
-
}
|
|
120
|
-
return (
|
|
121
|
-
(instance.$scopedSlots[prop] && execute && instance.$scopedSlots[prop](options)) ||
|
|
122
|
-
instance.$scopedSlots[prop] ||
|
|
123
|
-
instance.$slots[prop] ||
|
|
124
|
-
undefined
|
|
125
|
-
);
|
|
126
|
-
} else {
|
|
127
|
-
const h = instance.context.$createElement;
|
|
128
|
-
const temp = getPropsData(instance)[prop];
|
|
129
|
-
if (temp !== undefined) {
|
|
130
|
-
return typeof temp === 'function' && execute ? temp(h, options) : temp;
|
|
131
|
-
}
|
|
132
|
-
const slotScope = getScopedSlots(instance)[prop];
|
|
133
|
-
if (slotScope !== undefined) {
|
|
134
|
-
return typeof slotScope === 'function' && execute ? slotScope(h, options) : slotScope;
|
|
135
|
-
}
|
|
136
|
-
const slotsProp = [];
|
|
137
|
-
const componentOptions = instance.componentOptions || {};
|
|
138
|
-
(componentOptions.children || []).forEach(child => {
|
|
139
|
-
if (child.data && child.data.slot === prop) {
|
|
140
|
-
if (child.data.attrs) {
|
|
141
|
-
delete child.data.attrs.slot;
|
|
142
|
-
}
|
|
143
|
-
if (child.tag === 'template') {
|
|
144
|
-
slotsProp.push(child.children);
|
|
145
|
-
} else {
|
|
146
|
-
slotsProp.push(child);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return slotsProp.length ? slotsProp : undefined;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const getAllProps = ele => {
|
|
155
|
-
let data = ele.data || {};
|
|
156
|
-
let componentOptions = ele.componentOptions || {};
|
|
157
|
-
if (ele.$vnode) {
|
|
158
|
-
data = ele.$vnode.data || {};
|
|
159
|
-
componentOptions = ele.$vnode.componentOptions || {};
|
|
160
|
-
}
|
|
161
|
-
return { ...data.props, ...data.attrs, ...componentOptions.propsData };
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const getPropsData = ele => {
|
|
165
|
-
let componentOptions = ele.componentOptions;
|
|
166
|
-
if (ele.$vnode) {
|
|
167
|
-
componentOptions = ele.$vnode.componentOptions;
|
|
168
|
-
}
|
|
169
|
-
return componentOptions ? componentOptions.propsData || {} : {};
|
|
170
|
-
};
|
|
171
|
-
const getValueByProp = (ele, prop) => {
|
|
172
|
-
return getPropsData(ele)[prop];
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const getAttrs = ele => {
|
|
176
|
-
let data = ele.data;
|
|
177
|
-
if (ele.$vnode) {
|
|
178
|
-
data = ele.$vnode.data;
|
|
179
|
-
}
|
|
180
|
-
return data ? data.attrs || {} : {};
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const getKey = ele => {
|
|
184
|
-
let key = ele.key;
|
|
185
|
-
if (ele.$vnode) {
|
|
186
|
-
key = ele.$vnode.key;
|
|
187
|
-
}
|
|
188
|
-
return key;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export function getEvents(child) {
|
|
192
|
-
let events = {};
|
|
193
|
-
if (child.componentOptions && child.componentOptions.listeners) {
|
|
194
|
-
events = child.componentOptions.listeners;
|
|
195
|
-
} else if (child.data && child.data.on) {
|
|
196
|
-
events = child.data.on;
|
|
197
|
-
}
|
|
198
|
-
return { ...events };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// 获取 xxx.native 或者 原生标签 事件
|
|
202
|
-
export function getDataEvents(child) {
|
|
203
|
-
let events = {};
|
|
204
|
-
if (child.data && child.data.on) {
|
|
205
|
-
events = child.data.on;
|
|
206
|
-
}
|
|
207
|
-
return { ...events };
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// use getListeners instead this.$listeners
|
|
211
|
-
// https://github.com/vueComponent/ant-design-vue/issues/1705
|
|
212
|
-
export function getListeners(context) {
|
|
213
|
-
return (context.$vnode ? context.$vnode.componentOptions.listeners : context.$listeners) || {};
|
|
214
|
-
}
|
|
215
|
-
export function getClass(ele) {
|
|
216
|
-
let data = {};
|
|
217
|
-
if (ele.data) {
|
|
218
|
-
data = ele.data;
|
|
219
|
-
} else if (ele.$vnode && ele.$vnode.data) {
|
|
220
|
-
data = ele.$vnode.data;
|
|
221
|
-
}
|
|
222
|
-
const tempCls = data.class || {};
|
|
223
|
-
const staticClass = data.staticClass;
|
|
224
|
-
let cls = {};
|
|
225
|
-
staticClass &&
|
|
226
|
-
staticClass.split(' ').forEach(c => {
|
|
227
|
-
cls[c.trim()] = true;
|
|
228
|
-
});
|
|
229
|
-
if (typeof tempCls === 'string') {
|
|
230
|
-
tempCls.split(' ').forEach(c => {
|
|
231
|
-
cls[c.trim()] = true;
|
|
232
|
-
});
|
|
233
|
-
} else if (Array.isArray(tempCls)) {
|
|
234
|
-
classNames(tempCls)
|
|
235
|
-
.split(' ')
|
|
236
|
-
.forEach(c => {
|
|
237
|
-
cls[c.trim()] = true;
|
|
238
|
-
});
|
|
239
|
-
} else {
|
|
240
|
-
cls = { ...cls, ...tempCls };
|
|
241
|
-
}
|
|
242
|
-
return cls;
|
|
243
|
-
}
|
|
244
|
-
export function getStyle(ele, camel) {
|
|
245
|
-
let data = {};
|
|
246
|
-
if (ele.data) {
|
|
247
|
-
data = ele.data;
|
|
248
|
-
} else if (ele.$vnode && ele.$vnode.data) {
|
|
249
|
-
data = ele.$vnode.data;
|
|
250
|
-
}
|
|
251
|
-
let style = data.style || data.staticStyle;
|
|
252
|
-
if (typeof style === 'string') {
|
|
253
|
-
style = parseStyleText(style, camel);
|
|
254
|
-
} else if (camel && style) {
|
|
255
|
-
// 驼峰化
|
|
256
|
-
const res = {};
|
|
257
|
-
Object.keys(style).forEach(k => (res[camelize(k)] = style[k]));
|
|
258
|
-
return res;
|
|
259
|
-
}
|
|
260
|
-
return style;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function getComponentName(opts) {
|
|
264
|
-
return opts && (opts.Ctor.options.name || opts.tag);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export function isEmptyElement(c) {
|
|
268
|
-
return !(c.tag || (c.text && c.text.trim() !== ''));
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function isStringElement(c) {
|
|
272
|
-
return !c.tag;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function filterEmpty(children = []) {
|
|
276
|
-
return children.filter(c => !isEmptyElement(c));
|
|
277
|
-
}
|
|
278
|
-
const initDefaultProps = (propTypes, defaultProps) => {
|
|
279
|
-
Object.keys(defaultProps).forEach(k => {
|
|
280
|
-
if (propTypes[k]) {
|
|
281
|
-
propTypes[k].def && (propTypes[k] = propTypes[k].def(defaultProps[k]));
|
|
282
|
-
} else {
|
|
283
|
-
throw new Error(`not have ${k} prop`);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
return propTypes;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
export function mergeProps() {
|
|
290
|
-
const args = [].slice.call(arguments, 0);
|
|
291
|
-
const props = {};
|
|
292
|
-
args.forEach((p = {}) => {
|
|
293
|
-
for (const [k, v] of Object.entries(p)) {
|
|
294
|
-
props[k] = props[k] || {};
|
|
295
|
-
if (isPlainObject(v)) {
|
|
296
|
-
Object.assign(props[k], v);
|
|
297
|
-
} else {
|
|
298
|
-
props[k] = v;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
return props;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function isValidElement(element) {
|
|
306
|
-
return (
|
|
307
|
-
element &&
|
|
308
|
-
typeof element === 'object' &&
|
|
309
|
-
'componentOptions' in element &&
|
|
310
|
-
'context' in element &&
|
|
311
|
-
element.tag !== undefined
|
|
312
|
-
); // remove text node
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export {
|
|
316
|
-
hasProp,
|
|
317
|
-
filterProps,
|
|
318
|
-
getOptionProps,
|
|
319
|
-
getComponentFromProp,
|
|
320
|
-
getSlotOptions,
|
|
321
|
-
slotHasProp,
|
|
322
|
-
getPropsData,
|
|
323
|
-
getKey,
|
|
324
|
-
getAttrs,
|
|
325
|
-
getValueByProp,
|
|
326
|
-
parseStyleText,
|
|
327
|
-
initDefaultProps,
|
|
328
|
-
isValidElement,
|
|
329
|
-
camelize,
|
|
330
|
-
getSlots,
|
|
331
|
-
getSlot,
|
|
332
|
-
getAllProps,
|
|
333
|
-
getAllChildren,
|
|
334
|
-
};
|
|
335
|
-
export default hasProp;
|
|
1
|
+
import isPlainObject from 'lodash/isPlainObject';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
function getType(fn) {
|
|
4
|
+
const match = fn && fn.toString().match(/^\s*function (\w+)/);
|
|
5
|
+
return match ? match[1] : '';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const camelizeRE = /-(\w)/g;
|
|
9
|
+
const camelize = str => {
|
|
10
|
+
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
|
|
11
|
+
};
|
|
12
|
+
const parseStyleText = (cssText = '', camel) => {
|
|
13
|
+
const res = {};
|
|
14
|
+
const listDelimiter = /;(?![^(]*\))/g;
|
|
15
|
+
const propertyDelimiter = /:(.+)/;
|
|
16
|
+
cssText.split(listDelimiter).forEach(function(item) {
|
|
17
|
+
if (item) {
|
|
18
|
+
const tmp = item.split(propertyDelimiter);
|
|
19
|
+
if (tmp.length > 1) {
|
|
20
|
+
const k = camel ? camelize(tmp[0].trim()) : tmp[0].trim();
|
|
21
|
+
res[k] = tmp[1].trim();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return res;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const hasProp = (instance, prop) => {
|
|
29
|
+
const $options = instance.$options || {};
|
|
30
|
+
const propsData = $options.propsData || {};
|
|
31
|
+
return prop in propsData;
|
|
32
|
+
};
|
|
33
|
+
const slotHasProp = (slot, prop) => {
|
|
34
|
+
const $options = slot.componentOptions || {};
|
|
35
|
+
const propsData = $options.propsData || {};
|
|
36
|
+
return prop in propsData;
|
|
37
|
+
};
|
|
38
|
+
const filterProps = (props, propsData = {}) => {
|
|
39
|
+
const res = {};
|
|
40
|
+
Object.keys(props).forEach(k => {
|
|
41
|
+
if (k in propsData || props[k] !== undefined) {
|
|
42
|
+
res[k] = props[k];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return res;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getScopedSlots = ele => {
|
|
49
|
+
return (ele.data && ele.data.scopedSlots) || {};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getSlots = ele => {
|
|
53
|
+
let componentOptions = ele.componentOptions || {};
|
|
54
|
+
if (ele.$vnode) {
|
|
55
|
+
componentOptions = ele.$vnode.componentOptions || {};
|
|
56
|
+
}
|
|
57
|
+
const children = ele.children || componentOptions.children || [];
|
|
58
|
+
const slots = {};
|
|
59
|
+
children.forEach(child => {
|
|
60
|
+
if (!isEmptyElement(child)) {
|
|
61
|
+
const name = (child.data && child.data.slot) || 'default';
|
|
62
|
+
slots[name] = slots[name] || [];
|
|
63
|
+
slots[name].push(child);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return { ...slots, ...getScopedSlots(ele) };
|
|
67
|
+
};
|
|
68
|
+
const getSlot = (self, name = 'default', options = {}) => {
|
|
69
|
+
return (
|
|
70
|
+
(self.$scopedSlots && self.$scopedSlots[name] && self.$scopedSlots[name](options)) ||
|
|
71
|
+
self.$slots[name] ||
|
|
72
|
+
[]
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const getAllChildren = ele => {
|
|
77
|
+
let componentOptions = ele.componentOptions || {};
|
|
78
|
+
if (ele.$vnode) {
|
|
79
|
+
componentOptions = ele.$vnode.componentOptions || {};
|
|
80
|
+
}
|
|
81
|
+
return ele.children || componentOptions.children || [];
|
|
82
|
+
};
|
|
83
|
+
const getSlotOptions = ele => {
|
|
84
|
+
if (ele.fnOptions) {
|
|
85
|
+
// 函数式组件
|
|
86
|
+
return ele.fnOptions;
|
|
87
|
+
}
|
|
88
|
+
let componentOptions = ele.componentOptions;
|
|
89
|
+
if (ele.$vnode) {
|
|
90
|
+
componentOptions = ele.$vnode.componentOptions;
|
|
91
|
+
}
|
|
92
|
+
return componentOptions ? componentOptions.Ctor.options || {} : {};
|
|
93
|
+
};
|
|
94
|
+
const getOptionProps = instance => {
|
|
95
|
+
if (instance.componentOptions) {
|
|
96
|
+
const componentOptions = instance.componentOptions;
|
|
97
|
+
const { propsData = {}, Ctor = {} } = componentOptions;
|
|
98
|
+
const props = (Ctor.options || {}).props || {};
|
|
99
|
+
const res = {};
|
|
100
|
+
for (const [k, v] of Object.entries(props)) {
|
|
101
|
+
const def = v.default;
|
|
102
|
+
if (def !== undefined) {
|
|
103
|
+
res[k] =
|
|
104
|
+
typeof def === 'function' && getType(v.type) !== 'Function' ? def.call(instance) : def;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { ...res, ...propsData };
|
|
108
|
+
}
|
|
109
|
+
const { $options = {}, $props = {} } = instance;
|
|
110
|
+
return filterProps($props, $options.propsData);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
|
|
114
|
+
if (instance.$createElement) {
|
|
115
|
+
const h = instance.$createElement;
|
|
116
|
+
const temp = instance[prop];
|
|
117
|
+
if (temp !== undefined) {
|
|
118
|
+
return typeof temp === 'function' && execute ? temp(h, options) : temp;
|
|
119
|
+
}
|
|
120
|
+
return (
|
|
121
|
+
(instance.$scopedSlots[prop] && execute && instance.$scopedSlots[prop](options)) ||
|
|
122
|
+
instance.$scopedSlots[prop] ||
|
|
123
|
+
instance.$slots[prop] ||
|
|
124
|
+
undefined
|
|
125
|
+
);
|
|
126
|
+
} else {
|
|
127
|
+
const h = instance.context.$createElement;
|
|
128
|
+
const temp = getPropsData(instance)[prop];
|
|
129
|
+
if (temp !== undefined) {
|
|
130
|
+
return typeof temp === 'function' && execute ? temp(h, options) : temp;
|
|
131
|
+
}
|
|
132
|
+
const slotScope = getScopedSlots(instance)[prop];
|
|
133
|
+
if (slotScope !== undefined) {
|
|
134
|
+
return typeof slotScope === 'function' && execute ? slotScope(h, options) : slotScope;
|
|
135
|
+
}
|
|
136
|
+
const slotsProp = [];
|
|
137
|
+
const componentOptions = instance.componentOptions || {};
|
|
138
|
+
(componentOptions.children || []).forEach(child => {
|
|
139
|
+
if (child.data && child.data.slot === prop) {
|
|
140
|
+
if (child.data.attrs) {
|
|
141
|
+
delete child.data.attrs.slot;
|
|
142
|
+
}
|
|
143
|
+
if (child.tag === 'template') {
|
|
144
|
+
slotsProp.push(child.children);
|
|
145
|
+
} else {
|
|
146
|
+
slotsProp.push(child);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return slotsProp.length ? slotsProp : undefined;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const getAllProps = ele => {
|
|
155
|
+
let data = ele.data || {};
|
|
156
|
+
let componentOptions = ele.componentOptions || {};
|
|
157
|
+
if (ele.$vnode) {
|
|
158
|
+
data = ele.$vnode.data || {};
|
|
159
|
+
componentOptions = ele.$vnode.componentOptions || {};
|
|
160
|
+
}
|
|
161
|
+
return { ...data.props, ...data.attrs, ...componentOptions.propsData };
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const getPropsData = ele => {
|
|
165
|
+
let componentOptions = ele.componentOptions;
|
|
166
|
+
if (ele.$vnode) {
|
|
167
|
+
componentOptions = ele.$vnode.componentOptions;
|
|
168
|
+
}
|
|
169
|
+
return componentOptions ? componentOptions.propsData || {} : {};
|
|
170
|
+
};
|
|
171
|
+
const getValueByProp = (ele, prop) => {
|
|
172
|
+
return getPropsData(ele)[prop];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const getAttrs = ele => {
|
|
176
|
+
let data = ele.data;
|
|
177
|
+
if (ele.$vnode) {
|
|
178
|
+
data = ele.$vnode.data;
|
|
179
|
+
}
|
|
180
|
+
return data ? data.attrs || {} : {};
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const getKey = ele => {
|
|
184
|
+
let key = ele.key;
|
|
185
|
+
if (ele.$vnode) {
|
|
186
|
+
key = ele.$vnode.key;
|
|
187
|
+
}
|
|
188
|
+
return key;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export function getEvents(child) {
|
|
192
|
+
let events = {};
|
|
193
|
+
if (child.componentOptions && child.componentOptions.listeners) {
|
|
194
|
+
events = child.componentOptions.listeners;
|
|
195
|
+
} else if (child.data && child.data.on) {
|
|
196
|
+
events = child.data.on;
|
|
197
|
+
}
|
|
198
|
+
return { ...events };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 获取 xxx.native 或者 原生标签 事件
|
|
202
|
+
export function getDataEvents(child) {
|
|
203
|
+
let events = {};
|
|
204
|
+
if (child.data && child.data.on) {
|
|
205
|
+
events = child.data.on;
|
|
206
|
+
}
|
|
207
|
+
return { ...events };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// use getListeners instead this.$listeners
|
|
211
|
+
// https://github.com/vueComponent/ant-design-vue/issues/1705
|
|
212
|
+
export function getListeners(context) {
|
|
213
|
+
return (context.$vnode ? context.$vnode.componentOptions.listeners : context.$listeners) || {};
|
|
214
|
+
}
|
|
215
|
+
export function getClass(ele) {
|
|
216
|
+
let data = {};
|
|
217
|
+
if (ele.data) {
|
|
218
|
+
data = ele.data;
|
|
219
|
+
} else if (ele.$vnode && ele.$vnode.data) {
|
|
220
|
+
data = ele.$vnode.data;
|
|
221
|
+
}
|
|
222
|
+
const tempCls = data.class || {};
|
|
223
|
+
const staticClass = data.staticClass;
|
|
224
|
+
let cls = {};
|
|
225
|
+
staticClass &&
|
|
226
|
+
staticClass.split(' ').forEach(c => {
|
|
227
|
+
cls[c.trim()] = true;
|
|
228
|
+
});
|
|
229
|
+
if (typeof tempCls === 'string') {
|
|
230
|
+
tempCls.split(' ').forEach(c => {
|
|
231
|
+
cls[c.trim()] = true;
|
|
232
|
+
});
|
|
233
|
+
} else if (Array.isArray(tempCls)) {
|
|
234
|
+
classNames(tempCls)
|
|
235
|
+
.split(' ')
|
|
236
|
+
.forEach(c => {
|
|
237
|
+
cls[c.trim()] = true;
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
cls = { ...cls, ...tempCls };
|
|
241
|
+
}
|
|
242
|
+
return cls;
|
|
243
|
+
}
|
|
244
|
+
export function getStyle(ele, camel) {
|
|
245
|
+
let data = {};
|
|
246
|
+
if (ele.data) {
|
|
247
|
+
data = ele.data;
|
|
248
|
+
} else if (ele.$vnode && ele.$vnode.data) {
|
|
249
|
+
data = ele.$vnode.data;
|
|
250
|
+
}
|
|
251
|
+
let style = data.style || data.staticStyle;
|
|
252
|
+
if (typeof style === 'string') {
|
|
253
|
+
style = parseStyleText(style, camel);
|
|
254
|
+
} else if (camel && style) {
|
|
255
|
+
// 驼峰化
|
|
256
|
+
const res = {};
|
|
257
|
+
Object.keys(style).forEach(k => (res[camelize(k)] = style[k]));
|
|
258
|
+
return res;
|
|
259
|
+
}
|
|
260
|
+
return style;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function getComponentName(opts) {
|
|
264
|
+
return opts && (opts.Ctor.options.name || opts.tag);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function isEmptyElement(c) {
|
|
268
|
+
return !(c.tag || (c.text && c.text.trim() !== ''));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function isStringElement(c) {
|
|
272
|
+
return !c.tag;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function filterEmpty(children = []) {
|
|
276
|
+
return children.filter(c => !isEmptyElement(c));
|
|
277
|
+
}
|
|
278
|
+
const initDefaultProps = (propTypes, defaultProps) => {
|
|
279
|
+
Object.keys(defaultProps).forEach(k => {
|
|
280
|
+
if (propTypes[k]) {
|
|
281
|
+
propTypes[k].def && (propTypes[k] = propTypes[k].def(defaultProps[k]));
|
|
282
|
+
} else {
|
|
283
|
+
throw new Error(`not have ${k} prop`);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
return propTypes;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export function mergeProps() {
|
|
290
|
+
const args = [].slice.call(arguments, 0);
|
|
291
|
+
const props = {};
|
|
292
|
+
args.forEach((p = {}) => {
|
|
293
|
+
for (const [k, v] of Object.entries(p)) {
|
|
294
|
+
props[k] = props[k] || {};
|
|
295
|
+
if (isPlainObject(v)) {
|
|
296
|
+
Object.assign(props[k], v);
|
|
297
|
+
} else {
|
|
298
|
+
props[k] = v;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
return props;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function isValidElement(element) {
|
|
306
|
+
return (
|
|
307
|
+
element &&
|
|
308
|
+
typeof element === 'object' &&
|
|
309
|
+
'componentOptions' in element &&
|
|
310
|
+
'context' in element &&
|
|
311
|
+
element.tag !== undefined
|
|
312
|
+
); // remove text node
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export {
|
|
316
|
+
hasProp,
|
|
317
|
+
filterProps,
|
|
318
|
+
getOptionProps,
|
|
319
|
+
getComponentFromProp,
|
|
320
|
+
getSlotOptions,
|
|
321
|
+
slotHasProp,
|
|
322
|
+
getPropsData,
|
|
323
|
+
getKey,
|
|
324
|
+
getAttrs,
|
|
325
|
+
getValueByProp,
|
|
326
|
+
parseStyleText,
|
|
327
|
+
initDefaultProps,
|
|
328
|
+
isValidElement,
|
|
329
|
+
camelize,
|
|
330
|
+
getSlots,
|
|
331
|
+
getSlot,
|
|
332
|
+
getAllProps,
|
|
333
|
+
getAllChildren,
|
|
334
|
+
};
|
|
335
|
+
export default hasProp;
|