Liferay.Loader.define("fragment-web$codemirror@5.65.2/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 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(),c="",u="",d=[],f={start:s(0,0),end:s(t.lastLine(),t.getLineHandle(t.lastLine()).length)},p=n.indexOf(a);-1!=p;)d.push(r.posFromIndex(p)),p=n.indexOf(a,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===o&&getTable(c)&&(u=c),t!==i&&(c=e)})),!u);v++);}return u}e.registerHelper("hint","sql",(function(a,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 o in e)t[o.toUpperCase()]=wrapTable(o,e[o]);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}(a),o=function getIdentifierQuote(t){var r=t.doc.modeOption;return"sql"===r&&(r="text/x-sql"),e.resolveMode(r).identifierQuote||"`"}(a),l&&!r&&(r=findTableByAlias(l,a)),(r=r||[]).columns&&(r=r.columns);var u,d,f,p=a.getCursor(),g=[],h=a.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)==o)u=function nameCompletion(e,n,a,i){for(var l=!1,c=[],u=n.start,d=!0;d;)d="."==n.string.charAt(0),l=l||n.string.charAt(0)==o,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(a,f,t,(function(e){return l?insertIdentifierQuotes(e):e})),addMatches(a,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(a,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,a);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 o&&o.amd?o(["../../lib/codemirror","../../mode/sql/sql"],n):n(CodeMirror)}));
//# sourceMappingURL=sql-hint.js.map