From fa27d929802c3721a304353270a535fe9ca9ef2f Mon Sep 17 00:00:00 2001 From: Steffan Date: Mon, 27 Aug 2018 13:19:44 +0200 Subject: [PATCH] v1.0.7 --- README.md | 4 +-- dist/vue-fields.common.js | 51 +++++++++++++++++++++++---------------- dist/vue-fields.esm.js | 51 +++++++++++++++++++++++---------------- dist/vue-fields.js | 51 +++++++++++++++++++++++---------------- dist/vue-fields.min.js | 4 +-- package.json | 2 +- 6 files changed, 95 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 3e68aba..b0eb38d 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ $ npm install vue-fields ``` ### CDN -Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-fields@1.0.6) or [unpkg](https://unpkg.com/vue-fields@1.0.6). +Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-fields@1.0.7) or [unpkg](https://unpkg.com/vue-fields@1.0.7). ```html - + ``` ## Changelog diff --git a/dist/vue-fields.common.js b/dist/vue-fields.common.js index 69bf5cc..dc3fa32 100644 --- a/dist/vue-fields.common.js +++ b/dist/vue-fields.common.js @@ -1,5 +1,5 @@ /*! - * vue-fields v1.0.6 + * vue-fields v1.0.7 * https://github.com/pagekit/vue-fields * Released under the MIT License. */ @@ -83,15 +83,25 @@ function set(obj, key, val) { _set(obj, parts.shift(), val); } -function evaluate(self, expr, context) { +var parsedFunc = {}; +var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g; +var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g; - try { - return (Function('c', ("with(c){return " + expr + "}"))).call(self, context); - } catch (e) { - warn(e); - } +function parse(expr) { + return parsedFunc[expr] = parsedFunc[expr] || + Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe, + function (match, unquoted, quoted) { + if ( quoted === void 0 ) quoted = ''; + + return unquoted.replace(expressionRe, + function (match, prefix, expression) { + if ( prefix === void 0 ) prefix = ''; - return false; + return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : ''; + } + ) + quoted; + } + )) + "}")); } function each(obj, iterator) { @@ -319,26 +329,25 @@ var Fields = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_ } }, - evaluate: function evaluate$1(expr, values, config) { + evaluate: function evaluate(expression, values) { if ( values === void 0 ) values = this.values; - if ( config === void 0 ) config = this.config; - - if (isString(expr)) { - var context = {$match: $match, $values: values}; + try { - each(config, function (ref, key) { - var name = ref.name; if ( name === void 0 ) name = key; - - return set(context, name, get(values, name)); + if (isString(expression)) { + expression = parse(expression); } - ); - return evaluate(this, expr, assign(context, values)); + return expression.call(this, values, { + $match: $match, $get: function (key) { return get(values, key); } + }); + + } catch (e) { + warn(e); } - return expr.call(this, values, this); + return true; }, prepare: function prepare(config, prefix) { @@ -409,7 +418,7 @@ var Plugin = { Vue.component('fields', Fields); }, - version: '1.0.6' + version: '1.0.7' }; if (typeof window !== 'undefined' && window.Vue) { diff --git a/dist/vue-fields.esm.js b/dist/vue-fields.esm.js index d21c252..83e94ae 100644 --- a/dist/vue-fields.esm.js +++ b/dist/vue-fields.esm.js @@ -1,5 +1,5 @@ /*! - * vue-fields v1.0.6 + * vue-fields v1.0.7 * https://github.com/pagekit/vue-fields * Released under the MIT License. */ @@ -81,15 +81,25 @@ function set(obj, key, val) { _set(obj, parts.shift(), val); } -function evaluate(self, expr, context) { +var parsedFunc = {}; +var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g; +var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g; - try { - return (Function('c', ("with(c){return " + expr + "}"))).call(self, context); - } catch (e) { - warn(e); - } +function parse(expr) { + return parsedFunc[expr] = parsedFunc[expr] || + Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe, + function (match, unquoted, quoted) { + if ( quoted === void 0 ) quoted = ''; + + return unquoted.replace(expressionRe, + function (match, prefix, expression) { + if ( prefix === void 0 ) prefix = ''; - return false; + return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : ''; + } + ) + quoted; + } + )) + "}")); } function each(obj, iterator) { @@ -317,26 +327,25 @@ var Fields = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_ } }, - evaluate: function evaluate$1(expr, values, config) { + evaluate: function evaluate(expression, values) { if ( values === void 0 ) values = this.values; - if ( config === void 0 ) config = this.config; - - if (isString(expr)) { - var context = {$match: $match, $values: values}; + try { - each(config, function (ref, key) { - var name = ref.name; if ( name === void 0 ) name = key; - - return set(context, name, get(values, name)); + if (isString(expression)) { + expression = parse(expression); } - ); - return evaluate(this, expr, assign(context, values)); + return expression.call(this, values, { + $match: $match, $get: function (key) { return get(values, key); } + }); + + } catch (e) { + warn(e); } - return expr.call(this, values, this); + return true; }, prepare: function prepare(config, prefix) { @@ -407,7 +416,7 @@ var Plugin = { Vue.component('fields', Fields); }, - version: '1.0.6' + version: '1.0.7' }; if (typeof window !== 'undefined' && window.Vue) { diff --git a/dist/vue-fields.js b/dist/vue-fields.js index 4a7c0b2..ef8028d 100644 --- a/dist/vue-fields.js +++ b/dist/vue-fields.js @@ -1,5 +1,5 @@ /*! - * vue-fields v1.0.6 + * vue-fields v1.0.7 * https://github.com/pagekit/vue-fields * Released under the MIT License. */ @@ -87,15 +87,25 @@ _set(obj, parts.shift(), val); } - function evaluate(self, expr, context) { + var parsedFunc = {}; + var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g; + var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g; - try { - return (Function('c', ("with(c){return " + expr + "}"))).call(self, context); - } catch (e) { - warn(e); - } + function parse(expr) { + return parsedFunc[expr] = parsedFunc[expr] || + Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe, + function (match, unquoted, quoted) { + if ( quoted === void 0 ) quoted = ''; + + return unquoted.replace(expressionRe, + function (match, prefix, expression) { + if ( prefix === void 0 ) prefix = ''; - return false; + return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : ''; + } + ) + quoted; + } + )) + "}")); } function each(obj, iterator) { @@ -323,26 +333,25 @@ } }, - evaluate: function evaluate$1(expr, values, config) { + evaluate: function evaluate(expression, values) { if ( values === void 0 ) values = this.values; - if ( config === void 0 ) config = this.config; - - if (isString(expr)) { - var context = {$match: $match, $values: values}; + try { - each(config, function (ref, key) { - var name = ref.name; if ( name === void 0 ) name = key; - - return set(context, name, get(values, name)); + if (isString(expression)) { + expression = parse(expression); } - ); - return evaluate(this, expr, assign(context, values)); + return expression.call(this, values, { + $match: $match, $get: function (key) { return get(values, key); } + }); + + } catch (e) { + warn(e); } - return expr.call(this, values, this); + return true; }, prepare: function prepare(config, prefix) { @@ -413,7 +422,7 @@ Vue.component('fields', Fields); }, - version: '1.0.6' + version: '1.0.7' }; if (typeof window !== 'undefined' && window.Vue) { diff --git a/dist/vue-fields.min.js b/dist/vue-fields.min.js index 60cd860..165db66 100644 --- a/dist/vue-fields.min.js +++ b/dist/vue-fields.min.js @@ -1,7 +1,7 @@ /*! - * vue-fields v1.0.6 + * vue-fields v1.0.7 * https://github.com/pagekit/vue-fields * Released under the MIT License. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueFields=t()}(this,function(){"use strict";var a,i={},u=Object.assign||function(n){var e=[],t=arguments.length-1;for(;0