Liferay.Loader.define("liferay!layout-content-page-editor-web$codemirror@5.65.2/addon/hint/sql-hint",["module","exports","require","../../lib/codemirror","../../mode/sql/sql"],(function(e,t,r){var n;window,n=function(e){"use strict";var t,r,n,a,o=e.Pos,i=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(),s="",l="",u=[],c={start:o(0,0),end:o(t.lastLine(),t.getLineHandle(t.lastLine()).length)},f=n.indexOf(";");-1!=f;)u.push(r.posFromIndex(f)),f=n.indexOf(";",f+1);u.unshift(o(0,0)),u.push(o(t.lastLine(),t.getLineHandle(t.lastLine()).text.length));for(var d=null,p=t.getCursor(),g=0;g<u.length;g++){if((null==d||i(p,d)>0)&&i(p,u[g])<=0){c={start:d,end:u[g]};break}d=u[g]}if(c.start){var h=r.getRange(c.start,c.end,!1);for(g=0;g<h.length&&(eachWord(h[g],(function(e){var t=e.toUpperCase();t===a&&getTable(s)&&(l=s),"AS"!==t&&(s=e)})),!l);g++);}return l}e.registerHelper("hint","sql",(function(i,s){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}(s&&s.tables);var l=s&&s.defaultTable,u=s&&s.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}(i),a=function getIdentifierQuote(t){var r=t.doc.modeOption;return"sql"===r&&(r="text/x-sql"),e.resolveMode(r).identifierQuote||"`"}(i),l&&!r&&(r=findTableByAlias(l,i)),(r=r||[]).columns&&(r=r.columns);var c,f,d,p=i.getCursor(),g=[],h=i.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)?(d=h.string,c=h.start,f=h.end):(c=f=p.ch,d=""),"."==d.charAt(0)||d.charAt(0)==a)c=function nameCompletion(e,n,i,s){for(var l=!1,u=[],c=n.start,f=!0;f;)f="."==n.string.charAt(0),l=l||n.string.charAt(0)==a,c=n.start,u.unshift(cleanName(n.string)),"."==(n=s.getTokenAt(o(e.line,n.start))).string&&(f=!0,n=s.getTokenAt(o(e.line,n.start)));var d=u.join(".");addMatches(i,d,t,(function(e){return l?insertIdentifierQuotes(e):e})),addMatches(i,d,r,(function(e){return l?insertIdentifierQuotes(e):e})),d=u.pop();var p=u.join("."),g=!1,h=p;if(!getTable(p)){var v=p;(p=findTableByAlias(p,s))!==v&&(g=!0)}var b=getTable(p);return b&&b.columns&&(b=b.columns),b&&addMatches(i,d,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})),c}(p,h,g,i);else{var objectOrClass=function(e,t){return"object"==typeof e?e.className=t:e={text:e,className:t},e};addMatches(g,d,r,(function(e){return objectOrClass(e,"CodeMirror-hint-table CodeMirror-hint-default-table")})),addMatches(g,d,t,(function(e){return objectOrClass(e,"CodeMirror-hint-table")})),u||addMatches(g,d,n,(function(e){return objectOrClass(e.toUpperCase(),"CodeMirror-hint-keyword")}))}return{list:g,from:o(p.line,c),to:o(p.line,f)}}))},"object"==typeof t&&"object"==typeof e?n(r("../../lib/codemirror"),r("../../mode/sql/sql")):n(CodeMirror)}));
//# sourceMappingURL=sql-hint.js.map