1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import Vue from 'vue';
|
7 |
|
8 | function _typeof(obj) {
|
9 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
10 | _typeof = function (obj) {
|
11 | return typeof obj;
|
12 | };
|
13 | } else {
|
14 | _typeof = function (obj) {
|
15 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
16 | };
|
17 | }
|
18 |
|
19 | return _typeof(obj);
|
20 | }
|
21 |
|
22 | function _defineProperty(obj, key, value) {
|
23 | if (key in obj) {
|
24 | Object.defineProperty(obj, key, {
|
25 | value: value,
|
26 | enumerable: true,
|
27 | configurable: true,
|
28 | writable: true
|
29 | });
|
30 | } else {
|
31 | obj[key] = value;
|
32 | }
|
33 |
|
34 | return obj;
|
35 | }
|
36 |
|
37 | function _toConsumableArray(arr) {
|
38 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
39 | }
|
40 |
|
41 | function _arrayWithoutHoles(arr) {
|
42 | if (Array.isArray(arr)) {
|
43 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
44 |
|
45 | return arr2;
|
46 | }
|
47 | }
|
48 |
|
49 | function _iterableToArray(iter) {
|
50 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
51 | }
|
52 |
|
53 | function _nonIterableSpread() {
|
54 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function reflectionIsSupported() {
|
61 | return typeof Reflect !== 'undefined' && Reflect.defineMetadata && Reflect.getOwnMetadataKeys;
|
62 | }
|
63 | function copyReflectionMetadata(to, from) {
|
64 | forwardMetadata(to, from);
|
65 | Object.getOwnPropertyNames(from.prototype).forEach(function (key) {
|
66 | forwardMetadata(to.prototype, from.prototype, key);
|
67 | });
|
68 | Object.getOwnPropertyNames(from).forEach(function (key) {
|
69 | forwardMetadata(to, from, key);
|
70 | });
|
71 | }
|
72 |
|
73 | function forwardMetadata(to, from, propertyKey) {
|
74 | var metaKeys = propertyKey ? Reflect.getOwnMetadataKeys(from, propertyKey) : Reflect.getOwnMetadataKeys(from);
|
75 | metaKeys.forEach(function (metaKey) {
|
76 | var metadata = propertyKey ? Reflect.getOwnMetadata(metaKey, from, propertyKey) : Reflect.getOwnMetadata(metaKey, from);
|
77 |
|
78 | if (propertyKey) {
|
79 | Reflect.defineMetadata(metaKey, metadata, to, propertyKey);
|
80 | } else {
|
81 | Reflect.defineMetadata(metaKey, metadata, to);
|
82 | }
|
83 | });
|
84 | }
|
85 |
|
86 | var fakeArray = {
|
87 | __proto__: []
|
88 | };
|
89 | var hasProto = fakeArray instanceof Array;
|
90 | function createDecorator(factory) {
|
91 | return function (target, key, index) {
|
92 | var Ctor = typeof target === 'function' ? target : target.constructor;
|
93 |
|
94 | if (!Ctor.__decorators__) {
|
95 | Ctor.__decorators__ = [];
|
96 | }
|
97 |
|
98 | if (typeof index !== 'number') {
|
99 | index = undefined;
|
100 | }
|
101 |
|
102 | Ctor.__decorators__.push(function (options) {
|
103 | return factory(options, key, index);
|
104 | });
|
105 | };
|
106 | }
|
107 | function mixins() {
|
108 | for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) {
|
109 | Ctors[_key] = arguments[_key];
|
110 | }
|
111 |
|
112 | return Vue.extend({
|
113 | mixins: Ctors
|
114 | });
|
115 | }
|
116 | function isPrimitive(value) {
|
117 | var type = _typeof(value);
|
118 |
|
119 | return value == null || type !== 'object' && type !== 'function';
|
120 | }
|
121 | function warn(message) {
|
122 | if (typeof console !== 'undefined') {
|
123 | console.warn('[vue-class-component] ' + message);
|
124 | }
|
125 | }
|
126 |
|
127 | function collectDataFromConstructor(vm, Component) {
|
128 |
|
129 | var originalInit = Component.prototype._init;
|
130 |
|
131 | Component.prototype._init = function () {
|
132 | var _this = this;
|
133 |
|
134 |
|
135 | var keys = Object.getOwnPropertyNames(vm);
|
136 |
|
137 | if (vm.$options.props) {
|
138 | for (var key in vm.$options.props) {
|
139 | if (!vm.hasOwnProperty(key)) {
|
140 | keys.push(key);
|
141 | }
|
142 | }
|
143 | }
|
144 |
|
145 | keys.forEach(function (key) {
|
146 | if (key.charAt(0) !== '_') {
|
147 | Object.defineProperty(_this, key, {
|
148 | get: function get() {
|
149 | return vm[key];
|
150 | },
|
151 | set: function set(value) {
|
152 | vm[key] = value;
|
153 | },
|
154 | configurable: true
|
155 | });
|
156 | }
|
157 | });
|
158 | };
|
159 |
|
160 |
|
161 | var data = new Component();
|
162 |
|
163 | Component.prototype._init = originalInit;
|
164 |
|
165 | var plainData = {};
|
166 | Object.keys(data).forEach(function (key) {
|
167 | if (data[key] !== undefined) {
|
168 | plainData[key] = data[key];
|
169 | }
|
170 | });
|
171 |
|
172 | if (process.env.NODE_ENV !== 'production') {
|
173 | if (!(Component.prototype instanceof Vue) && Object.keys(plainData).length > 0) {
|
174 | warn('Component class must inherit Vue or its descendant class ' + 'when class property is used.');
|
175 | }
|
176 | }
|
177 |
|
178 | return plainData;
|
179 | }
|
180 |
|
181 | var $internalHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeDestroy', 'destroyed', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch'
|
182 | ];
|
183 | function componentFactory(Component) {
|
184 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
185 | options.name = options.name || Component._componentTag || Component.name;
|
186 |
|
187 | var proto = Component.prototype;
|
188 | Object.getOwnPropertyNames(proto).forEach(function (key) {
|
189 | if (key === 'constructor') {
|
190 | return;
|
191 | }
|
192 |
|
193 |
|
194 | if ($internalHooks.indexOf(key) > -1) {
|
195 | options[key] = proto[key];
|
196 | return;
|
197 | }
|
198 |
|
199 | var descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
200 |
|
201 | if (descriptor.value !== void 0) {
|
202 |
|
203 | if (typeof descriptor.value === 'function') {
|
204 | (options.methods || (options.methods = {}))[key] = descriptor.value;
|
205 | } else {
|
206 |
|
207 | (options.mixins || (options.mixins = [])).push({
|
208 | data: function data() {
|
209 | return _defineProperty({}, key, descriptor.value);
|
210 | }
|
211 | });
|
212 | }
|
213 | } else if (descriptor.get || descriptor.set) {
|
214 |
|
215 | (options.computed || (options.computed = {}))[key] = {
|
216 | get: descriptor.get,
|
217 | set: descriptor.set
|
218 | };
|
219 | }
|
220 | });
|
221 | (options.mixins || (options.mixins = [])).push({
|
222 | data: function data() {
|
223 | return collectDataFromConstructor(this, Component);
|
224 | }
|
225 | });
|
226 |
|
227 | var decorators = Component.__decorators__;
|
228 |
|
229 | if (decorators) {
|
230 | decorators.forEach(function (fn) {
|
231 | return fn(options);
|
232 | });
|
233 | delete Component.__decorators__;
|
234 | }
|
235 |
|
236 |
|
237 | var superProto = Object.getPrototypeOf(Component.prototype);
|
238 | var Super = superProto instanceof Vue ? superProto.constructor : Vue;
|
239 | var Extended = Super.extend(options);
|
240 | forwardStaticMembers(Extended, Component, Super);
|
241 |
|
242 | if (reflectionIsSupported()) {
|
243 | copyReflectionMetadata(Extended, Component);
|
244 | }
|
245 |
|
246 | return Extended;
|
247 | }
|
248 | var reservedPropertyNames = [
|
249 | 'cid',
|
250 | 'super',
|
251 | 'options', 'superOptions', 'extendOptions', 'sealedOptions',
|
252 | 'component', 'directive', 'filter'];
|
253 | var shouldIgnore = {
|
254 | prototype: true,
|
255 | arguments: true,
|
256 | callee: true,
|
257 | caller: true
|
258 | };
|
259 |
|
260 | function forwardStaticMembers(Extended, Original, Super) {
|
261 |
|
262 | Object.getOwnPropertyNames(Original).forEach(function (key) {
|
263 |
|
264 | if (shouldIgnore[key]) {
|
265 | return;
|
266 | }
|
267 |
|
268 |
|
269 | var extendedDescriptor = Object.getOwnPropertyDescriptor(Extended, key);
|
270 |
|
271 | if (extendedDescriptor && !extendedDescriptor.configurable) {
|
272 | return;
|
273 | }
|
274 |
|
275 | var descriptor = Object.getOwnPropertyDescriptor(Original, key);
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 | if (!hasProto) {
|
284 |
|
285 |
|
286 |
|
287 | if (key === 'cid') {
|
288 | return;
|
289 | }
|
290 |
|
291 | var superDescriptor = Object.getOwnPropertyDescriptor(Super, key);
|
292 |
|
293 | if (!isPrimitive(descriptor.value) && superDescriptor && superDescriptor.value === descriptor.value) {
|
294 | return;
|
295 | }
|
296 | }
|
297 |
|
298 |
|
299 | if (process.env.NODE_ENV !== 'production' && reservedPropertyNames.indexOf(key) >= 0) {
|
300 | warn("Static property name '".concat(key, "' declared on class '").concat(Original.name, "' ") + 'conflicts with reserved property name of Vue internal. ' + 'It may cause unexpected behavior of the component. Consider renaming the property.');
|
301 | }
|
302 |
|
303 | Object.defineProperty(Extended, key, descriptor);
|
304 | });
|
305 | }
|
306 |
|
307 | function Component(options) {
|
308 | if (typeof options === 'function') {
|
309 | return componentFactory(options);
|
310 | }
|
311 |
|
312 | return function (Component) {
|
313 | return componentFactory(Component, options);
|
314 | };
|
315 | }
|
316 |
|
317 | Component.registerHooks = function registerHooks(keys) {
|
318 | $internalHooks.push.apply($internalHooks, _toConsumableArray(keys));
|
319 | };
|
320 |
|
321 | export default Component;
|
322 | export { createDecorator, mixins };
|