diff --git a/dist/vue-class-component.cjs.js b/dist/vue-class-component.cjs.js new file mode 100644 index 0000000..b7595b8 --- /dev/null +++ b/dist/vue-class-component.cjs.js @@ -0,0 +1,439 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var vue = require('vue'); + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +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; +} + +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; +} + +function _objectSpread2(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; +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } +} + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); +} + +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function () { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; +} + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); +} + +function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); +} + +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); +} + +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; +} + +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."); +} + +function defineGetter(obj, key, getter) { + Object.defineProperty(obj, key, { + get: getter, + enumerable: false, + configurable: true + }); +} + +function defineProxy(proxy, key, target) { + Object.defineProperty(proxy, key, { + get: function get() { + return target[key]; + }, + set: function set(value) { + target[key] = value; + }, + enumerable: true, + configurable: true + }); +} + +function getSuperOptions(Ctor) { + var superProto = Object.getPrototypeOf(Ctor.prototype); + + if (!superProto) { + return undefined; + } + + var Super = superProto.constructor; + return Super.__vccOpts; +} + +var VueImpl = /*#__PURE__*/function () { + function VueImpl(props, ctx) { + var _this = this; + + _classCallCheck(this, VueImpl); + + defineGetter(this, '$props', function () { + return props; + }); + defineGetter(this, '$attrs', function () { + return ctx.attrs; + }); + defineGetter(this, '$slots', function () { + return ctx.slots; + }); + defineGetter(this, '$emit', function () { + return ctx.emit; + }); + Object.keys(props).forEach(function (key) { + Object.defineProperty(_this, key, { + enumerable: false, + configurable: true, + writable: true, + value: props[key] + }); + }); + } + /** @internal */ + + + _createClass(VueImpl, null, [{ + key: "registerHooks", + value: function registerHooks(keys) { + var _this$__vccHooks; + + (_this$__vccHooks = this.__vccHooks).push.apply(_this$__vccHooks, _toConsumableArray(keys)); + } + }, { + key: "__vccOpts", + get: function get() { + // Early return if `this` is base class as it does not have any options + if (this === Vue) { + return {}; + } + + var cache = this.hasOwnProperty('__vccCache') && this.__vccCache; + + if (cache) { + return cache; + } + + var Ctor = this; // If the options are provided via decorator use it as a base + + var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options + + options["extends"] = getSuperOptions(Ctor); // Handle mixins + + var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins; + + if (mixins) { + options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins; + } + + options.methods = _objectSpread2({}, options.methods); + options.computed = _objectSpread2({}, options.computed); + var proto = Ctor.prototype; + Object.getOwnPropertyNames(proto).forEach(function (key) { + if (key === 'constructor') { + return; + } // hooks + + + if (Ctor.__vccHooks.indexOf(key) > -1) { + options[key] = proto[key]; + return; + } + + var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods + + if (typeof descriptor.value === 'function') { + options.methods[key] = descriptor.value; + return; + } // computed properties + + + if (descriptor.get || descriptor.set) { + options.computed[key] = { + get: descriptor.get, + set: descriptor.set + }; + return; + } + }); + + options.setup = function (props, ctx) { + var data = new Ctor(props, ctx); + var dataKeys = Object.keys(data); + var plainData = vue.reactive({}); // Initialize reactive data and convert constructor `this` to a proxy + + dataKeys.forEach(function (key) { + // Skip if the value is undefined not to make it reactive. + // If the value has `__s`, it's a value from `setup` helper, proceed it later. + if (data[key] === undefined || data[key] && data[key].__s) { + return; + } + + plainData[key] = data[key]; + defineProxy(data, key, plainData); + }); // Invoke composition functions + + dataKeys.forEach(function (key) { + if (data[key] && data[key].__s) { + plainData[key] = data[key].__s(); + } + }); + return plainData; + }; + + var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators; + + if (decorators) { + decorators.forEach(function (fn) { + return fn(options); + }); + } // from Vue Loader + + + var injections = ['render', 'ssrRender', '__file', '__cssModules', '__scopeId', '__hmrId']; + injections.forEach(function (key) { + if (Ctor[key]) { + options[key] = Ctor[key]; + } + }); + return options; + } + }]); + + return VueImpl; +}(); +/** @internal */ + + +VueImpl.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch']; +var Vue = VueImpl; + +function Options(options) { + return function (Component) { + Component.__vccBase = options; + return Component; + }; +} +function createDecorator(factory) { + return function (target, key, index) { + var Ctor = typeof target === 'function' ? target : target.constructor; + + if (!Ctor.__vccDecorators) { + Ctor.__vccDecorators = []; + } + + if (typeof index !== 'number') { + index = undefined; + } + + Ctor.__vccDecorators.push(function (options) { + return factory(options, key, index); + }); + }; +} +function mixins() { + for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) { + Ctors[_key] = arguments[_key]; + } + + var _a; + + return _a = /*#__PURE__*/function (_Vue) { + _inherits(MixedVue, _Vue); + + var _super = _createSuper(MixedVue); + + function MixedVue(props, ctx) { + var _this; + + _classCallCheck(this, MixedVue); + + _this = _super.call(this, props, ctx); + Ctors.forEach(function (Ctor) { + var data = new Ctor(props, ctx); + Object.keys(data).forEach(function (key) { + _this[key] = data[key]; + }); + }); + return _this; + } + + return MixedVue; + }(Vue), _a.__vccMixins = Ctors.map(function (Ctor) { + return Ctor.__vccOpts; + }), _a; +} +function setup(setupFn) { + // Hack to delay the invocation of setup function. + // Will be called after dealing with class properties. + return { + __s: setupFn + }; +} + +exports.Options = Options; +exports.Vue = Vue; +exports.createDecorator = createDecorator; +exports.mixins = mixins; +exports.setup = setup; diff --git a/dist/vue-class-component.common.js b/dist/vue-class-component.common.js index e85b1c4..ede79a1 100644 --- a/dist/vue-class-component.common.js +++ b/dist/vue-class-component.common.js @@ -1,5 +1,5 @@ /** - * vue-class-component v7.2.3 + * vue-class-component v7.2.4 * (c) 2015-present Evan You * @license MIT */ @@ -149,17 +149,15 @@ function collectDataFromConstructor(vm, Component) { } keys.forEach(function (key) { - if (key.charAt(0) !== '_') { - Object.defineProperty(_this, key, { - get: function get() { - return vm[key]; - }, - set: function set(value) { - vm[key] = value; - }, - configurable: true - }); - } + Object.defineProperty(_this, key, { + get: function get() { + return vm[key]; + }, + set: function set(value) { + vm[key] = value; + }, + configurable: true + }); }); }; // should be acquired class property values diff --git a/dist/vue-class-component.d.ts b/dist/vue-class-component.d.ts new file mode 100644 index 0000000..c7d16df --- /dev/null +++ b/dist/vue-class-component.d.ts @@ -0,0 +1,80 @@ +import { ComponentOptions } from 'vue'; +import { ComponentPublicInstance } from 'vue'; +import { SetupContext } from 'vue'; +import { UnwrapRef } from 'vue'; +import { VNode } from 'vue'; + +export declare interface ClassComponentHooks { + data?(): object; + beforeCreate?(): void; + created?(): void; + beforeMount?(): void; + mounted?(): void; + beforeUnmount?(): void; + unmounted?(): void; + beforeUpdate?(): void; + updated?(): void; + activated?(): void; + deactivated?(): void; + render?(): VNode | void; + errorCaptured?(err: Error, vm: Vue, info: string): boolean | undefined; + serverPrefetch?(): Promise; +} + +export declare function createDecorator(factory: (options: ComponentOptions, key: string, index: number) => void): VueDecorator; + +export declare type ExtractInstance = T extends VueMixin ? V : never; + +export declare type MixedVueBase = Mixins extends (infer T)[] ? VueBase> & Vue> & PropsMixin : never; + +export declare function mixins(...Ctors: T): MixedVueBase; + +export declare function Options(options: ComponentOptions & ThisType): (target: VC) => VC; + +export declare interface PropsMixin { + new (...args: any[]): { + $props: Props; + }; +} + +export declare function setup(setupFn: () => R): UnwrapRef; + +export declare type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; + +export declare type Vue = ComponentPublicInstance<{}, {}, {}, {}, {}, Record, Props> & ClassComponentHooks; + +export declare const Vue: VueConstructor; + +export declare type VueBase = VueMixin & (new (...args: any[]) => V); + +export declare interface VueConstructor extends VueStatic { + new (prop: Props, ctx: SetupContext): Vue; +} + +export declare interface VueDecorator { + (Ctor: VueBase): void; + (target: Vue, key: string): void; + (target: Vue, key: string, index: number): void; +} + +export declare type VueMixin = VueStatic & { + prototype: V; +}; + +export declare interface VueStatic { + /* Excluded from this release type: __vccCache */ + /* Excluded from this release type: __vccBase */ + /* Excluded from this release type: __vccDecorators */ + /* Excluded from this release type: __vccMixins */ + /* Excluded from this release type: __vccHooks */ + /* Excluded from this release type: __vccOpts */ + /* Excluded from this release type: render */ + /* Excluded from this release type: ssrRender */ + /* Excluded from this release type: __file */ + /* Excluded from this release type: __cssModules */ + /* Excluded from this release type: __scopeId */ + /* Excluded from this release type: __hmrId */ + registerHooks(keys: string[]): void; +} + +export { } diff --git a/dist/vue-class-component.esm-browser.js b/dist/vue-class-component.esm-browser.js new file mode 100644 index 0000000..063eac2 --- /dev/null +++ b/dist/vue-class-component.esm-browser.js @@ -0,0 +1,260 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +import { reactive } from 'vue'; + +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; +} + +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; +} + +function _objectSpread2(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; +} + +function defineGetter(obj, key, getter) { + Object.defineProperty(obj, key, { + get: getter, + enumerable: false, + configurable: true + }); +} + +function defineProxy(proxy, key, target) { + Object.defineProperty(proxy, key, { + get: () => target[key], + set: value => { + target[key] = value; + }, + enumerable: true, + configurable: true + }); +} + +function getSuperOptions(Ctor) { + var superProto = Object.getPrototypeOf(Ctor.prototype); + + if (!superProto) { + return undefined; + } + + var Super = superProto.constructor; + return Super.__vccOpts; +} + +class VueImpl { + constructor(props, ctx) { + defineGetter(this, '$props', () => props); + defineGetter(this, '$attrs', () => ctx.attrs); + defineGetter(this, '$slots', () => ctx.slots); + defineGetter(this, '$emit', () => ctx.emit); + Object.keys(props).forEach(key => { + Object.defineProperty(this, key, { + enumerable: false, + configurable: true, + writable: true, + value: props[key] + }); + }); + } + /** @internal */ + + + static get __vccOpts() { + // Early return if `this` is base class as it does not have any options + if (this === Vue) { + return {}; + } + + var cache = this.hasOwnProperty('__vccCache') && this.__vccCache; + + if (cache) { + return cache; + } + + var Ctor = this; // If the options are provided via decorator use it as a base + + var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options + + options.extends = getSuperOptions(Ctor); // Handle mixins + + var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins; + + if (mixins) { + options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins; + } + + options.methods = _objectSpread2({}, options.methods); + options.computed = _objectSpread2({}, options.computed); + var proto = Ctor.prototype; + Object.getOwnPropertyNames(proto).forEach(key => { + if (key === 'constructor') { + return; + } // hooks + + + if (Ctor.__vccHooks.indexOf(key) > -1) { + options[key] = proto[key]; + return; + } + + var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods + + if (typeof descriptor.value === 'function') { + options.methods[key] = descriptor.value; + return; + } // computed properties + + + if (descriptor.get || descriptor.set) { + options.computed[key] = { + get: descriptor.get, + set: descriptor.set + }; + return; + } + }); + + options.setup = function (props, ctx) { + var data = new Ctor(props, ctx); + var dataKeys = Object.keys(data); + var plainData = reactive({}); // Initialize reactive data and convert constructor `this` to a proxy + + dataKeys.forEach(key => { + // Skip if the value is undefined not to make it reactive. + // If the value has `__s`, it's a value from `setup` helper, proceed it later. + if (data[key] === undefined || data[key] && data[key].__s) { + return; + } + + plainData[key] = data[key]; + defineProxy(data, key, plainData); + }); // Invoke composition functions + + dataKeys.forEach(key => { + if (data[key] && data[key].__s) { + plainData[key] = data[key].__s(); + } + }); + return plainData; + }; + + var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators; + + if (decorators) { + decorators.forEach(fn => fn(options)); + } // from Vue Loader + + + var injections = ['render', 'ssrRender', '__file', '__cssModules', '__scopeId', '__hmrId']; + injections.forEach(key => { + if (Ctor[key]) { + options[key] = Ctor[key]; + } + }); + return options; + } + + static registerHooks(keys) { + this.__vccHooks.push(...keys); + } + +} +/** @internal */ + + +VueImpl.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch']; +var Vue = VueImpl; + +function Options(options) { + return Component => { + Component.__vccBase = options; + return Component; + }; +} +function createDecorator(factory) { + return (target, key, index) => { + var Ctor = typeof target === 'function' ? target : target.constructor; + + if (!Ctor.__vccDecorators) { + Ctor.__vccDecorators = []; + } + + if (typeof index !== 'number') { + index = undefined; + } + + Ctor.__vccDecorators.push(options => factory(options, key, index)); + }; +} +function mixins() { + for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) { + Ctors[_key] = arguments[_key]; + } + + var _a; + + return _a = class MixedVue extends Vue { + constructor(props, ctx) { + super(props, ctx); + Ctors.forEach(Ctor => { + var data = new Ctor(props, ctx); + Object.keys(data).forEach(key => { + this[key] = data[key]; + }); + }); + } + + }, _a.__vccMixins = Ctors.map(Ctor => Ctor.__vccOpts), _a; +} +function setup(setupFn) { + // Hack to delay the invocation of setup function. + // Will be called after dealing with class properties. + return { + __s: setupFn + }; +} + +export { Options, Vue, createDecorator, mixins, setup }; diff --git a/dist/vue-class-component.esm-browser.prod.js b/dist/vue-class-component.esm-browser.prod.js new file mode 100644 index 0000000..f883f04 --- /dev/null +++ b/dist/vue-class-component.esm-browser.prod.js @@ -0,0 +1,6 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +import{reactive}from"vue";function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);t&&(c=c.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,c)}return r}function _objectSpread2(e){for(var t=1;tr[t],set:e=>{r[t]=e},enumerable:!0,configurable:!0})}function getSuperOptions(e){var t=Object.getPrototypeOf(e.prototype);if(t)return t.constructor.__vccOpts}class VueImpl{constructor(e,t){defineGetter(this,"$props",()=>e),defineGetter(this,"$attrs",()=>t.attrs),defineGetter(this,"$slots",()=>t.slots),defineGetter(this,"$emit",()=>t.emit),Object.keys(e).forEach(t=>{Object.defineProperty(this,t,{enumerable:!1,configurable:!0,writable:!0,value:e[t]})})}static get __vccOpts(){if(this===Vue)return{};var e=this.hasOwnProperty("__vccCache")&&this.__vccCache;if(e)return e;var t=this,r=this.__vccCache=this.hasOwnProperty("__vccBase")?_objectSpread2({},this.__vccBase):{};r.extends=getSuperOptions(t);var c=this.hasOwnProperty("__vccMixins")&&this.__vccMixins;c&&(r.mixins=r.mixins?r.mixins.concat(c):c),r.methods=_objectSpread2({},r.methods),r.computed=_objectSpread2({},r.computed);var o=t.prototype;Object.getOwnPropertyNames(o).forEach(e=>{if("constructor"!==e)if(t.__vccHooks.indexOf(e)>-1)r[e]=o[e];else{var c=Object.getOwnPropertyDescriptor(o,e);"function"!=typeof c.value?(c.get||c.set)&&(r.computed[e]={get:c.get,set:c.set}):r.methods[e]=c.value}}),r.setup=function(e,r){var c=new t(e,r),o=Object.keys(c),n=reactive({});return o.forEach(e=>{void 0===c[e]||c[e]&&c[e].__s||(n[e]=c[e],defineProxy(c,e,n))}),o.forEach(e=>{c[e]&&c[e].__s&&(n[e]=c[e].__s())}),n};var n=this.hasOwnProperty("__vccDecorators")&&this.__vccDecorators;n&&n.forEach(e=>e(r));return["render","ssrRender","__file","__cssModules","__scopeId","__hmrId"].forEach(e=>{t[e]&&(r[e]=t[e])}),r}static registerHooks(e){this.__vccHooks.push(...e)}}VueImpl.__vccHooks=["data","beforeCreate","created","beforeMount","mounted","beforeUnmount","unmounted","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];var Vue;function Options(e){return t=>(t.__vccBase=e,t)}function createDecorator(e){return(t,r,c)=>{var o="function"==typeof t?t:t.constructor;o.__vccDecorators||(o.__vccDecorators=[]),"number"!=typeof c&&(c=void 0),o.__vccDecorators.push(t=>e(t,r,c))}}function mixins(){for(var e=arguments.length,t=new Array(e),r=0;r{var c=new t(e,r);Object.keys(c).forEach(e=>{this[e]=c[e]})})}}).__vccMixins=t.map(e=>e.__vccOpts),c}function setup(e){return{__s:e}}export{Options,VueImpl as Vue,createDecorator,mixins,setup}; \ No newline at end of file diff --git a/dist/vue-class-component.esm-bundler.js b/dist/vue-class-component.esm-bundler.js new file mode 100644 index 0000000..b7f148c --- /dev/null +++ b/dist/vue-class-component.esm-bundler.js @@ -0,0 +1,431 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +import { reactive } from 'vue'; + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +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; +} + +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; +} + +function _objectSpread2(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; +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } +} + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); +} + +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function () { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; +} + +function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); +} + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); +} + +function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); +} + +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); +} + +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; +} + +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."); +} + +function defineGetter(obj, key, getter) { + Object.defineProperty(obj, key, { + get: getter, + enumerable: false, + configurable: true + }); +} + +function defineProxy(proxy, key, target) { + Object.defineProperty(proxy, key, { + get: function get() { + return target[key]; + }, + set: function set(value) { + target[key] = value; + }, + enumerable: true, + configurable: true + }); +} + +function getSuperOptions(Ctor) { + var superProto = Object.getPrototypeOf(Ctor.prototype); + + if (!superProto) { + return undefined; + } + + var Super = superProto.constructor; + return Super.__vccOpts; +} + +var VueImpl = /*#__PURE__*/function () { + function VueImpl(props, ctx) { + var _this = this; + + _classCallCheck(this, VueImpl); + + defineGetter(this, '$props', function () { + return props; + }); + defineGetter(this, '$attrs', function () { + return ctx.attrs; + }); + defineGetter(this, '$slots', function () { + return ctx.slots; + }); + defineGetter(this, '$emit', function () { + return ctx.emit; + }); + Object.keys(props).forEach(function (key) { + Object.defineProperty(_this, key, { + enumerable: false, + configurable: true, + writable: true, + value: props[key] + }); + }); + } + /** @internal */ + + + _createClass(VueImpl, null, [{ + key: "registerHooks", + value: function registerHooks(keys) { + var _this$__vccHooks; + + (_this$__vccHooks = this.__vccHooks).push.apply(_this$__vccHooks, _toConsumableArray(keys)); + } + }, { + key: "__vccOpts", + get: function get() { + // Early return if `this` is base class as it does not have any options + if (this === Vue) { + return {}; + } + + var cache = this.hasOwnProperty('__vccCache') && this.__vccCache; + + if (cache) { + return cache; + } + + var Ctor = this; // If the options are provided via decorator use it as a base + + var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options + + options["extends"] = getSuperOptions(Ctor); // Handle mixins + + var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins; + + if (mixins) { + options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins; + } + + options.methods = _objectSpread2({}, options.methods); + options.computed = _objectSpread2({}, options.computed); + var proto = Ctor.prototype; + Object.getOwnPropertyNames(proto).forEach(function (key) { + if (key === 'constructor') { + return; + } // hooks + + + if (Ctor.__vccHooks.indexOf(key) > -1) { + options[key] = proto[key]; + return; + } + + var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods + + if (typeof descriptor.value === 'function') { + options.methods[key] = descriptor.value; + return; + } // computed properties + + + if (descriptor.get || descriptor.set) { + options.computed[key] = { + get: descriptor.get, + set: descriptor.set + }; + return; + } + }); + + options.setup = function (props, ctx) { + var data = new Ctor(props, ctx); + var dataKeys = Object.keys(data); + var plainData = reactive({}); // Initialize reactive data and convert constructor `this` to a proxy + + dataKeys.forEach(function (key) { + // Skip if the value is undefined not to make it reactive. + // If the value has `__s`, it's a value from `setup` helper, proceed it later. + if (data[key] === undefined || data[key] && data[key].__s) { + return; + } + + plainData[key] = data[key]; + defineProxy(data, key, plainData); + }); // Invoke composition functions + + dataKeys.forEach(function (key) { + if (data[key] && data[key].__s) { + plainData[key] = data[key].__s(); + } + }); + return plainData; + }; + + var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators; + + if (decorators) { + decorators.forEach(function (fn) { + return fn(options); + }); + } // from Vue Loader + + + var injections = ['render', 'ssrRender', '__file', '__cssModules', '__scopeId', '__hmrId']; + injections.forEach(function (key) { + if (Ctor[key]) { + options[key] = Ctor[key]; + } + }); + return options; + } + }]); + + return VueImpl; +}(); +/** @internal */ + + +VueImpl.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch']; +var Vue = VueImpl; + +function Options(options) { + return function (Component) { + Component.__vccBase = options; + return Component; + }; +} +function createDecorator(factory) { + return function (target, key, index) { + var Ctor = typeof target === 'function' ? target : target.constructor; + + if (!Ctor.__vccDecorators) { + Ctor.__vccDecorators = []; + } + + if (typeof index !== 'number') { + index = undefined; + } + + Ctor.__vccDecorators.push(function (options) { + return factory(options, key, index); + }); + }; +} +function mixins() { + for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) { + Ctors[_key] = arguments[_key]; + } + + var _a; + + return _a = /*#__PURE__*/function (_Vue) { + _inherits(MixedVue, _Vue); + + var _super = _createSuper(MixedVue); + + function MixedVue(props, ctx) { + var _this; + + _classCallCheck(this, MixedVue); + + _this = _super.call(this, props, ctx); + Ctors.forEach(function (Ctor) { + var data = new Ctor(props, ctx); + Object.keys(data).forEach(function (key) { + _this[key] = data[key]; + }); + }); + return _this; + } + + return MixedVue; + }(Vue), _a.__vccMixins = Ctors.map(function (Ctor) { + return Ctor.__vccOpts; + }), _a; +} +function setup(setupFn) { + // Hack to delay the invocation of setup function. + // Will be called after dealing with class properties. + return { + __s: setupFn + }; +} + +export { Options, Vue, createDecorator, mixins, setup }; diff --git a/dist/vue-class-component.esm.browser.js b/dist/vue-class-component.esm.browser.js index 6df468a..b448447 100644 --- a/dist/vue-class-component.esm.browser.js +++ b/dist/vue-class-component.esm.browser.js @@ -1,5 +1,5 @@ /** - * vue-class-component v7.2.3 + * vue-class-component v7.2.4 * (c) 2015-present Evan You * @license MIT */ @@ -89,15 +89,13 @@ function collectDataFromConstructor(vm, Component) { } keys.forEach(key => { - if (key.charAt(0) !== '_') { - Object.defineProperty(this, key, { - get: () => vm[key], - set: value => { - vm[key] = value; - }, - configurable: true - }); - } + Object.defineProperty(this, key, { + get: () => vm[key], + set: value => { + vm[key] = value; + }, + configurable: true + }); }); }; // should be acquired class property values diff --git a/dist/vue-class-component.esm.browser.min.js b/dist/vue-class-component.esm.browser.min.js index 4191e57..e9b8a35 100644 --- a/dist/vue-class-component.esm.browser.min.js +++ b/dist/vue-class-component.esm.browser.min.js @@ -1,6 +1,6 @@ /** - * vue-class-component v7.2.3 + * vue-class-component v7.2.4 * (c) 2015-present Evan You * @license MIT */ -import Vue from"vue";function reflectionIsSupported(){return"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys}function copyReflectionMetadata(e,t){forwardMetadata(e,t),Object.getOwnPropertyNames(t.prototype).forEach(r=>{forwardMetadata(e.prototype,t.prototype,r)}),Object.getOwnPropertyNames(t).forEach(r=>{forwardMetadata(e,t,r)})}function forwardMetadata(e,t,r){(r?Reflect.getOwnMetadataKeys(t,r):Reflect.getOwnMetadataKeys(t)).forEach(o=>{var a=r?Reflect.getOwnMetadata(o,t,r):Reflect.getOwnMetadata(o,t);r?Reflect.defineMetadata(o,a,e,r):Reflect.defineMetadata(o,a,e)})}var fakeArray={__proto__:[]},hasProto=fakeArray instanceof Array;function createDecorator(e){return(t,r,o)=>{var a="function"==typeof t?t:t.constructor;a.__decorators__||(a.__decorators__=[]),"number"!=typeof o&&(o=void 0),a.__decorators__.push(t=>e(t,r,o))}}function mixins(){for(var e=arguments.length,t=new Array(e),r=0;r{"_"!==t.charAt(0)&&Object.defineProperty(this,t,{get:()=>e[t],set:r=>{e[t]=r},configurable:!0})})};var o=new t;t.prototype._init=r;var a={};return Object.keys(o).forEach(e=>{void 0!==o[e]&&(a[e]=o[e])}),a}var $internalHooks=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function componentFactory(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.name=t.name||e._componentTag||e.name;var r=e.prototype;Object.getOwnPropertyNames(r).forEach(function(e){if("constructor"!==e)if($internalHooks.indexOf(e)>-1)t[e]=r[e];else{var o=Object.getOwnPropertyDescriptor(r,e);void 0!==o.value?"function"==typeof o.value?(t.methods||(t.methods={}))[e]=o.value:(t.mixins||(t.mixins=[])).push({data:()=>({[e]:o.value})}):(o.get||o.set)&&((t.computed||(t.computed={}))[e]={get:o.get,set:o.set})}}),(t.mixins||(t.mixins=[])).push({data(){return collectDataFromConstructor(this,e)}});var o=e.__decorators__;o&&(o.forEach(e=>e(t)),delete e.__decorators__);var a=Object.getPrototypeOf(e.prototype),n=a instanceof Vue?a.constructor:Vue,c=n.extend(t);return forwardStaticMembers(c,e,n),reflectionIsSupported()&©ReflectionMetadata(c,e),c}var shouldIgnore={prototype:!0,arguments:!0,callee:!0,caller:!0};function forwardStaticMembers(e,t,r){Object.getOwnPropertyNames(t).forEach(o=>{if(!shouldIgnore[o]){var a=Object.getOwnPropertyDescriptor(e,o);if(!a||a.configurable){var n=Object.getOwnPropertyDescriptor(t,o);if(!hasProto){if("cid"===o)return;var c=Object.getOwnPropertyDescriptor(r,o);if(!isPrimitive(n.value)&&c&&c.value===n.value)return}Object.defineProperty(e,o,n)}}})}function Component(e){return"function"==typeof e?componentFactory(e):function(t){return componentFactory(t,e)}}Component.registerHooks=function(e){$internalHooks.push(...e)};export default Component;export{createDecorator,mixins}; \ No newline at end of file +import Vue from"vue";function reflectionIsSupported(){return"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys}function copyReflectionMetadata(e,t){forwardMetadata(e,t),Object.getOwnPropertyNames(t.prototype).forEach(r=>{forwardMetadata(e.prototype,t.prototype,r)}),Object.getOwnPropertyNames(t).forEach(r=>{forwardMetadata(e,t,r)})}function forwardMetadata(e,t,r){(r?Reflect.getOwnMetadataKeys(t,r):Reflect.getOwnMetadataKeys(t)).forEach(o=>{var a=r?Reflect.getOwnMetadata(o,t,r):Reflect.getOwnMetadata(o,t);r?Reflect.defineMetadata(o,a,e,r):Reflect.defineMetadata(o,a,e)})}var fakeArray={__proto__:[]},hasProto=fakeArray instanceof Array;function createDecorator(e){return(t,r,o)=>{var a="function"==typeof t?t:t.constructor;a.__decorators__||(a.__decorators__=[]),"number"!=typeof o&&(o=void 0),a.__decorators__.push(t=>e(t,r,o))}}function mixins(){for(var e=arguments.length,t=new Array(e),r=0;r{Object.defineProperty(this,t,{get:()=>e[t],set:r=>{e[t]=r},configurable:!0})})};var o=new t;t.prototype._init=r;var a={};return Object.keys(o).forEach(e=>{void 0!==o[e]&&(a[e]=o[e])}),a}var $internalHooks=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];function componentFactory(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.name=t.name||e._componentTag||e.name;var r=e.prototype;Object.getOwnPropertyNames(r).forEach(function(e){if("constructor"!==e)if($internalHooks.indexOf(e)>-1)t[e]=r[e];else{var o=Object.getOwnPropertyDescriptor(r,e);void 0!==o.value?"function"==typeof o.value?(t.methods||(t.methods={}))[e]=o.value:(t.mixins||(t.mixins=[])).push({data:()=>({[e]:o.value})}):(o.get||o.set)&&((t.computed||(t.computed={}))[e]={get:o.get,set:o.set})}}),(t.mixins||(t.mixins=[])).push({data(){return collectDataFromConstructor(this,e)}});var o=e.__decorators__;o&&(o.forEach(e=>e(t)),delete e.__decorators__);var a=Object.getPrototypeOf(e.prototype),n=a instanceof Vue?a.constructor:Vue,c=n.extend(t);return forwardStaticMembers(c,e,n),reflectionIsSupported()&©ReflectionMetadata(c,e),c}var shouldIgnore={prototype:!0,arguments:!0,callee:!0,caller:!0};function forwardStaticMembers(e,t,r){Object.getOwnPropertyNames(t).forEach(o=>{if(!shouldIgnore[o]){var a=Object.getOwnPropertyDescriptor(e,o);if(!a||a.configurable){var n=Object.getOwnPropertyDescriptor(t,o);if(!hasProto){if("cid"===o)return;var c=Object.getOwnPropertyDescriptor(r,o);if(!isPrimitive(n.value)&&c&&c.value===n.value)return}Object.defineProperty(e,o,n)}}})}function Component(e){return"function"==typeof e?componentFactory(e):function(t){return componentFactory(t,e)}}Component.registerHooks=function(e){$internalHooks.push(...e)};export default Component;export{createDecorator,mixins}; \ No newline at end of file diff --git a/dist/vue-class-component.esm.js b/dist/vue-class-component.esm.js index 511bc43..0a67a0d 100644 --- a/dist/vue-class-component.esm.js +++ b/dist/vue-class-component.esm.js @@ -1,5 +1,5 @@ /** - * vue-class-component v7.2.3 + * vue-class-component v7.2.4 * (c) 2015-present Evan You * @license MIT */ @@ -143,17 +143,15 @@ function collectDataFromConstructor(vm, Component) { } keys.forEach(function (key) { - if (key.charAt(0) !== '_') { - Object.defineProperty(_this, key, { - get: function get() { - return vm[key]; - }, - set: function set(value) { - vm[key] = value; - }, - configurable: true - }); - } + Object.defineProperty(_this, key, { + get: function get() { + return vm[key]; + }, + set: function set(value) { + vm[key] = value; + }, + configurable: true + }); }); }; // should be acquired class property values diff --git a/dist/vue-class-component.global.js b/dist/vue-class-component.global.js new file mode 100644 index 0000000..47d2e9a --- /dev/null +++ b/dist/vue-class-component.global.js @@ -0,0 +1,440 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +var VueClassComponent = (function (exports, vue) { + 'use strict'; + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + 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; + } + + 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; + } + + function _objectSpread2(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; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); + } + + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function () { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; + } + + function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); + } + + function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + } + + function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); + } + + 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); + } + + 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; + } + + 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."); + } + + function defineGetter(obj, key, getter) { + Object.defineProperty(obj, key, { + get: getter, + enumerable: false, + configurable: true + }); + } + + function defineProxy(proxy, key, target) { + Object.defineProperty(proxy, key, { + get: function get() { + return target[key]; + }, + set: function set(value) { + target[key] = value; + }, + enumerable: true, + configurable: true + }); + } + + function getSuperOptions(Ctor) { + var superProto = Object.getPrototypeOf(Ctor.prototype); + + if (!superProto) { + return undefined; + } + + var Super = superProto.constructor; + return Super.__vccOpts; + } + + var VueImpl = /*#__PURE__*/function () { + function VueImpl(props, ctx) { + var _this = this; + + _classCallCheck(this, VueImpl); + + defineGetter(this, '$props', function () { + return props; + }); + defineGetter(this, '$attrs', function () { + return ctx.attrs; + }); + defineGetter(this, '$slots', function () { + return ctx.slots; + }); + defineGetter(this, '$emit', function () { + return ctx.emit; + }); + Object.keys(props).forEach(function (key) { + Object.defineProperty(_this, key, { + enumerable: false, + configurable: true, + writable: true, + value: props[key] + }); + }); + } + /** @internal */ + + + _createClass(VueImpl, null, [{ + key: "registerHooks", + value: function registerHooks(keys) { + var _this$__vccHooks; + + (_this$__vccHooks = this.__vccHooks).push.apply(_this$__vccHooks, _toConsumableArray(keys)); + } + }, { + key: "__vccOpts", + get: function get() { + // Early return if `this` is base class as it does not have any options + if (this === Vue) { + return {}; + } + + var cache = this.hasOwnProperty('__vccCache') && this.__vccCache; + + if (cache) { + return cache; + } + + var Ctor = this; // If the options are provided via decorator use it as a base + + var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options + + options["extends"] = getSuperOptions(Ctor); // Handle mixins + + var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins; + + if (mixins) { + options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins; + } + + options.methods = _objectSpread2({}, options.methods); + options.computed = _objectSpread2({}, options.computed); + var proto = Ctor.prototype; + Object.getOwnPropertyNames(proto).forEach(function (key) { + if (key === 'constructor') { + return; + } // hooks + + + if (Ctor.__vccHooks.indexOf(key) > -1) { + options[key] = proto[key]; + return; + } + + var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods + + if (typeof descriptor.value === 'function') { + options.methods[key] = descriptor.value; + return; + } // computed properties + + + if (descriptor.get || descriptor.set) { + options.computed[key] = { + get: descriptor.get, + set: descriptor.set + }; + return; + } + }); + + options.setup = function (props, ctx) { + var data = new Ctor(props, ctx); + var dataKeys = Object.keys(data); + var plainData = vue.reactive({}); // Initialize reactive data and convert constructor `this` to a proxy + + dataKeys.forEach(function (key) { + // Skip if the value is undefined not to make it reactive. + // If the value has `__s`, it's a value from `setup` helper, proceed it later. + if (data[key] === undefined || data[key] && data[key].__s) { + return; + } + + plainData[key] = data[key]; + defineProxy(data, key, plainData); + }); // Invoke composition functions + + dataKeys.forEach(function (key) { + if (data[key] && data[key].__s) { + plainData[key] = data[key].__s(); + } + }); + return plainData; + }; + + var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators; + + if (decorators) { + decorators.forEach(function (fn) { + return fn(options); + }); + } // from Vue Loader + + + var injections = ['render', 'ssrRender', '__file', '__cssModules', '__scopeId', '__hmrId']; + injections.forEach(function (key) { + if (Ctor[key]) { + options[key] = Ctor[key]; + } + }); + return options; + } + }]); + + return VueImpl; + }(); + /** @internal */ + + + VueImpl.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch']; + var Vue = VueImpl; + + function Options(options) { + return function (Component) { + Component.__vccBase = options; + return Component; + }; + } + function createDecorator(factory) { + return function (target, key, index) { + var Ctor = typeof target === 'function' ? target : target.constructor; + + if (!Ctor.__vccDecorators) { + Ctor.__vccDecorators = []; + } + + if (typeof index !== 'number') { + index = undefined; + } + + Ctor.__vccDecorators.push(function (options) { + return factory(options, key, index); + }); + }; + } + function mixins() { + for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) { + Ctors[_key] = arguments[_key]; + } + + var _a; + + return _a = /*#__PURE__*/function (_Vue) { + _inherits(MixedVue, _Vue); + + var _super = _createSuper(MixedVue); + + function MixedVue(props, ctx) { + var _this; + + _classCallCheck(this, MixedVue); + + _this = _super.call(this, props, ctx); + Ctors.forEach(function (Ctor) { + var data = new Ctor(props, ctx); + Object.keys(data).forEach(function (key) { + _this[key] = data[key]; + }); + }); + return _this; + } + + return MixedVue; + }(Vue), _a.__vccMixins = Ctors.map(function (Ctor) { + return Ctor.__vccOpts; + }), _a; + } + function setup(setupFn) { + // Hack to delay the invocation of setup function. + // Will be called after dealing with class properties. + return { + __s: setupFn + }; + } + + exports.Options = Options; + exports.Vue = Vue; + exports.createDecorator = createDecorator; + exports.mixins = mixins; + exports.setup = setup; + + return exports; + +}({}, Vue)); diff --git a/dist/vue-class-component.global.prod.js b/dist/vue-class-component.global.prod.js new file mode 100644 index 0000000..f331ecf --- /dev/null +++ b/dist/vue-class-component.global.prod.js @@ -0,0 +1,6 @@ +/** + * vue-class-component v8.0.0-alpha.6 + * (c) 2015-present Evan You + * @license MIT + */ +var VueClassComponent=function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r-1)n[t]=c[t];else{var e=Object.getOwnPropertyDescriptor(c,t);"function"!=typeof e.value?(e.get||e.set)&&(n.computed[t]={get:e.get,set:e.set}):n.methods[t]=e.value}}),n.setup=function(t,n){var o=new r(t,n),c=Object.keys(o),i=e.reactive({});return c.forEach(function(t){void 0===o[t]||o[t]&&o[t].__s||(i[t]=o[t],function(t,e,r){Object.defineProperty(t,e,{get:function(){return r[e]},set:function(t){r[e]=t},enumerable:!0,configurable:!0})}(o,t,i))}),c.forEach(function(t){o[t]&&o[t].__s&&(i[t]=o[t].__s())}),i};var u=this.hasOwnProperty("__vccDecorators")&&this.__vccDecorators;u&&u.forEach(function(t){return t(n)});return["render","ssrRender","__file","__cssModules","__scopeId","__hmrId"].forEach(function(t){r[t]&&(n[t]=r[t])}),n}}],(c=null)&&n(o.prototype,c),u&&n(o,u),t}();v.__vccHooks=["data","beforeCreate","created","beforeMount","mounted","beforeUnmount","unmounted","beforeUpdate","updated","activated","deactivated","render","errorCaptured","serverPrefetch"];var b=v;return t.Options=function(t){return function(e){return e.__vccBase=t,e}},t.Vue=b,t.createDecorator=function(t){return function(e,r,n){var o="function"==typeof e?e:e.constructor;o.__vccDecorators||(o.__vccDecorators=[]),"number"!=typeof n&&(n=void 0),o.__vccDecorators.push(function(e){return t(e,r,n)})}},t.mixins=function(){for(var t=arguments.length,e=new Array(t),n=0;n1&&void 0!==arguments[1]?arguments[1]:{};n.name=n.name||e._componentTag||e.name;var c=e.prototype;Object.getOwnPropertyNames(c).forEach(function(e){if("constructor"!==e)if(i.indexOf(e)>-1)n[e]=c[e];else{var t=Object.getOwnPropertyDescriptor(c,e);void 0!==t.value?"function"==typeof t.value?(n.methods||(n.methods={}))[e]=t.value:(n.mixins||(n.mixins=[])).push({data:function(){return function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},e,t.value)}}):(t.get||t.set)&&((n.computed||(n.computed={}))[e]={get:t.get,set:t.set})}}),(n.mixins||(n.mixins=[])).push({data:function(){return function(e,t){var r=t.prototype._init;t.prototype._init=function(){var t=this,r=Object.getOwnPropertyNames(e);if(e.$options.props)for(var n in e.$options.props)e.hasOwnProperty(n)||r.push(n);r.forEach(function(r){"_"!==r.charAt(0)&&Object.defineProperty(t,r,{get:function(){return e[r]},set:function(t){e[r]=t},configurable:!0})})};var n=new t;t.prototype._init=r;var o={};return Object.keys(n).forEach(function(e){void 0!==n[e]&&(o[e]=n[e])}),o}(this,e)}});var u=e.__decorators__;u&&(u.forEach(function(e){return e(n)}),delete e.__decorators__);var p,s,d=Object.getPrototypeOf(e.prototype),y=d instanceof t?d.constructor:t,l=y.extend(n);return function(e,t,n){Object.getOwnPropertyNames(t).forEach(function(o){if(!f[o]){var i=Object.getOwnPropertyDescriptor(e,o);if(!i||i.configurable){var c,u,p=Object.getOwnPropertyDescriptor(t,o);if(!a){if("cid"===o)return;var s=Object.getOwnPropertyDescriptor(n,o);if(c=p.value,u=r(c),null!=c&&("object"===u||"function"===u)&&s&&s.value===p.value)return}Object.defineProperty(e,o,p)}}})}(l,e,y),"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys&&(o(p=l,s=e),Object.getOwnPropertyNames(s.prototype).forEach(function(e){o(p.prototype,s.prototype,e)}),Object.getOwnPropertyNames(s).forEach(function(e){o(p,s,e)})),l}var f={prototype:!0,arguments:!0,callee:!0,caller:!0};function u(e){return"function"==typeof e?c(e):function(t){return c(t,e)}}u.registerHooks=function(e){i.push.apply(i,n(e))},e.createDecorator=function(e){return function(t,r,n){var o="function"==typeof t?t:t.constructor;o.__decorators__||(o.__decorators__=[]),"number"!=typeof n&&(n=void 0),o.__decorators__.push(function(t){return e(t,r,n)})}},e.default=u,e.mixins=function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:{};n.name=n.name||e._componentTag||e.name;var c=e.prototype;Object.getOwnPropertyNames(c).forEach(function(e){if("constructor"!==e)if(i.indexOf(e)>-1)n[e]=c[e];else{var t=Object.getOwnPropertyDescriptor(c,e);void 0!==t.value?"function"==typeof t.value?(n.methods||(n.methods={}))[e]=t.value:(n.mixins||(n.mixins=[])).push({data:function(){return function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},e,t.value)}}):(t.get||t.set)&&((n.computed||(n.computed={}))[e]={get:t.get,set:t.set})}}),(n.mixins||(n.mixins=[])).push({data:function(){return function(e,t){var r=t.prototype._init;t.prototype._init=function(){var t=this,r=Object.getOwnPropertyNames(e);if(e.$options.props)for(var n in e.$options.props)e.hasOwnProperty(n)||r.push(n);r.forEach(function(r){Object.defineProperty(t,r,{get:function(){return e[r]},set:function(t){e[r]=t},configurable:!0})})};var n=new t;t.prototype._init=r;var o={};return Object.keys(n).forEach(function(e){void 0!==n[e]&&(o[e]=n[e])}),o}(this,e)}});var u=e.__decorators__;u&&(u.forEach(function(e){return e(n)}),delete e.__decorators__);var p,s,d=Object.getPrototypeOf(e.prototype),y=d instanceof t?d.constructor:t,l=y.extend(n);return function(e,t,n){Object.getOwnPropertyNames(t).forEach(function(o){if(!f[o]){var i=Object.getOwnPropertyDescriptor(e,o);if(!i||i.configurable){var c,u,p=Object.getOwnPropertyDescriptor(t,o);if(!a){if("cid"===o)return;var s=Object.getOwnPropertyDescriptor(n,o);if(c=p.value,u=r(c),null!=c&&("object"===u||"function"===u)&&s&&s.value===p.value)return}Object.defineProperty(e,o,p)}}})}(l,e,y),"undefined"!=typeof Reflect&&Reflect.defineMetadata&&Reflect.getOwnMetadataKeys&&(o(p=l,s=e),Object.getOwnPropertyNames(s.prototype).forEach(function(e){o(p.prototype,s.prototype,e)}),Object.getOwnPropertyNames(s).forEach(function(e){o(p,s,e)})),l}var f={prototype:!0,arguments:!0,callee:!0,caller:!0};function u(e){return"function"==typeof e?c(e):function(t){return c(t,e)}}u.registerHooks=function(e){i.push.apply(i,n(e))},e.createDecorator=function(e){return function(t,r,n){var o="function"==typeof t?t:t.constructor;o.__decorators__||(o.__decorators__=[]),"number"!=typeof n&&(n=void 0),o.__decorators__.push(function(t){return e(t,r,n)})}},e.default=u,e.mixins=function(){for(var e=arguments.length,r=new Array(e),n=0;n