|
| 1 | +/** |
| 2 | + * vue-class-component v8.0.0-alpha.6 |
| 3 | + * (c) 2015-present Evan You |
| 4 | + * @license MIT |
| 5 | + */ |
| 6 | +import { reactive } from 'vue'; |
| 7 | + |
| 8 | +function _defineProperty(obj, key, value) { |
| 9 | + if (key in obj) { |
| 10 | + Object.defineProperty(obj, key, { |
| 11 | + value: value, |
| 12 | + enumerable: true, |
| 13 | + configurable: true, |
| 14 | + writable: true |
| 15 | + }); |
| 16 | + } else { |
| 17 | + obj[key] = value; |
| 18 | + } |
| 19 | + |
| 20 | + return obj; |
| 21 | +} |
| 22 | + |
| 23 | +function ownKeys(object, enumerableOnly) { |
| 24 | + var keys = Object.keys(object); |
| 25 | + |
| 26 | + if (Object.getOwnPropertySymbols) { |
| 27 | + var symbols = Object.getOwnPropertySymbols(object); |
| 28 | + if (enumerableOnly) symbols = symbols.filter(function (sym) { |
| 29 | + return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
| 30 | + }); |
| 31 | + keys.push.apply(keys, symbols); |
| 32 | + } |
| 33 | + |
| 34 | + return keys; |
| 35 | +} |
| 36 | + |
| 37 | +function _objectSpread2(target) { |
| 38 | + for (var i = 1; i < arguments.length; i++) { |
| 39 | + var source = arguments[i] != null ? arguments[i] : {}; |
| 40 | + |
| 41 | + if (i % 2) { |
| 42 | + ownKeys(Object(source), true).forEach(function (key) { |
| 43 | + _defineProperty(target, key, source[key]); |
| 44 | + }); |
| 45 | + } else if (Object.getOwnPropertyDescriptors) { |
| 46 | + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); |
| 47 | + } else { |
| 48 | + ownKeys(Object(source)).forEach(function (key) { |
| 49 | + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
| 50 | + }); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + return target; |
| 55 | +} |
| 56 | + |
| 57 | +function defineGetter(obj, key, getter) { |
| 58 | + Object.defineProperty(obj, key, { |
| 59 | + get: getter, |
| 60 | + enumerable: false, |
| 61 | + configurable: true |
| 62 | + }); |
| 63 | +} |
| 64 | + |
| 65 | +function defineProxy(proxy, key, target) { |
| 66 | + Object.defineProperty(proxy, key, { |
| 67 | + get: () => target[key], |
| 68 | + set: value => { |
| 69 | + target[key] = value; |
| 70 | + }, |
| 71 | + enumerable: true, |
| 72 | + configurable: true |
| 73 | + }); |
| 74 | +} |
| 75 | + |
| 76 | +function getSuperOptions(Ctor) { |
| 77 | + var superProto = Object.getPrototypeOf(Ctor.prototype); |
| 78 | + |
| 79 | + if (!superProto) { |
| 80 | + return undefined; |
| 81 | + } |
| 82 | + |
| 83 | + var Super = superProto.constructor; |
| 84 | + return Super.__vccOpts; |
| 85 | +} |
| 86 | + |
| 87 | +class VueImpl { |
| 88 | + constructor(props, ctx) { |
| 89 | + defineGetter(this, '$props', () => props); |
| 90 | + defineGetter(this, '$attrs', () => ctx.attrs); |
| 91 | + defineGetter(this, '$slots', () => ctx.slots); |
| 92 | + defineGetter(this, '$emit', () => ctx.emit); |
| 93 | + Object.keys(props).forEach(key => { |
| 94 | + Object.defineProperty(this, key, { |
| 95 | + enumerable: false, |
| 96 | + configurable: true, |
| 97 | + writable: true, |
| 98 | + value: props[key] |
| 99 | + }); |
| 100 | + }); |
| 101 | + } |
| 102 | + /** @internal */ |
| 103 | + |
| 104 | + |
| 105 | + static get __vccOpts() { |
| 106 | + // Early return if `this` is base class as it does not have any options |
| 107 | + if (this === Vue) { |
| 108 | + return {}; |
| 109 | + } |
| 110 | + |
| 111 | + var cache = this.hasOwnProperty('__vccCache') && this.__vccCache; |
| 112 | + |
| 113 | + if (cache) { |
| 114 | + return cache; |
| 115 | + } |
| 116 | + |
| 117 | + var Ctor = this; // If the options are provided via decorator use it as a base |
| 118 | + |
| 119 | + var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options |
| 120 | + |
| 121 | + options.extends = getSuperOptions(Ctor); // Handle mixins |
| 122 | + |
| 123 | + var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins; |
| 124 | + |
| 125 | + if (mixins) { |
| 126 | + options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins; |
| 127 | + } |
| 128 | + |
| 129 | + options.methods = _objectSpread2({}, options.methods); |
| 130 | + options.computed = _objectSpread2({}, options.computed); |
| 131 | + var proto = Ctor.prototype; |
| 132 | + Object.getOwnPropertyNames(proto).forEach(key => { |
| 133 | + if (key === 'constructor') { |
| 134 | + return; |
| 135 | + } // hooks |
| 136 | + |
| 137 | + |
| 138 | + if (Ctor.__vccHooks.indexOf(key) > -1) { |
| 139 | + options[key] = proto[key]; |
| 140 | + return; |
| 141 | + } |
| 142 | + |
| 143 | + var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods |
| 144 | + |
| 145 | + if (typeof descriptor.value === 'function') { |
| 146 | + options.methods[key] = descriptor.value; |
| 147 | + return; |
| 148 | + } // computed properties |
| 149 | + |
| 150 | + |
| 151 | + if (descriptor.get || descriptor.set) { |
| 152 | + options.computed[key] = { |
| 153 | + get: descriptor.get, |
| 154 | + set: descriptor.set |
| 155 | + }; |
| 156 | + return; |
| 157 | + } |
| 158 | + }); |
| 159 | + |
| 160 | + options.setup = function (props, ctx) { |
| 161 | + var data = new Ctor(props, ctx); |
| 162 | + var dataKeys = Object.keys(data); |
| 163 | + var plainData = reactive({}); // Initialize reactive data and convert constructor `this` to a proxy |
| 164 | + |
| 165 | + dataKeys.forEach(key => { |
| 166 | + // Skip if the value is undefined not to make it reactive. |
| 167 | + // If the value has `__s`, it's a value from `setup` helper, proceed it later. |
| 168 | + if (data[key] === undefined || data[key] && data[key].__s) { |
| 169 | + return; |
| 170 | + } |
| 171 | + |
| 172 | + plainData[key] = data[key]; |
| 173 | + defineProxy(data, key, plainData); |
| 174 | + }); // Invoke composition functions |
| 175 | + |
| 176 | + dataKeys.forEach(key => { |
| 177 | + if (data[key] && data[key].__s) { |
| 178 | + plainData[key] = data[key].__s(); |
| 179 | + } |
| 180 | + }); |
| 181 | + return plainData; |
| 182 | + }; |
| 183 | + |
| 184 | + var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators; |
| 185 | + |
| 186 | + if (decorators) { |
| 187 | + decorators.forEach(fn => fn(options)); |
| 188 | + } // from Vue Loader |
| 189 | + |
| 190 | + |
| 191 | + var injections = ['render', 'ssrRender', '__file', '__cssModules', '__scopeId', '__hmrId']; |
| 192 | + injections.forEach(key => { |
| 193 | + if (Ctor[key]) { |
| 194 | + options[key] = Ctor[key]; |
| 195 | + } |
| 196 | + }); |
| 197 | + return options; |
| 198 | + } |
| 199 | + |
| 200 | + static registerHooks(keys) { |
| 201 | + this.__vccHooks.push(...keys); |
| 202 | + } |
| 203 | + |
| 204 | +} |
| 205 | +/** @internal */ |
| 206 | + |
| 207 | + |
| 208 | +VueImpl.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch']; |
| 209 | +var Vue = VueImpl; |
| 210 | + |
| 211 | +function Options(options) { |
| 212 | + return Component => { |
| 213 | + Component.__vccBase = options; |
| 214 | + return Component; |
| 215 | + }; |
| 216 | +} |
| 217 | +function createDecorator(factory) { |
| 218 | + return (target, key, index) => { |
| 219 | + var Ctor = typeof target === 'function' ? target : target.constructor; |
| 220 | + |
| 221 | + if (!Ctor.__vccDecorators) { |
| 222 | + Ctor.__vccDecorators = []; |
| 223 | + } |
| 224 | + |
| 225 | + if (typeof index !== 'number') { |
| 226 | + index = undefined; |
| 227 | + } |
| 228 | + |
| 229 | + Ctor.__vccDecorators.push(options => factory(options, key, index)); |
| 230 | + }; |
| 231 | +} |
| 232 | +function mixins() { |
| 233 | + for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) { |
| 234 | + Ctors[_key] = arguments[_key]; |
| 235 | + } |
| 236 | + |
| 237 | + var _a; |
| 238 | + |
| 239 | + return _a = class MixedVue extends Vue { |
| 240 | + constructor(props, ctx) { |
| 241 | + super(props, ctx); |
| 242 | + Ctors.forEach(Ctor => { |
| 243 | + var data = new Ctor(props, ctx); |
| 244 | + Object.keys(data).forEach(key => { |
| 245 | + this[key] = data[key]; |
| 246 | + }); |
| 247 | + }); |
| 248 | + } |
| 249 | + |
| 250 | + }, _a.__vccMixins = Ctors.map(Ctor => Ctor.__vccOpts), _a; |
| 251 | +} |
| 252 | +function setup(setupFn) { |
| 253 | + // Hack to delay the invocation of setup function. |
| 254 | + // Will be called after dealing with class properties. |
| 255 | + return { |
| 256 | + __s: setupFn |
| 257 | + }; |
| 258 | +} |
| 259 | + |
| 260 | +export { Options, Vue, createDecorator, mixins, setup }; |
0 commit comments