adaptivecards-templating
Version:
Adaptive Card data binding and templating engine for JavaScript
2 lines • 9.36 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("adaptive-expressions")):"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ACData=t(require("adaptive-expressions")):e.ACData=t(e.AEL)}(this,(function(e){return(()=>{"use strict";var t={716:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(557),t),i(r(241),t)},241:function(e,t){var r=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};function n(e,t,o){if("boolean"==typeof e)return null;switch(e.type){case"array":return Array.isArray(e.items)?function(e,t,a){var o,s;return Array.isArray(e.items)?{type:"Container",items:r(r([],i(e,0,a),!0),null!==(s=null===(o=e.items)||void 0===o?void 0:o.map((function(e,r){return n(e,t+"["+r+"]",a+1)})))&&void 0!==s?s:[],!0)}:null}(e,t,o):function(e,t,n){return{type:"Container",items:r([],i(e,0,n),!0)}}(e,0,o);case"object":return a(e,t,o);case"boolean":return function(e,t){return{type:"Input.Toggle",id:t,title:e.title,label:e.description,value:e.default}}(e,t);case"integer":case"number":return function(e,t){var r,n;return{type:"Input.Number",id:t,title:e.title,placeholder:e.description,value:e.default,min:null!==(r=e.exclusiveMinimum)&&void 0!==r?r:e.minimum,max:null!==(n=e.exclusiveMaximum)&&void 0!==n?n:e.maximum}}(e,t);case"string":return e.enum?function(e,t){return{type:"Input.ChoiceSet",id:t,title:e.title,choices:e.enum.map((function(e){return{title:e,value:e}})),placeholder:e.description,value:e.default}}(e,t):function(e,t){return{type:"Input.Text",id:t,title:e.title,placeholder:e.description,value:e.default,maxLength:e.maxLength,regex:e.pattern}}(e,t);case"date-time":case"time":case"date":return function(e,t){return{type:"Input.Time",id:t,title:e.title,placeholder:e.description,value:e.default}}(e,t);default:return null}}function i(e,t,r){return[e.title?{type:"TextBlock",size:void 0,text:e.title}:null,e.description?{type:"TextBlock",size:void 0,isSubtle:!0,wrap:!0,text:e.description}:null]}function a(e,t,a){var o,s;return{type:"Container",items:r(r([],i(e),!0),null!==(s=null===(o=e.required)||void 0===o?void 0:o.map((function(r){return n(e.properties[r],t+"."+function(e){return encodeURIComponent(e).replace(".","%2e")}(r),a+1)})))&&void 0!==s?s:[],!0)}}Object.defineProperty(t,"__esModule",{value:!0}),t.JSONSchemaCard=void 0,t.JSONSchemaCard=function(e){try{return{type:"AdaptiveCard",body:[a(e,"",0)]}}catch(e){return void console.error(e)}}},557:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Template=t.GlobalSettings=void 0;var n=r(949),i=r(147),a=function(){function e(e){this._stateStack=[],void 0!==e&&(this.$_acTemplateVersion=this.generateVersionJson(),this.$root=e.$root,this.$host=e.$host)}return 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,"$data",{get:function(){return void 0!==this._$data?this._$data:this.$root},set:function(e){this._$data=e},enumerable:!1,configurable:!0}),e.prototype.generateVersionJson=function(){var e=i.version.split("."),t=[];return e[2]&&(t=e[2].split("-")),{major:parseInt(e[0]),minor:parseInt(e[1]),patch:parseInt(t[0]),suffix:t[1]||""}},e._reservedFields=["$data","$when","$root","$index","$host","$_acTemplateVersion"],e}(),o=function(){function e(){this._memory=new n.SimpleObjectMemory(this)}return e.prototype.getValue=function(e){var t=e.length>0&&"$"!==e[0]?"$data."+e:e;return this._memory.getValue(t)},e.prototype.setValue=function(e,t){this._memory.setValue(e,t)},e.prototype.version=function(){return this._memory.version()},e}(),s=function(){function e(){}return e.getUndefinedFieldValueSubstitutionString=void 0,e}();t.GlobalSettings=s;var p=function(){function e(t){this._preparedPayload=e.prepare(t)}return e.prepare=function(t){if("string"==typeof t)return e.parseInterpolatedString(t);if("object"==typeof t&&null!==t){if(Array.isArray(t)){for(var r=[],n=0,i=t;n<i.length;n++){var a=i[n];r.push(e.prepare(a))}return r}r={};for(var o=0,s=Object.keys(t);o<s.length;o++){var p=s[o];r[p]=e.prepare(t[p])}return r}return t},e.internalTryEvaluateExpression=function(e,t,r){var i=new o;i.$root=t.$root,i.$data=t.$data,i.$index=t.$index,i.$host=t.$host,i.$_acTemplateVersion=t.$_acTemplateVersion;var a=void 0;if(r&&((a=new n.Options).nullSubstitution=function(e){var t=void 0;return s.getUndefinedFieldValueSubstitutionString&&(t=s.getUndefinedFieldValueSubstitutionString(e)),t||"${"+e+"}"}),e.type===n.ExpressionType.Concat&&r){for(var p="",u=0,l=e.children;u<l.length;u++){var d=l[u],c=void 0;try{c=d.tryEvaluate(i,a)}catch(e){c={value:void 0,error:e}}c.error&&(c.value="${"+d.toString()+"}"),p+=c.value.toString()}return{value:p,error:void 0}}return e.tryEvaluate(i,a)},e.parseInterpolatedString=function(e){if(e.indexOf("${")>=0){var t=n.Expression.parse("`"+e+"`",(function(e){return n.ExpressionFunctions.standardFunctions.get(e)||new n.ExpressionEvaluator(e,(function(t,r,n){throw new Error("Unknown function "+e)}),n.ReturnType.String)}));if("concat"===t.type){if(!(1!==t.children.length||t.children[0]instanceof n.Constant))return t.children[0];if(2===t.children.length){var r=t.children[0];if(r instanceof n.Constant&&""===r.value&&!(t.children[1]instanceof n.Constant))return t.children[1]}return t}}return e},e.tryEvaluateExpression=function(t,r,n){return e.internalTryEvaluateExpression(t,new a(r),n)},e.prototype.expandSingleObject=function(e){for(var t={},r=0,n=Object.keys(e);r<n.length;r++){var i=n[r];if(!this._context.isReservedField(i)){var a=this.internalExpand(e[i]);void 0!==a&&(t[i]=a)}}return t},e.prototype.internalExpand=function(t){var r;if(this._context.saveState(),Array.isArray(t)){for(var i=[],a=0,o=t;a<o.length;a++){var s=o[a],p=this.internalExpand(s);null!==p&&(Array.isArray(p)?i=i.concat(p):i.push(p))}r=i}else if(t instanceof n.Expression){if((h=e.internalTryEvaluateExpression(t,this._context,!0)).error)throw new Error(h.error);r=h.value}else if("object"==typeof t&&null!==t){var u=t.$when,l=t.$data,d=!1,c=void 0;if(void 0===l)c=[void 0];else{if(l instanceof n.Expression){if((h=e.internalTryEvaluateExpression(l,this._context,!0)).error)throw new Error(h.error);l=h.value}Array.isArray(l)?(c=l,d=!0):c=[l]}r=[];for(var f=0;f<c.length;f++){d&&(this._context.$index=f),void 0!==c[f]&&(this._context.$data=c[f]);var v=!1;if(u instanceof n.Expression){var h,y=!1;(h=e.internalTryEvaluateExpression(u,this._context,!1)).error||(y="boolean"==typeof h.value&&h.value),h.value||this.templateExpansionWarnings.push("WARN: Unable to parse the Adaptive Expression "+u+". The $when condition has been set to false by default."),v=!y}else u&&(this.templateExpansionWarnings.push("WARN: "+u+" is not an Adaptive Expression. The $when condition has been set to false by default."),v=!0);if(!v){var m=this.expandSingleObject(t);null!==m&&r.push(m)}}0===r.length?r=null:1===r.length&&(r=r[0])}else r=t;return this._context.restoreLastState(),r},e.prototype.expand=function(e){return this.templateExpansionWarnings=[],this._context=new a(e),this.internalExpand(this._preparedPayload)},e.prototype.getLastTemplateExpansionWarnings=function(){return this.templateExpansionWarnings},e}();t.Template=p},949:t=>{t.exports=e},147:e=>{e.exports=JSON.parse('{"name":"adaptivecards-templating","version":"2.3.1","description":"Adaptive Card data binding and templating engine for JavaScript","author":"AdaptiveCards","license":"MIT","homepage":"https://adaptivecards.io","repository":{"type":"git","url":"https://github.com/microsoft/AdaptiveCards.git","directory":"source/nodejs/adaptivecards-templating"},"keywords":["adaptivecards","adaptive","cards","microsoft","bot"],"main":"lib/adaptivecards-templating.js","types":"lib/adaptivecards-templating.d.ts","files":["lib","dist","src"],"scripts":{"clean":"rimraf build lib dist","prebuild":"tsc","build":"webpack","watch":"webpack --watch","start":"webpack-dev-server --open","dts":"dts-generator --prefix adaptivecards-templating --project . --out dist/adaptivecards-templating.d.ts","lint":"eslint src/*.ts","release":"npm run build && webpack --mode=production && npm run dts","docs":"npx typedoc"},"devDependencies":{"@types/json-schema":"^7.0.8","adaptive-expressions":"^4.11.0","adaptivecards":"^2.11.1","typedoc":"^0.22.5","typedoc-plugin-markdown":"^3.11.2"},"peerDependencies":{"adaptive-expressions":"^4.11.0"}}')}},r={};return function e(n){var i=r[n];if(void 0!==i)return i.exports;var a=r[n]={exports:{}};return t[n].call(a.exports,a,a.exports,e),a.exports}(716)})()}));
//# sourceMappingURL=adaptivecards-templating.min.js.map