adaptivecards-templating
Advanced tools
Comparing version 0.1.0-alpha1 to 0.1.1-alpha.0
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ACData=t():e.ACData=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var i=["/","*","-","+","==","!=","<","<=",">",">="],a=["identifier","string","number","boolean"],s=function(){function e(){}return e.init=function(){e.rules.push({tokenType:void 0,regEx:/^\s/},{tokenType:"{",regEx:/^{/},{tokenType:"?#",regEx:/^\?#/},{tokenType:"}",regEx:/^}/},{tokenType:"[",regEx:/^\[/},{tokenType:"]",regEx:/^\]/},{tokenType:"(",regEx:/^\(/},{tokenType:")",regEx:/^\)/},{tokenType:"boolean",regEx:/^true|^false/},{tokenType:"identifier",regEx:/^[$a-z_]+/i},{tokenType:".",regEx:/^\./},{tokenType:",",regEx:/^,/},{tokenType:"+",regEx:/^\+/},{tokenType:"-",regEx:/^-/},{tokenType:"*",regEx:/^\*/},{tokenType:"/",regEx:/^\//},{tokenType:"==",regEx:/^==/},{tokenType:"!=",regEx:/^!=/},{tokenType:"<=",regEx:/^<=/},{tokenType:"<",regEx:/^</},{tokenType:">=",regEx:/^>=/},{tokenType:">",regEx:/^>/},{tokenType:"string",regEx:/^"([^"]*)"/},{tokenType:"string",regEx:/^'([^']*)'/},{tokenType:"number",regEx:/^\d*\.?\d+/})},e.parse=function(t){for(var n=[],r=0;r<t.length;){for(var o=t.substring(r),i=!1,a=0,s=e.rules;a<s.length;a++){var u=s[a],p=u.regEx.exec(o);if(p){if(p.length>2)throw new Error("A tokenizer rule matched more than one group.");null!=u.tokenType&&n.push({type:u.tokenType,value:p[1==p.length?0:1],originalPosition:r}),r+=p[0].length,i=!0;break}}if(!i)throw new Error("Unexpected character "+o[0]+" at position "+r)}return n},e.rules=[],e}();function u(e){if("number"==typeof e||"string"==typeof e||"boolean"==typeof e)return e;throw new Error("Invalid value type: "+typeof e)}s.init();var p=function(){function e(){this._functions={},this._stateStack=[]}return e.init=function(){e._builtInFunctions.substr=function(e,t,n){return"string"==typeof e&&"number"==typeof t&&"number"==typeof n?e.substr(t,n):""},e._builtInFunctions["JSON.parse"]=function(e){return JSON.parse(e)},e._builtInFunctions.if=function(e,t,n){return e?t:n},e._builtInFunctions.toUpper=function(e){return"string"==typeof e?e.toUpperCase():e},e._builtInFunctions.toLower=function(e){return"string"==typeof e?e.toLowerCase():e},e._builtInFunctions["Date.format"]=function(e,t){var n;if("string"==typeof e)n=Date.parse(e);else{if("number"!=typeof e)return e;n=e}var r=new Date(n),o="compact";return"string"==typeof t&&(o=t.toLowerCase(),["long","short","compact"].indexOf(o)<0&&(o="compact")),"compact"===o?r.toLocaleDateString():r.toLocaleDateString(void 0,{day:"numeric",weekday:o,month:o,year:"numeric"})},e._builtInFunctions["Time.format"]=function(e){var t;if("string"==typeof e)t=Date.parse(e);else{if("number"!=typeof e)return e;t=e}return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}},e.prototype.registerFunction=function(e,t){this._functions[e]=t},e.prototype.unregisterFunction=function(e){delete this._functions[e]},e.prototype.getFunction=function(t){var n=this._functions[t];return null==n&&(n=e._builtInFunctions[t]),n},e.prototype.isReservedField=function(t){return e._reservedFields.indexOf(t)>=0},e.prototype.saveState=function(){this._stateStack.push({$data:this.$data,$index:this.$index})},e.prototype.restoreLastState=function(){if(0==this._stateStack.length)throw new Error("There is no evaluation context state to restore.");var e=this._stateStack.pop();this.$data=e.$data,this.$index=e.$index},Object.defineProperty(e.prototype,"currentDataContext",{get:function(){return null!=this.$data?this.$data:this.$root},enumerable:!0,configurable:!0}),e._reservedFields=["$data","$root","$index"],e._builtInFunctions={},e}();t.EvaluationContext=p,p.init();var c=function(){return function(){}}(),f=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.nodes=[],t.allowNull=!0,t}return o(t,e),t.prototype.evaluate=function(e){for(var t=this.nodes,n=0,r=[["/","*"],["-","+"],["==","!=","<","<=",">",">="]];n<r.length;n++)for(var o=r[n],i=0;i<t.length;){var a=t[i];if(a instanceof v&&o.indexOf(a.operator)>=0){var s=u(t[i-1].evaluate(e)),p=u(t[i+1].evaluate(e));if(typeof s!=typeof p)throw new Error("Incompatible operands "+s+" and "+p+" for operator "+a.operator);var c=void 0;if("number"==typeof s&&"number"==typeof p)switch(a.operator){case"/":c=s/p;break;case"*":c=s*p;break;case"-":c=s-p;break;case"+":c=s+p}if("string"==typeof s&&"string"==typeof p)switch(a.operator){case"+":c=s+p}switch(a.operator){case"==":c=s==p;break;case"!=":c=s!=p;break;case"<":c=s<p;break;case"<=":c=s<=p;break;case">":c=s>p;break;case">=":c=s>=p}t.splice(i-1,3,new y(c)),i--}i++}return t[0].evaluate(e)},t}(c),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.evaluate=function(e){return this.identifier},t}(c),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.evaluate=function(e){return this.index.evaluate(e)},t}(c),d=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.functionName=null,t.parameters=[],t}return o(t,e),t.prototype.evaluate=function(e){var t=e.getFunction(this.functionName);if(null!=t){for(var n=[],r=0,o=this.parameters;r<o.length;r++){var i=o[r];n.push(i.evaluate(e))}return t.apply(void 0,n)}throw new Error("Undefined function: "+this.functionName)},t}(c),y=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return o(t,e),t.prototype.evaluate=function(e){return this.value},t}(c),v=function(e){function t(t){var n=e.call(this)||this;return n.operator=t,n}return o(t,e),t.prototype.evaluate=function(e){throw new Error("An operator cannot be evaluated on its own.")},t}(c),x=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.parts=[],t}return o(t,e),t.prototype.evaluate=function(e){for(var t=void 0,n=0;n<this.parts.length;){var r=this.parts[n];try{if(r instanceof l&&0==n)switch(r.identifier){case"$root":t=e.$root;break;case"$data":t=e.currentDataContext;break;case"$index":t=e.$index;break;default:t=e.currentDataContext[r.identifier]}else{var o=r.evaluate(e);t=0==n?o:"boolean"!=typeof o?t[o]:t[o.toString()]}}catch(e){return}n++}return t},t}(c),g=function(){function e(e){this._index=0,this._tokens=e}return e.prototype.unexpectedToken=function(){throw new Error("Unexpected token "+this.current.value+" at position "+this.current.originalPosition+".")},e.prototype.unexpectedEoe=function(){throw new Error("Unexpected end of expression.")},e.prototype.moveNext=function(){this._index++},e.prototype.parseToken=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.eoe&&this.unexpectedEoe();var n=this.current;return e.indexOf(this.current.type)<0&&this.unexpectedToken(),this.moveNext(),n},e.prototype.parseOptionalToken=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!this.eoe)return!(e.indexOf(this.current.type)<0)&&(this.moveNext(),!0);this.unexpectedEoe()},e.prototype.parseFunctionCall=function(e){var t=new d;t.functionName=e,this.parseToken("(");var n=this.parseExpression(),r=!1;if(n){t.parameters.push(n);do{if(r=this.parseOptionalToken(",")){var o=this.parseExpression();t.parameters.push(o)}}while(r)}return this.parseToken(")"),t},e.prototype.parseIdentifier=function(){var e=new l;return e.identifier=this.current.value,this.moveNext(),e},e.prototype.parseIndexer=function(){var e=new h;return this.parseToken("["),e.index=this.parseExpression(),this.parseToken("]"),e},e.prototype.parsePath=function(){for(var e=new x,t=["identifier","("];!this.eoe;){if(t.indexOf(this.current.type)<0)return e;switch(this.current.type){case"(":if(0==e.parts.length)this.moveNext(),e.parts.push(this.parseExpression()),this.parseToken(")");else{for(var n="",r=0,o=e.parts;r<o.length;r++){var i=o[r];i instanceof l||this.unexpectedToken(),""!=n&&(n+="."),n+=i.identifier}e.parts=[],e.parts.push(this.parseFunctionCall(n))}t=[".","["];break;case"[":e.parts.push(this.parseIndexer()),t=[".","(","["];break;case"identifier":e.parts.push(this.parseIdentifier()),t=[".","(","["];break;case".":this.moveNext(),t=["identifier"];break;default:t=[]}}},e.prototype.parseExpression=function(){for(var e=new f,t=a.concat("(","+","-");!this.eoe;){if(t.indexOf(this.current.type)<0)return 0==e.nodes.length&&this.unexpectedToken(),e;switch(this.current.type){case"(":case"identifier":e.nodes.push(this.parsePath()),t=i;break;case"string":case"number":case"boolean":"string"==this.current.type?e.nodes.push(new y(this.current.value)):"number"==this.current.type?e.nodes.push(new y(parseFloat(this.current.value))):e.nodes.push(new y("true"===this.current.value)),this.moveNext(),t=i;break;case"-":0==e.nodes.length?(e.nodes.push(new y(-1)),e.nodes.push(new v("*")),t=["identifier","number","("]):(e.nodes.push(new v(this.current.type)),t=a.concat("(")),this.moveNext();break;case"+":0==e.nodes.length?t=a.concat("("):(e.nodes.push(new v(this.current.type)),t=a.concat("(")),this.moveNext();break;case"*":case"/":case"==":case"!=":case"<":case"<=":case">":case">=":e.nodes.push(new v(this.current.type)),this.moveNext(),t=a.concat("(");break;default:t=[]}}},Object.defineProperty(e.prototype,"eoe",{get:function(){return this._index>=this._tokens.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"current",{get:function(){return this._tokens[this._index]},enumerable:!0,configurable:!0}),e.parseBinding=function(t){var n=new e(s.parse(t));n.parseToken("{");var r=!n.parseOptionalToken("?#"),o=n.parseExpression();return n.parseToken("}"),new b(o,r)},e}();t.ExpressionParser=g;var b=function(){function e(e,t){void 0===t&&(t=!0),this.expression=e,this.allowNull=t}return e.prototype.evaluate=function(e){return this.expression.evaluate(e)},e}();t.Binding=b},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(0)),r(n(2))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=function(){function e(){this._parts=[],this._shouldDropOwner=!1}return e.parse=function(t){var n=new e,o=0;do{var i=!1,a=o,s=void 0;do{s=!1,(a=t.indexOf("{",a))>=0&&a+1<t.length&&"{"==t[a+1]&&(a+=2,s=!0)}while(s);if(a>=0){var u=t.indexOf("}",a);if(u>=0){i=!0,a>o&&n._parts.push(t.substring(o,a));var p=t.substring(a,u+1),c=void 0;try{c=r.ExpressionParser.parseBinding(p)}catch(e){c=p}n._parts.push(c),o=u+1}}if(!i){n._parts.push(t.substr(o));break}}while(o<t.length);return 1==n._parts.length&&"string"==typeof n._parts[0]?n._parts[0]:n},e.prototype.evalExpression=function(e,t){var n=e.evaluate(t);return null==n&&(this._shouldDropOwner=this._shouldDropOwner||!e.allowNull),n},e.prototype.internalEvaluate=function(e){if(0!=this._parts.length){if(1==this._parts.length)return"string"==typeof this._parts[0]?this._parts[0]:this.evalExpression(this._parts[0],e);for(var t="",n=0,r=this._parts;n<r.length;n++){var o=r[n];t+="string"==typeof o?o:this.evalExpression(o,e)}return t}},e.prototype.evaluate=function(e){return this._shouldDropOwner=!1,this.internalEvaluate(e)},Object.defineProperty(e.prototype,"shouldDropOwner",{get:function(){return this._shouldDropOwner},enumerable:!0,configurable:!0}),e}(),i=function(){function e(t){this.preparedPayload=e.prepare(t)}return e.prepare=function(t){if("string"==typeof t)return o.parse(t);if("object"==typeof t&&null!=t){if(Array.isArray(t)){for(var n=[],r=0,i=t;r<i.length;r++){var a=i[r];n.push(e.prepare(a))}return n}n={};for(var s=0,u=Object.keys(t);s<u.length;s++){var p=u[s];n[p]=e.prepare(t[p])}return n}return t},e.prototype.expandSingleObject=function(e){for(var t={},n=0,r=Object.keys(e);n<r.length;n++){var o=r[n];if(!this._context.isReservedField(o)){var i=this.internalExpand(e[o]);null!=i&&(t[o]=i)}}return t},e.prototype.internalExpand=function(e){var t;if(this._context.saveState(),Array.isArray(e)){for(var n=[],r=0,i=e;r<i.length;r++){var a=i[r],s=this.internalExpand(a);null!=s&&(Array.isArray(s)?n=n.concat(s):n.push(s))}t=n}else if(e instanceof o)t=e.evaluate(this._context),e.shouldDropOwner&&(t=null);else if("object"==typeof e&&null!=e){var u=!1,p=e.$when;if(p instanceof o){var c=p.evaluate(this._context);"boolean"==typeof c&&(u=!c)}if(u)t=null;else{var f=e.$data;if(null!=f)if(f instanceof o&&(f=f.evaluate(this._context)),Array.isArray(f)){t=[];for(var l=0;l<f.length;l++){this._context.$data=f[l],this._context.$index=l;var h=this.expandSingleObject(e);null!=h&&t.push(h)}}else this._context.$data=f,t=this.expandSingleObject(e);else t=this.expandSingleObject(e)}}else t=e;return this._context.restoreLastState(),t},e.prototype.expand=function(e){return this._context=e,this.internalExpand(this.preparedPayload)},e}();t.Template=i}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ACData=t():e.ACData=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var i=["/","*","-","+","==","!=","<","<=",">",">="],a=["identifier","string","number","boolean"],s=function(){function e(){}return e.init=function(){e.rules.push({tokenType:void 0,regEx:/^\s/},{tokenType:"{",regEx:/^{/},{tokenType:"?#",regEx:/^\?#/},{tokenType:"}",regEx:/^}/},{tokenType:"[",regEx:/^\[/},{tokenType:"]",regEx:/^\]/},{tokenType:"(",regEx:/^\(/},{tokenType:")",regEx:/^\)/},{tokenType:"boolean",regEx:/^true|^false/},{tokenType:"identifier",regEx:/^[$a-z_]+/i},{tokenType:".",regEx:/^\./},{tokenType:",",regEx:/^,/},{tokenType:"+",regEx:/^\+/},{tokenType:"-",regEx:/^-/},{tokenType:"*",regEx:/^\*/},{tokenType:"/",regEx:/^\//},{tokenType:"==",regEx:/^==/},{tokenType:"!=",regEx:/^!=/},{tokenType:"<=",regEx:/^<=/},{tokenType:"<",regEx:/^</},{tokenType:">=",regEx:/^>=/},{tokenType:">",regEx:/^>/},{tokenType:"string",regEx:/^"([^"]*)"/},{tokenType:"string",regEx:/^'([^']*)'/},{tokenType:"number",regEx:/^\d*\.?\d+/})},e.parse=function(t){for(var n=[],r=0;r<t.length;){for(var o=t.substring(r),i=!1,a=0,s=e.rules;a<s.length;a++){var u=s[a],p=u.regEx.exec(o);if(p){if(p.length>2)throw new Error("A tokenizer rule matched more than one group.");null!=u.tokenType&&n.push({type:u.tokenType,value:p[1==p.length?0:1],originalPosition:r}),r+=p[0].length,i=!0;break}}if(!i)throw new Error("Unexpected character "+o[0]+" at position "+r)}return n},e.rules=[],e}();function u(e){if("number"==typeof e||"string"==typeof e||"boolean"==typeof e)return e;throw new Error("Invalid value type: "+typeof e)}s.init();var p=function(){function e(){this._functions={},this._stateStack=[]}return e.init=function(){e._builtInFunctions.substr=function(e,t,n){return"string"==typeof e&&"number"==typeof t&&"number"==typeof n?e.substr(t,n):""},e._builtInFunctions["JSON.parse"]=function(e){return JSON.parse(e)},e._builtInFunctions.if=function(e,t,n){return e?t:n},e._builtInFunctions.toUpper=function(e){return"string"==typeof e?e.toUpperCase():e},e._builtInFunctions.toLower=function(e){return"string"==typeof e?e.toLowerCase():e},e._builtInFunctions["Date.format"]=function(e,t){var n;if("string"==typeof e)n=Date.parse(e);else{if("number"!=typeof e)return e;n=e}var r=new Date(n),o="compact";return"string"==typeof t&&(o=t.toLowerCase(),["long","short","compact"].indexOf(o)<0&&(o="compact")),"compact"===o?r.toLocaleDateString():r.toLocaleDateString(void 0,{day:"numeric",weekday:o,month:o,year:"numeric"})},e._builtInFunctions["Time.format"]=function(e){var t;if("string"==typeof e)t=Date.parse(e);else{if("number"!=typeof e)return e;t=e}return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}},e.prototype.registerFunction=function(e,t){this._functions[e]=t},e.prototype.unregisterFunction=function(e){delete this._functions[e]},e.prototype.getFunction=function(t){var n=this._functions[t];return null==n&&(n=e._builtInFunctions[t]),n},e.prototype.isReservedField=function(t){return e._reservedFields.indexOf(t)>=0},e.prototype.saveState=function(){this._stateStack.push({$data:this.$data,$index:this.$index})},e.prototype.restoreLastState=function(){if(0==this._stateStack.length)throw new Error("There is no evaluation context state to restore.");var e=this._stateStack.pop();this.$data=e.$data,this.$index=e.$index},Object.defineProperty(e.prototype,"currentDataContext",{get:function(){return null!=this.$data?this.$data:this.$root},enumerable:!0,configurable:!0}),e._reservedFields=["$data","$root","$index"],e._builtInFunctions={},e}();t.EvaluationContext=p,p.init();var c=function(){},f=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.nodes=[],t.allowNull=!0,t}return o(t,e),t.prototype.evaluate=function(e){for(var t=this.nodes,n=0,r=[["/","*"],["-","+"],["==","!=","<","<=",">",">="]];n<r.length;n++)for(var o=r[n],i=0;i<t.length;){var a=t[i];if(a instanceof v&&o.indexOf(a.operator)>=0){var s=u(t[i-1].evaluate(e)),p=u(t[i+1].evaluate(e));if(typeof s!=typeof p)throw new Error("Incompatible operands "+s+" and "+p+" for operator "+a.operator);var c=void 0;if("number"==typeof s&&"number"==typeof p)switch(a.operator){case"/":c=s/p;break;case"*":c=s*p;break;case"-":c=s-p;break;case"+":c=s+p}if("string"==typeof s&&"string"==typeof p)switch(a.operator){case"+":c=s+p}switch(a.operator){case"==":c=s==p;break;case"!=":c=s!=p;break;case"<":c=s<p;break;case"<=":c=s<=p;break;case">":c=s>p;break;case">=":c=s>=p}t.splice(i-1,3,new y(c)),i--}i++}return t[0].evaluate(e)},t}(c),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.evaluate=function(e){return this.identifier},t}(c),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.evaluate=function(e){return this.index.evaluate(e)},t}(c),d=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.functionName=null,t.parameters=[],t}return o(t,e),t.prototype.evaluate=function(e){var t=e.getFunction(this.functionName);if(null!=t){for(var n=[],r=0,o=this.parameters;r<o.length;r++){var i=o[r];n.push(i.evaluate(e))}return t.apply(void 0,n)}throw new Error("Undefined function: "+this.functionName)},t}(c),y=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return o(t,e),t.prototype.evaluate=function(e){return this.value},t}(c),v=function(e){function t(t){var n=e.call(this)||this;return n.operator=t,n}return o(t,e),t.prototype.evaluate=function(e){throw new Error("An operator cannot be evaluated on its own.")},t}(c),x=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.parts=[],t}return o(t,e),t.prototype.evaluate=function(e){for(var t=void 0,n=0;n<this.parts.length;){var r=this.parts[n];try{if(r instanceof l&&0==n)switch(r.identifier){case"$root":t=e.$root;break;case"$data":t=e.currentDataContext;break;case"$index":t=e.$index;break;default:t=e.currentDataContext[r.identifier]}else{var o=r.evaluate(e);t=0==n?o:"boolean"!=typeof o?t[o]:t[o.toString()]}}catch(e){return}n++}return t},t}(c),g=function(){function e(e){this._index=0,this._tokens=e}return e.prototype.unexpectedToken=function(){throw new Error("Unexpected token "+this.current.value+" at position "+this.current.originalPosition+".")},e.prototype.unexpectedEoe=function(){throw new Error("Unexpected end of expression.")},e.prototype.moveNext=function(){this._index++},e.prototype.parseToken=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.eoe&&this.unexpectedEoe();var n=this.current;return e.indexOf(this.current.type)<0&&this.unexpectedToken(),this.moveNext(),n},e.prototype.parseOptionalToken=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!this.eoe)return!(e.indexOf(this.current.type)<0)&&(this.moveNext(),!0);this.unexpectedEoe()},e.prototype.parseFunctionCall=function(e){var t=new d;t.functionName=e,this.parseToken("(");var n=this.parseExpression(),r=!1;if(n){t.parameters.push(n);do{if(r=this.parseOptionalToken(",")){var o=this.parseExpression();t.parameters.push(o)}}while(r)}return this.parseToken(")"),t},e.prototype.parseIdentifier=function(){var e=new l;return e.identifier=this.current.value,this.moveNext(),e},e.prototype.parseIndexer=function(){var e=new h;return this.parseToken("["),e.index=this.parseExpression(),this.parseToken("]"),e},e.prototype.parsePath=function(){for(var e=new x,t=["identifier","("];!this.eoe;){if(t.indexOf(this.current.type)<0)return e;switch(this.current.type){case"(":if(0==e.parts.length)this.moveNext(),e.parts.push(this.parseExpression()),this.parseToken(")");else{for(var n="",r=0,o=e.parts;r<o.length;r++){var i=o[r];i instanceof l||this.unexpectedToken(),""!=n&&(n+="."),n+=i.identifier}e.parts=[],e.parts.push(this.parseFunctionCall(n))}t=[".","["];break;case"[":e.parts.push(this.parseIndexer()),t=[".","(","["];break;case"identifier":e.parts.push(this.parseIdentifier()),t=[".","(","["];break;case".":this.moveNext(),t=["identifier"];break;default:t=[]}}},e.prototype.parseExpression=function(){for(var e=new f,t=a.concat("(","+","-");!this.eoe;){if(t.indexOf(this.current.type)<0)return 0==e.nodes.length&&this.unexpectedToken(),e;switch(this.current.type){case"(":case"identifier":e.nodes.push(this.parsePath()),t=i;break;case"string":case"number":case"boolean":"string"==this.current.type?e.nodes.push(new y(this.current.value)):"number"==this.current.type?e.nodes.push(new y(parseFloat(this.current.value))):e.nodes.push(new y("true"===this.current.value)),this.moveNext(),t=i;break;case"-":0==e.nodes.length?(e.nodes.push(new y(-1)),e.nodes.push(new v("*")),t=["identifier","number","("]):(e.nodes.push(new v(this.current.type)),t=a.concat("(")),this.moveNext();break;case"+":0==e.nodes.length?t=a.concat("("):(e.nodes.push(new v(this.current.type)),t=a.concat("(")),this.moveNext();break;case"*":case"/":case"==":case"!=":case"<":case"<=":case">":case">=":e.nodes.push(new v(this.current.type)),this.moveNext(),t=a.concat("(");break;default:t=[]}}},Object.defineProperty(e.prototype,"eoe",{get:function(){return this._index>=this._tokens.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"current",{get:function(){return this._tokens[this._index]},enumerable:!0,configurable:!0}),e.parseBinding=function(t){var n=new e(s.parse(t));n.parseToken("{");var r=!n.parseOptionalToken("?#"),o=n.parseExpression();return n.parseToken("}"),new b(o,r)},e}();t.ExpressionParser=g;var b=function(){function e(e,t){void 0===t&&(t=!0),this.expression=e,this.allowNull=t}return e.prototype.evaluate=function(e){return this.expression.evaluate(e)},e}();t.Binding=b},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(0)),r(n(2))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=function(){function e(){this._parts=[],this._shouldDropOwner=!1}return e.parse=function(t){var n=new e,o=0;do{var i=!1,a=o,s=void 0;do{s=!1,(a=t.indexOf("{",a))>=0&&a+1<t.length&&"{"==t[a+1]&&(a+=2,s=!0)}while(s);if(a>=0){var u=t.indexOf("}",a);if(u>=0){i=!0,a>o&&n._parts.push(t.substring(o,a));var p=t.substring(a,u+1),c=void 0;try{c=r.ExpressionParser.parseBinding(p)}catch(e){c=p}n._parts.push(c),o=u+1}}if(!i){n._parts.push(t.substr(o));break}}while(o<t.length);return 1==n._parts.length&&"string"==typeof n._parts[0]?n._parts[0]:n},e.prototype.evalExpression=function(e,t){var n=e.evaluate(t);return null==n&&(this._shouldDropOwner=this._shouldDropOwner||!e.allowNull),n},e.prototype.internalEvaluate=function(e){if(0!=this._parts.length){if(1==this._parts.length)return"string"==typeof this._parts[0]?this._parts[0]:this.evalExpression(this._parts[0],e);for(var t="",n=0,r=this._parts;n<r.length;n++){var o=r[n];t+="string"==typeof o?o:this.evalExpression(o,e)}return t}},e.prototype.evaluate=function(e){return this._shouldDropOwner=!1,this.internalEvaluate(e)},Object.defineProperty(e.prototype,"shouldDropOwner",{get:function(){return this._shouldDropOwner},enumerable:!0,configurable:!0}),e}(),i=function(){function e(t){this.preparedPayload=e.prepare(t)}return e.prepare=function(t){if("string"==typeof t)return o.parse(t);if("object"==typeof t&&null!=t){if(Array.isArray(t)){for(var n=[],r=0,i=t;r<i.length;r++){var a=i[r];n.push(e.prepare(a))}return n}n={};for(var s=0,u=Object.keys(t);s<u.length;s++){var p=u[s];n[p]=e.prepare(t[p])}return n}return t},e.prototype.expandSingleObject=function(e){for(var t={},n=0,r=Object.keys(e);n<r.length;n++){var o=r[n];if(!this._context.isReservedField(o)){var i=this.internalExpand(e[o]);null!=i&&(t[o]=i)}}return t},e.prototype.internalExpand=function(e){var t;if(this._context.saveState(),Array.isArray(e)){for(var n=[],r=0,i=e;r<i.length;r++){var a=i[r],s=this.internalExpand(a);null!=s&&(Array.isArray(s)?n=n.concat(s):n.push(s))}t=n}else if(e instanceof o)t=e.evaluate(this._context),e.shouldDropOwner&&(t=null);else if("object"==typeof e&&null!=e){var u=!1,p=e.$when;if(p instanceof o){var c=p.evaluate(this._context);"boolean"==typeof c&&(u=!c)}if(u)t=null;else{var f=e.$data;if(null!=f)if(f instanceof o&&(f=f.evaluate(this._context)),Array.isArray(f)){t=[];for(var l=0;l<f.length;l++){this._context.$data=f[l],this._context.$index=l;var h=this.expandSingleObject(e);null!=h&&t.push(h)}}else this._context.$data=f,t=this.expandSingleObject(e);else t=this.expandSingleObject(e)}}else t=e;return this._context.restoreLastState(),t},e.prototype.expand=function(e){return this._context=e,this.internalExpand(this.preparedPayload)},e}();t.Template=i}])}); | ||
//# sourceMappingURL=adaptivecards-templating.min.js.map |
{ | ||
"name": "adaptivecards-templating", | ||
"version": "0.1.0-alpha1", | ||
"description": "Adaptive Card data binding abd tmeplating engine for JavaScript", | ||
"version": "0.1.1-alpha.0", | ||
"description": "Adaptive Card data binding and templating engine for JavaScript", | ||
"author": "AdaptiveCards", | ||
@@ -26,8 +26,8 @@ "license": "MIT", | ||
"rimraf": "^2.6.2", | ||
"typescript": "^3.2.2", | ||
"webpack": "^4.27.1", | ||
"webpack-cli": "^3.1.2", | ||
"typescript": "^3.5.3", | ||
"webpack": "^4.38.0", | ||
"webpack-cli": "^3.3.6", | ||
"webpack-concat-plugin": "^3.0.0", | ||
"webpack-dev-server": "^3.1.14" | ||
"webpack-dev-server": "^3.7.2" | ||
} | ||
} |
# Adaptive Card Data Binding and Templating Engine for JavaScript (Preview) | ||
This library implements a JSON-to-JSON templating/data-bing engine. While it is designed to be used with Adaptive Cards, it is not dependent on Adaptive Cards and can therefore be used in many contexts and applications. | ||
This library implements a JSON-to-JSON templating/data-binding engine. While it is designed to be used with Adaptive Cards, it is not dependent on Adaptive Cards and can therefore be used in many contexts and applications. | ||
For more information about the data binding language implemented by this library, [please refer to GitHub](https://github.com/microsoft/AdaptiveCards/issues/2448) | ||
## Hello World example | ||
## Install and import the module | ||
Here is a simplistic "Hello World" example on how to use the library to generate an Adaptive Card using a template bound to a data object: | ||
### Node | ||
```console | ||
npm install adaptivecards-templating --save | ||
``` | ||
```js | ||
// Import the module: | ||
import * as ACData from "adaptivecards-templating"; | ||
// OR require it: | ||
var ACData = require("adaptivecards-templating"); | ||
``` | ||
### CDN | ||
The unpkg.com CDN makes it easy to load the script in an browser. | ||
The latest release will keep you up to date with features and fixes, but may have breaking changes over time. For maximum stability you should use a specific version. | ||
* `adaptivecards-templating.js` - non-minified, useful for dev | ||
* `adaptivecards-templating.min.js` - minified version, best for production | ||
```html | ||
<!-- Option 1: always load the latest release --> | ||
<script src="https://unpkg.com/adaptivecards-templating/dist/adaptivecards-templating.min.js"></script> | ||
<!-- Option 2: load a specific version (e.g, 0.1.0-alpha1) --> | ||
<script src="https://unpkg.com/adaptivecards@0.1.0-alpha1/dist/adaptivecards-templating.min.js"></script> | ||
``` | ||
Once the library is loaded, the global `ACData` variable is defined and ready to be used. | ||
## Usage | ||
### Hello World example | ||
Here is a simplistic "Hello World" example on how to use the library to generate an Adaptive Card using a template bound to a data object. Note this example requires the [adaptivecards](https://www.npmjs.com/package/adaptivecards) package. | ||
```typescript | ||
import * as ACData from "adaptivecards-templating"; | ||
import * as AdaptiveCards from "adaptivecards"; | ||
// Define a template payload | ||
var templatePayload = { | ||
"type": "AdaptiveCard", | ||
"version": "1.0", | ||
"body": [ | ||
"type": "AdaptiveCard", | ||
"version": "1.0", | ||
"body": [ | ||
{ | ||
@@ -47,7 +87,7 @@ "type": "TextBlock", | ||
## Built-in functions | ||
### Built-in functions | ||
This library provides a set of built-in functions for use in data binding expressions. Note that any function parameter can itself be an expression. | ||
### substr | ||
#### substr | ||
Extracts a substring from a string. | ||
@@ -62,6 +102,6 @@ | ||
|s|The input string| | ||
|index|The index (zero based) where to strat the extraction| | ||
|index|The index (zero based) where to start the extraction| | ||
|count|The number of characters to extract| | ||
### JSON.parse | ||
#### JSON.parse | ||
Converts a string representing JSON data into an object to make it possible to access its individual properties within an expression. | ||
@@ -75,5 +115,5 @@ | ||
|---|---| | ||
|input|The input string. Must be a valid JSOJN payload.| | ||
|input|The input string. Must be a valid JSON payload.| | ||
### if | ||
#### if | ||
Returns a value that depends on whether a condition evaluates to true or false. | ||
@@ -91,3 +131,3 @@ | ||
### toUpper | ||
#### toUpper | ||
Converts a string to its upper case representation. | ||
@@ -103,3 +143,3 @@ | ||
### toLower | ||
#### toLower | ||
Converts a string to its lower case representation. | ||
@@ -115,3 +155,3 @@ | ||
### Date.format | ||
#### Date.format | ||
Formats an ISO 8601 date/time string into a human redable date. | ||
@@ -128,3 +168,3 @@ | ||
### Time.format | ||
#### Time.format | ||
Formats an ISO 8601 date/time string into a human redable time. | ||
@@ -140,4 +180,4 @@ | ||
## Custom functions | ||
Applications can add support for custom functions with the engine, in order to enable additional scenarios. Custom functions need to be registered with the EvaluationContext: | ||
### Custom functions | ||
Applications can add support for custom functions by registering them with the engine. Custom functions open up additional possibilities and scenarios. To register a custom function: | ||
@@ -144,0 +184,0 @@ ```typescript |
Sorry, the diff of this file is not supported yet
290264
209