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