Liferay.Loader.define("liferay!template-web$codemirror@5.65.2/addon/hint/sql-hint",["module","exports","require","../../lib/codemirror","../../mode/sql/sql"],(function(e,t,r){var n,a=void 0;window;n=function(e){"use strict";var t,r,n,a,o=";",i="AS",s=e.Pos,l=e.cmpPos;function isArray(e){return"[object Array]"==Object.prototype.toString.call(e)}function getText(e){return"string"==typeof e?e:e.text}function wrapTable(e,t){return isArray(t)&&(t={columns:t}),t.text||(t.text=e),t}function getTable(e){return t[e.toUpperCase()]}function shallowClone(e){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function match(e,t){var r=e.length,n=getText(t).substr(0,r);return e.toUpperCase()===n.toUpperCase()}function addMatches(e,t,r,n){if(isArray(r))for(var a=0;a<r.length;a++)match(t,r[a])&&e.push(n(r[a]));else for(var o in r)if(r.hasOwnProperty(o)){var i=r[o];match(t,i=i&&!0!==i?i.displayText?{text:i.text,displayText:i.displayText}:i.text:o)&&e.push(n(i))}}function cleanName(e){"."==e.charAt(0)&&(e=e.substr(1));for(var t=e.split(a+a),r=0;r<t.length;r++)t[r]=t[r].replace(new RegExp(a,"g"),"");return t.join(a)}function insertIdentifierQuotes(e){for(var t=getText(e).split("."),r=0;r<t.length;r++)t[r]=a+t[r].replace(new RegExp(a,"g"),a+a)+a;var n=t.join(".");return"string"==typeof e?n:((e=shallowClone(e)).text=n,e)}function eachWord(e,t){for(var r=e.split(/\s+/),n=0;n<r.length;n++)r[n]&&t(r[n].replace(/[`,;]/g,""))}function findTableByAlias(e,t){for(var r=t.doc,n=r.getValue(),a=e.toUpperCase(),c="",u="",d=[],f={start:s(0,0),end:s(t.lastLine(),t.getLineHandle(t.lastLine()).length)},p=n.indexOf(o);-1!=p;)d.push(r.posFromIndex(p)),p=n.indexOf(o,p+1);d.unshift(s(0,0)),d.push(s(t.lastLine(),t.getLineHandle(t.lastLine()).text.length));for(var g=null,h=t.getCursor(),v=0;v<d.length;v++){if((null==g||l(h,g)>0)&&l(h,d[v])<=0){f={start:g,end:d[v]};break}g=d[v]}if(f.start){var b=r.getRange(f.start,f.end,!1);for(v=0;v<b.length&&(eachWord(b[v],(function(e){var t=e.toUpperCase();t===a&&getTable(c)&&(u=c),t!==i&&(c=e)})),!u);v++);}return u}e.registerHelper("hint","sql",(function(o,i){t=function parseTables(e){var t={};if(isArray(e))for(var r=e.length-1;r>=0;r--){var n=e[r];t[getText(n).toUpperCase()]=wrapTable(getText(n),n)}else if(e)for(var a in e)t[a.toUpperCase()]=wrapTable(a,e[a]);return t}(i&&i.tables);var l=i&&i.defaultTable,c=i&&i.disableKeywords;r=l&&getTable(l),n=function getKeywords(t){var r=t.doc.modeOption;return"sql"===r&&(r="text/x-sql"),e.resolveMode(r).keywords}(o),a=function getIdentifierQuote(t){var r=t.doc.modeOption;return"sql"===r&&(r="text/x-sql"),e.resolveMode(r).identifierQuote||"`"}(o),l&&!r&&(r=findTableByAlias(l,o)),(r=r||[]).columns&&(r=r.columns);var u,d,f,p=o.getCursor(),g=[],h=o.getTokenAt(p);if(h.end>p.ch&&(h.end=p.ch,h.string=h.string.slice(0,p.ch-h.start)),h.string.match(/^[.`"'\w@][\w$#]*$/g)?(f=h.string,u=h.start,d=h.end):(u=d=p.ch,f=""),"."==f.charAt(0)||f.charAt(0)==a)u=function nameCompletion(e,n,o,i){for(var l=!1,c=[],u=n.start,d=!0;d;)d="."==n.string.charAt(0),l=l||n.string.charAt(0)==a,u=n.start,c.unshift(cleanName(n.string)),"."==(n=i.getTokenAt(s(e.line,n.start))).string&&(d=!0,n=i.getTokenAt(s(e.line,n.start)));var f=c.join(".");addMatches(o,f,t,(function(e){return l?insertIdentifierQuotes(e):e})),addMatches(o,f,r,(function(e){return l?insertIdentifierQuotes(e):e})),f=c.pop();var p=c.join("."),g=!1,h=p;if(!getTable(p)){var v=p;(p=findTableByAlias(p,i))!==v&&(g=!0)}var b=getTable(p);return b&&b.columns&&(b=b.columns),b&&addMatches(o,f,b,(function(e){var t=p;return 1==g&&(t=h),"string"==typeof e?e=t+"."+e:(e=shallowClone(e)).text=t+"."+e.text,l?insertIdentifierQuotes(e):e})),u}(p,h,g,o);else{var objectOrClass=function(e,t){return"object"==typeof e?e.className=t:e={text:e,className:t},e};addMatches(g,f,r,(function(e){return objectOrClass(e,"CodeMirror-hint-table CodeMirror-hint-default-table")})),addMatches(g,f,t,(function(e){return objectOrClass(e,"CodeMirror-hint-table")})),c||addMatches(g,f,n,(function(e){return objectOrClass(e.toUpperCase(),"CodeMirror-hint-keyword")}))}return{list:g,from:s(p.line,u),to:s(p.line,d)}}))},"object"==typeof t&&"object"==typeof e?n(r("../../lib/codemirror"),r("../../mode/sql/sql")):"function"==typeof a&&a.amd?a(["../../lib/codemirror","../../mode/sql/sql"],n):n(CodeMirror)}));
//# sourceMappingURL=sql-hint.js.map