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